-
Notifications
You must be signed in to change notification settings - Fork 2k
[RFC] Allows use of generated schemas for execution. #469
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
Conversation
Right now our generated schemas (built from introspection, built from AST) explicitly do not allow their use in execution. They throw as soon as any resolver function is called. This conservative behavior was appropriate for early versions where we wanted to limit the surface area under use. Today it's becoming more clear that there are immediately valuable use cases for using generated schema in execution.
234f2ff
to
930d489
Compare
Case 1 is really nice here - it lets people set up a graphql server without learning the API for the GraphQLSchema, GraphQLObjectType and so on. So +1 for making this change. Just a style thing but what do you think about a helper function that does buildASTSchema(parse(x)) ? |
I like that idea! |
This is great. Case 1 seems like a really solid use-case to make prototyping and iteration on servers easier. ship it! |
Love case 1, should be useful. As for case 2:
There are two disadvantages using this in Apollo Client or a similar tool, for me:
I'd be happy to collaborate with anyone to unblock this use case - there might be some small changes that can be made to make it possible for anyone to build a nice client-side cache using this package, which I think would be a big win for the community overall, and reduce the amount of custom work we need to do in Apollo Client. |
Fat fingers on mobile phone, my bad |
@stubailo - yeah, I'm with you there. I think the first case is compelling and the second is only just interesting. There's definitely some fruit for future exploration in what you're talking about, but of course if you're executing queries locally without a schema, then this is kind of moot since it's about the behavior of the schema itself :) |
Sigh......... I got nerd sniped. Feast your eyes: https://github.com/stubailo/graphql-anywhere Next up, refactoring Apollo Client to use this package to read from the cache! |
Heya, I'm trying to use the generated schema with Relay, but I'm getting the "Generated Schema cannot use Interface or Union types for execution." error. From what I can tell, for nodeDefinitions to work, we need interfaces. |
Hey, give this package a try: https://github.com/apollostack/graphql-tools It's like |
Right now our generated schemas (built from introspection, built from AST) explicitly do not allow their use in execution. They throw as soon as any resolver function is called. This conservative behavior was appropriate for early versions where we wanted to limit the surface area under use. Today it's becoming more clear that there are immediately valuable use cases for using generated schema in execution.
The ability to execute will still be somewhat limited: generated schema do not contain enough information to resolve Interface and Union types, and coerce values for custom Scalars.
Case 1: Resolvers live in your domain models, AST schema is useful:
This is pretty compelling for simpler schema. You can define your schema entirely in AST and allow resolvers to completely exist outside the GraphQL type domain. This approach is now immediately useful thanks to @lacker's #468.
Case 2: Querying your local cache:
I admit that this use case is more experimental and less thought through, but I believe that contributors & community may take this idea further. Conceptually it's compelling: given a query I want to submit and my local cache of results, what partial results can I use right away before the server returns? I'm absolutely sure there are missing pieces to truly enable this, but this should be a first step.