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

Support running partial graphql queries #5136

Open
rmosolgo opened this issue Oct 31, 2024 · 0 comments · May be fixed by #5183
Open

Support running partial graphql queries #5136

rmosolgo opened this issue Oct 31, 2024 · 0 comments · May be fixed by #5183

Comments

@rmosolgo
Copy link
Owner

For ObjectCache, I could improve the granularity of caching if I could re-execute parts (eg, uncacheable parts) of queries without re-running the whole thing. This comes with some possible foot-guns, since fields sometimes depend on "upstream" context for their resolution, but it could also work pretty well in most cases.

I think the best API for me would be something like:

query = GraphQL::Query.new(...) # make a query somehow 
query_partial = query.partial_for("currentUser", "posts")
partial_result = query_partial.execute(@current_user.posts) # run the selected portion of the query using the given object as the underlying data

That would also support multiplexing, eg:

query = GraphQLQuery.new(...)
# Run these partials concurrently (sharing a dataloader cache, etc) 
results = query.execute_partials({
  ["currentUser", "posts"] => @current_user.posts, 
  ["currentUser", "profile", "auditLog"] => AuditLog.events(user: @current_user), 
  # Etc 
})

Then it's up to the caller how to handle those results.

@rmosolgo rmosolgo linked a pull request Dec 5, 2024 that will close this issue
5 tasks
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

Successfully merging a pull request may close this issue.

1 participant