-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Proposal: "and" (or product) types. #247
Comments
What about an alternative - open types? So: type Mutation {
createArticle(authorId: ID!, title: String!, body: String!): Article
}
type Mutation {
createUser(username: String!): User
} Could just merge into one type by default. That seems to address the current issue more directly. |
Hm, I worry about the lack of explicitness with that approach. Is it actually my intent to merge the two types? Or have I accidentally created a 2nd type with a name that clashes with another? |
That's true, it would be possible to make a mistake of that nature with that approach. I'm a bit worried that the type merging approach will result in tons of unused types in the schema though, like if you generate docs they will have many different mutation types. Two other options: # Explicitly declare that we are reopening a type
extend type Mutation {
createArticle(authorId: ID!, title: String!, body: String!): Article
} # Type fragments
type fragment UserMutation {
createUser(username: String!): User
}
type fragment ArticleMutation {
createArticle(authorId: ID!, title: String!, body: String!): Article
}
type Mutation {
...UserMutation
...ArticleMutation
} The fragment thing is essentially the same as your proposal, except that the fragments wouldn't be listed in the documentation as their own types. Or perhaps there is some other way to mark types as "unlisted". I feel like having a way to declare snippets of fields would be pretty valuable, for example |
✋ as a Ruby developer ... open classes seems like a lot of fun until it's not! 😆 Just for all the same reasons described above: strange coupling between parts without any indication in the source code itself. I prefer the |
Yeah the only unfortunate part with the type fragments thing is that it (I think) requires changing the parser, so we can't easily polyfill it. |
Confirmed: https://astexplorer.net/#/HHyDzIQq7H |
I've been experimenting with the idea of merging schema fragments over in https://github.com/jamesgorman2/graphql-type-repository . I've only got a (non-runnable since I've not finished it) code example up, not a full readme. The intuition is that An extension to this was that since the internals are based around decorating immutable type graphs until they are complete (see Internal repository execution in the readme), you could add a decorator that namespaces each of your |
This seems similar to #48, but seems to be only syntax sugar instead of allowing new use cases. A reminder that any decision that compromises between readability and writability, I think readability should always be the priority. Since this proposal is syntax sugar that makes reading the schema language more difficult, I think it's appropriate to move this to rejected. |
When building large schemas using the schema language patterns, it's relatively awkward to build the mutation type. My definitions are spread across a large number of files, and I typically want my mutations to be defined alongside the types they are most related to.
We're restricted to having a single Mutation type, with no namespacing, that has to hold all the mutations for the entire schema, this makes it relatively awkward to define mutations in a modular way without resorting to some trickery.
I'm proposing something like this:
Aside from the syntactic sugar provided by the last line, this is something I already do as a post-processing step after generating my schema. But i'd prefer to do away with the hack entirely and have a solution that feels more standardised.
The basic spec would be that an and type combines all the fields of the types being added, and errors on a collision.
The text was updated successfully, but these errors were encountered: