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
When using introspection, Strawberry is not returning any custom schema directives. Looking into it, I found a partial cause and a workaround.
I created a repository to show the issue. If you run main.py, it will run eight tests:
test field directive schema export Should pass showing that export-schema correctly outputs directives
test one of schema export Should pass showing the same for the one_of property
test field directive introspection Should fail showing that custom directives are not listed in an introspection query
test one of introspection Should fail showing the same for the one_of property
The last four tests should all pass, they show a work-around of passing the directives to Schema(..., types=[...]). Note that this doesn't work if passed to schema_directives=[...] instead.
There is also no automatic collection of directives when generating introspection. Leaving the types off Schema entirely works when running schema export, but not when running introspection.
What I personally consider to be "the bug"
Types passed to Schema via schema_directives aren't being added to the graphql_directives list, but they probably should be
Automatic collection of schema directives works in export-schema but not in introspection.
System Information
Operating system: MacOS Ventura 13.2.1
Strawberry version (if applicable): 0.243.1 (but the issue exists much further back)
Additional Context
I believe it makes the most sense to pass the schema directives to Schema via schema_directives. Currently, Schema is looking for them in types and using compat.is_schema_directive to check if they're schema directives. By modifying Schema to simply iterate over schema_directives and running the same code, I was able to get that portion working exactly as I expected. This probably solves part one of the bug, but I haven't had time to run the unit tests against this yet.
No idea why part two is happening.
Upvote & Fund
We're using Polar.sh so you can upvote and help fund this issue.
We receive the funding once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog.
The text was updated successfully, but these errors were encountered:
I didn't notice that it wasn't part of the spec. It appears I confused schema directives and operation directives when experimenting with work-arounds.
I was trying to use the schema directives for metadata for codegen (particularly oneOf). I had misremembered using the introspection feature to do just that on an earlier project, but looking at it, it appears I was using export-schema and using that for the codegen. Is that the best approach?
Okay, using export-schema to export an SDL to be served by my API works perfectly. I'll be closing this issue; feel free to reopen if anyone needs more from it. Thanks for your help!
Describe the Bug
When using introspection, Strawberry is not returning any custom schema directives. Looking into it, I found a partial cause and a workaround.
I created a repository to show the issue. If you run
main.py
, it will run eight tests:test field directive schema export
Should pass showing that export-schema correctly outputs directivestest one of schema export
Should pass showing the same for theone_of
propertytest field directive introspection
Should fail showing that custom directives are not listed in an introspection querytest one of introspection
Should fail showing the same for theone_of
propertyThe last four tests should all pass, they show a work-around of passing the directives to
Schema(..., types=[...])
. Note that this doesn't work if passed toschema_directives=[...]
instead.There is also no automatic collection of directives when generating introspection. Leaving the types off
Schema
entirely works when running schema export, but not when running introspection.What I personally consider to be "the bug"
Schema
viaschema_directives
aren't being added to thegraphql_directives
list, but they probably should beSystem Information
Additional Context
I believe it makes the most sense to pass the schema directives to
Schema
viaschema_directives
. Currently,Schema
is looking for them intypes
and usingcompat.is_schema_directive
to check if they're schema directives. By modifyingSchema
to simply iterate overschema_directives
and running the same code, I was able to get that portion working exactly as I expected. This probably solves part one of the bug, but I haven't had time to run the unit tests against this yet.No idea why part two is happening.
Upvote & Fund
The text was updated successfully, but these errors were encountered: