Closed jacobmoshipco closed 1 month ago
Types passed to Schema via schema_directives aren't being added to the graphql_directives list, but they probably should be
Schema directives won't show in the introspection because that's not supported by the spec 😊 see: https://github.com/graphql/graphql-spec/issues/300
What are you trying to do, why do you need schema directives in introspection? Maybe you need operation directives?
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