-
-
Notifications
You must be signed in to change notification settings - Fork 818
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 ability to implement schema using both SDL and GraphQLObjectTypes #185
Comments
I like that approach, and I think it's complementary to graphql-tools. GraphQL-tools has the advantage that the schema becomes much easier to read, while graphql-utilities has the advantage of keeping the resolver code close to the schema types that it applies to. |
You can always separate the resolvers like you do in Colocating the resolvers is an advantage but it's not 100% required if you don't want to do it that way. EDIT: You could build the entire schema just like in |
@migueloller are you willing to create a PR adding this feature? :) |
@DxCx, definitely! Could you take a look at migueloller/graphql-utilities#12 There I go over some of the work I want to do to get the I'm in the Apollo Slack as |
hi @migueloller, anyway, yeah, this is more or less what i had in mind, also, we need to think how to specify context requirements for a type.. |
Awesome! I'm currently working on migueloller/graphql-utilities#12 as fast as I can so I'll let you know as soon as that's done. With regards to context requirements, do we really want to limit how context gets defined by the library consumer? Shouldn't they simply provide a root value that takes advantage of the default resolver? |
oh no, i don't want to limit anything, |
Hey I'm going through and looking at some of the issues here, and this is still something that comes up a lot! We're going to try to address some of these in the coming weeks :) Going to use this as the main issue for this idea. |
@stubailo, sounds good! Please let me know if you want any help/contributions. |
Any update on this issue? |
@stubailo did you have any progress on this? |
Folding into #1306. |
This is possible using stitchSchemas using types property? but that is not really new functionality, it was just given a new property name but it used to work just fine in the schemas property before that was broken out into subschemas... |
Aha, I might be confused here, thought it's an issue about |
Not as familiar with the merge package. @ardatan ? Note that you don't actually have to use stitching here, If you don't pass any sub schemas you can just merge types and typedefs using the stitching function but there is no delegation |
Then you would get a schema output, what kind of output are you looking for |
@borekb mergeTypeDefs accepts an array of the following types: The function works by merging types represented as AST nodes, which is what you get when you use The function doesn't support passing in instances of GraphQLObjectType or the other type classes directly. However, if those types are part of a schema, you can just pass in the schema. If they are not part of any schema, you can still pass them in this way:
|
This is a continuation of my comments on #116.
To answer @stubailo's question:
With
graphql-utilities
the idea is very simple, GraphQL.js provides a JavaScript implementation to define a GraphQL schema but we could always use the less verbose schema language. The initial goal of the library was to allow anybody to build anything that could be built with GraphQL.js but using the schema language.For example,
to build a schema:
to build a type:
here's another type:
A few things to note:
build
, it would simply be exported with its name in the returned type map. When building a single type, you could return that type instead of a type map but I've found this to result in a more confusing API (the library currently does that but I was planning to remove support for it).__schema
name above is a simple selection, it could be any other name but it was the one that made the most sense after much thought.graphql-tag
for syntax highlighting and other nice perks. Implementing this would be extremely simple.resolver
field, you simply pass in the resolver. Here's the difference with and without:with shortcut:
without shortcut:
buildASTSchema
) but this type of magic makes the API a bit confusing. It could be kept or removed but what I know for sure is that good error messages are essential for debugging these things.build
takes the following parameters:There are more things I have in mind for this library (like custom types for URLs, Email, etc.) but I feel like starting with
build
is a good start. Whatgraphql-tools
currently does with appplying resolvers by modifying the schema after the fact feels hacky, and doesn't lend itself for colocation of resolvers and definitions which is why ultimately I builtgraphql-utilities
.If my approach is something of interest I would love to discuss it more and potentially even make it a part of
graphql-tools
as I'm honestly just looking to benefit the ecosystem as a whole and not have another library to compete (https://xkcd.com/927/ heh).Thanks for all the great work you guys have been doing with the Apollo stack. Truly amazing stuff! 😄
The text was updated successfully, but these errors were encountered: