You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After #4598, print_definition=False is supported on @strawberry.schema_directive (since #2047), strawberry.scalar, and strawberry.enum. Object types, input types, interfaces, and unions have no equivalent, so there is currently no way to keep those kinds of support types out of printed SDL while keeping them available to introspection and execution.
This issue tracks filling that gap so the visibility mechanism is consistent across every kind of definition.
Current behavior
A hidden directive whose argument is an input object still prints that input, because inputs cannot be hidden. The test test_print_definition_false_remains_available_to_introspection in tests/schema/test_schema_directives.py shows this:
directive @hidden is omitted as requested, but HiddenConfig — which exists only to serve that hidden directive — is force-printed. Today, this is the only option for input types, so the test asserts the current output as expected.
Proposed change (by claude)
Add print_definition: bool = True to @strawberry.type, @strawberry.input, @strawberry.interface, and strawberry.union, stored on StrawberryObjectDefinition / StrawberryUnion and consulted by _should_print_type in strawberry/printer/printer.py exactly as it already is for scalars and enums.
Expected details, matching the existing semantics:
Hidden types stay registered in the GraphQLSchema and remain visible to introspection; ition is omitted.
A hidden type that is referenced by a visible definition is still printed, so the emitted SDL stays valid (same reachability rule the printer applies to scalars and enums today).
The HiddenConfig case above should then be able to produce just type Query { name: Stri
Open questions
Interfaces: should hiding an interface also require hiding its implementations, or should reachability handle it? Reachability is probably enough, but it needs a test.
Unions: a hidden union referenced by a visible field will be printed by reachability; that's consistent, just worth documenting.
Whether a single generic, schema-level visibility hook would be preferable to per-decorator flags was discussed on Expose attached schema directives through introspection #4598. The conclusion was to stay consistent with the existing declaration-site print_definition convention rather than introduce a second mechanism.
I also wonder if we keep this API to change to to _print_definition since it's more about internal stuff.
Or we find a different way altogether to do this, which could also make it easier to implement schema visibility support 🤔
After #4598,
print_definition=Falseis supported on@strawberry.schema_directive(since #2047),strawberry.scalar, andstrawberry.enum. Object types, input types, interfaces, and unions have no equivalent, so there is currently no way to keep those kinds of support types out of printed SDL while keeping them available to introspection and execution.This issue tracks filling that gap so the visibility mechanism is consistent across every kind of definition.
Current behavior
A hidden directive whose argument is an input object still prints that input, because inputs cannot be hidden. The test
test_print_definition_false_remains_available_to_introspectionintests/schema/test_schema_directives.pyshows this:directive
@hiddenis omitted as requested, butHiddenConfig— which exists only to serve that hidden directive — is force-printed. Today, this is the only option for input types, so the test asserts the current output as expected.Proposed change (by claude)
Add
print_definition: bool = Trueto@strawberry.type,@strawberry.input,@strawberry.interface, andstrawberry.union, stored onStrawberryObjectDefinition / StrawberryUnionand consulted by_should_print_typeinstrawberry/printer/printer.pyexactly as it already is for scalars and enums.Expected details, matching the existing semantics:
Open questions
I also wonder if we keep this API to change to to
_print_definitionsince it's more about internal stuff.Or we find a different way altogether to do this, which could also make it easier to implement schema visibility support 🤔