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

buildType that mirrors buildSchema but for types #474

Closed
migueloller opened this issue Aug 31, 2016 · 3 comments
Closed

buildType that mirrors buildSchema but for types #474

migueloller opened this issue Aug 31, 2016 · 3 comments

Comments

@migueloller
Copy link

Now that we have buildSchema it would be nice to also have a buildType to create custom types using IDL. The main benefit would be code separation.

GraphQL schema for large APIs are quite big and often it's beneficial to separate types in different files. Right now graphql-tools offers makeExecutableSchema which can take an array of strings (IDL), each defining a type. Then you have to use addResolveFunctionsToSchema to add resolvers.

It would be great if we could build types using IDL and passing any other required functions as a map (buildType(IDL, config)). buildType would take care of fields and args internally.

buildSchema could then be modified to take an array of types so that the schema is executable (including field resolution).

Thoughts?

@migueloller
Copy link
Author

@stubailo and @leebyron,

I kind of needed this ASAP so I ended up writing my own. It works pretty well and has some nice shortcuts (like the resolve shortcut from graphql-tools and building a scalar using the schema language but getting serialize, parseValue, and parseLiteral from another scalar). I'm planning on making more tools later on (e.g., type factories) so I simply made a whole package called graphql-utilities.

I'm not sure if GraphQL.js (as a reference implementation) should have complex utilities like this one, if it's something within it's scope I wouldn't mind doing a PR. If it's outside the scope then I'll keep developing it on that repo.

@migueloller
Copy link
Author

It's worth mentioning that the implementation of build reimplementes various functions that buildASTSchema uses internally. build could be modified to behave like it by default and then it could be a drop-in replacement for buildASTSchema

@IvanGoncharov
Copy link
Member

Closing since, #597 has the bigger scope that fully incorporates this issue.

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