Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema directives not included in introspection #3649

Closed
jacobmoshipco opened this issue Sep 27, 2024 · 3 comments
Closed

Schema directives not included in introspection #3649

jacobmoshipco opened this issue Sep 27, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@jacobmoshipco
Copy link
Contributor

jacobmoshipco commented Sep 27, 2024

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 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"

  1. Types passed to Schema via schema_directives aren't being added to the graphql_directives list, but they probably should be
  2. 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.
Fund with Polar
@jacobmoshipco jacobmoshipco added the bug Something isn't working label Sep 27, 2024
@patrick91
Copy link
Member

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: graphql/graphql-spec#300

What are you trying to do, why do you need schema directives in introspection? Maybe you need operation directives?

@jacobmoshipco
Copy link
Contributor Author

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?

@jacobmoshipco
Copy link
Contributor Author

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!

@jacobmoshipco jacobmoshipco closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants