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

Improve visiblity / type filtering #5014

Open
3 of 6 tasks
rmosolgo opened this issue Jul 12, 2024 · 3 comments
Open
3 of 6 tasks

Improve visiblity / type filtering #5014

rmosolgo opened this issue Jul 12, 2024 · 3 comments

Comments

@rmosolgo
Copy link
Owner

rmosolgo commented Jul 12, 2024

In #4998, I started on a new schema visibility implementation. I have a few goals here:

  • Make it possible to load GraphQL types lazily -- only loading types needed by a given query.
  • Make it possible to use cached schema subsets (don't have to recalculate the visible schema on every query -- when possible)
  • Improve logging and debugging of visibility (especially when types are hidden)
  • Make a very smooth migration process:
    • Use the Query#types interface to support logging when the two systems would diverge
    • Clearly document the expectations of the new system (Warden was basically never documented, and arguably tried to do too much, but couldn't do everything)

I'm opening this issue for my own purposes but also in case anyone wants to share any thoughts or questions on the work.

TODO:

@sealabcore
Copy link

I'm having an issue with the latest version of the gem related to this work in the tests for my mutations.

In my tests I call this

context = { current_user: user }
Mutations::AcceptDiscussionEmailInvite.new(object: nil, field: nil, context: context).resolve(**args)

And with the latest gem version I am getting this error:

NoMethodError: undefined method `types' for { :current_user=> <User> }
test/graphql/mutations/accept_discussion_email_invite_test.rb:8:in `new'

Any thoughts on what I should be passing into the mutation as the context for my tests? Looks like a hash doesn't work anymore.

@sealabcore
Copy link

Figured it out,

context = { current_user: user }
context = GraphQL::Query::Context.new(query: GraphQL::Query.new(MapleSchema), values: context)
Mutations::AcceptDiscussionEmailInvite.new(object: nil, field: nil, context: context).resolve(**args)

@rmosolgo
Copy link
Owner Author

Hey, sorry for the disruption there. Initializing Mutations outside of query execution isn't a formally supported API, but I'm glad you found something that works. In a pinch, another way to get a context is:

query = MySchema.query_class.new(self, "{ __typename }", context: { ... } )
context = query.context

Also, you could try the run_graphql_field helper to get nearly-full runtime context: https://graphql-ruby.org/testing/helpers.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants