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

Add utility function function for generating fully-featured schema from SDL #1858

Open
danielrearden opened this issue May 9, 2019 · 3 comments

Comments

@danielrearden
Copy link
Contributor

With SDL officially part of the specification, would it be worthwhile to provide a way to build a build a fully-featured schema from a Document AST?

Currently, schemas built using buildASTSchema/buildSchema lack several features that are otherwise available if constructed programmatically:

  • Specifying resolve functions for fields
  • Specifying resolveType functions for unions and interfaces and isTypeOf functions for types
  • Specifying enum value values
  • Adding custom scalars

Workarounds exist for some of these limitations (functions can be passed through the root object for root type fields, abstract types can be handled by explicitly providing a __typename property, etc.). In practice, though, if I'm starting a new project and want to use SDL to define my schema, I'm forced to use graphql-tools or another third-party package. This was completely understandable prior to the 2018 version of the spec, but now it may be appropriate for this functionality to be part of the core library.

@IvanGoncharov
Copy link
Member

@danielrearden It's one of the goals of buildSchema/extendSchema refactoring I'm working in the background. I still like that simplicity of buildSchema so ATM my long term plan is to create a better version of transformSchema from #1199.
And based on it create a high-level function to attach resolvers to any schema (produced by buildSchema, extendSchema, buildClientSchema, new GraphQLSchema, etc.).

BTW, You can use SDL together with ES6 classes so you don't need to attach resolvers to schema: https://github.com/IvanGoncharov/swapi-demo/blob/master/src/index.ts
That said I still think it extremely important to support the pattern of attaching static resolvers since it's the widest spread pattern in GraphQL JS ecosystem.

@IvanGoncharov
Copy link
Member

Here is a great article on the topic: https://medium.com/@samerbuna/the-api-i-wish-javascript-graphql-implementations-supported-91eecfb96106 and accompanying library https://github.com/jscomplete/graphql-makers

@yaacovCR
Copy link
Contributor

Related: #597

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

No branches or pull requests

3 participants