Exemple #1
0
def print_fields(type_, schema: BaseSchema) -> str:
    strawberry_type = cast(TypeDefinition, schema.get_type_by_name(type_.name))

    fields = []

    for i, (name, field) in enumerate(type_.fields.items()):
        strawberry_field = strawberry_type.get_field(
            name) if strawberry_type else None

        fields.append(
            print_description(field, "  ", not i) + f"  {name}" +
            print_args(field.args, "  ") + f": {field.type}" +
            print_federation_field_directive(strawberry_field) +
            print_deprecated(field.deprecation_reason))

    return print_block(fields)
Exemple #2
0
def print_fields(type_, schema: BaseSchema) -> str:
    strawberry_type = cast(TypeDefinition, schema.get_type_by_name(type_.name))

    fields = []

    for i, (name, field) in enumerate(type_.fields.items()):
        python_name = field.extensions and field.extensions.get("python_name")

        strawberry_field = (strawberry_type.get_field(python_name)
                            if strawberry_type and python_name else None)

        fields.append(
            print_description(field, "  ", not i) + f"  {name}" +
            print_args(field.args, "  ") + f": {field.type}" +
            print_field_directives(strawberry_field, schema=schema) +
            print_deprecated(field.deprecation_reason))

    return print_block(fields)
Exemple #3
0
def print_fields(type_) -> str:
    strawberry_type = get_strawberry_type_for_graphql_type(type_)
    strawberry_fields = dataclasses.fields(strawberry_type) if strawberry_type else []

    def _get_metadata(field_name):
        return next(
            (
                f.metadata
                for f in strawberry_fields
                if (getattr(f, "field_name", None) or f.name) == field_name
            ),
            None,
        )

    fields = [
        print_description(field, "  ", not i)
        + f"  {name}"
        + print_args(field.args, "  ")
        + f": {field.type}"
        + print_federation_field_directive(field, _get_metadata(name))
        + print_deprecated(field)
        for i, (name, field) in enumerate(type_.fields.items())
    ]
    return print_block(fields)