コード例 #1
0
ファイル: table.py プロジェクト: usri99/nebulo
    def build_attrs():
        attrs = {}

        # Override id to relay standard
        attrs["nodeId"] = Field(NonNull(ID), resolve=default_resolver)

        for column in get_columns(sqla_model):
            if not Config.exclude_read(column):
                key = Config.column_name_mapper(column)
                attrs[key] = convert_column(column)

        for relationship in get_relationships(sqla_model):
            direction = relationship.direction
            to_sqla_model = relationship.mapper.class_
            relationship_is_nullable = is_nullable(relationship)

            # Name of the attribute on the model
            attr_key = Config.relationship_name_mapper(relationship)

            # If this model has 1 counterpart, do not use a list
            if direction == interfaces.MANYTOONE:
                _type = table_factory(to_sqla_model)
                _type = NonNull(_type) if not relationship_is_nullable else _type
                attrs[attr_key] = Field(_type, resolve=default_resolver)

            # Otherwise, set it up as a connection
            elif direction in (interfaces.ONETOMANY, interfaces.MANYTOMANY):
                connection_field = connection_field_factory(
                    to_sqla_model, resolver=default_resolver, not_null=relationship_is_nullable
                )
                attrs[attr_key] = connection_field

        return attrs
コード例 #2
0
def condition_factory(sqla_model: TableProtocol) -> InputObjectType:
    result_name = f"{Config.table_name_mapper(sqla_model)}Condition"

    attrs = {}
    for column in get_columns(sqla_model):
        field_key = Config.column_name_mapper(column)
        attrs[field_key] = convert_column_to_input(column)
    return InputObjectType(result_name, attrs, description="")
コード例 #3
0
def patch_type_factory(sqla_model: TableProtocol) -> InputObjectType:
    """AccountPatch"""
    relevant_type_name = Config.table_type_name_mapper(sqla_model)
    result_name = f"{relevant_type_name}Patch"

    attrs = {}
    for column in get_columns(sqla_model):
        if not Config.exclude_update(column):
            field_key = Config.column_name_mapper(column)
            column_field = convert_column_to_input(column)
            # TODO Unwrap not null here
            attrs[field_key] = column_field
    return TableInputType(result_name, attrs, description=f"An input for mutations affecting {relevant_type_name}.")
コード例 #4
0
def input_type_factory(sqla_model: TableProtocol) -> TableInputType:
    """AccountInput"""
    relevant_type_name = Config.table_type_name_mapper(sqla_model)
    result_name = f"{relevant_type_name}Input"

    attrs = {}
    for column in get_columns(sqla_model):
        if not Config.exclude_create(column):
            field_key = Config.column_name_mapper(column)
            attrs[field_key] = convert_column_to_input(column)
    return TableInputType(
        result_name,
        attrs,
        description=f"An input for mutations affecting {relevant_type_name}.")
コード例 #5
0
def field_name_to_column(sqla_model: TableProtocol,
                         gql_field_name: str) -> Column:
    for column in get_columns(sqla_model):
        if Config.column_name_mapper(column) == gql_field_name:
            return column
    raise KeyError(f"No column corresponding to field {gql_field_name}")