-
Notifications
You must be signed in to change notification settings - Fork 2k
Allow defining empty types #937
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
Comments
I would be happy to do that too. For now I write : type Mutation {
_ : Boolean
} |
I actually found another way that can suit me for now (I'm using graphql-tools): // user mutations
const UserMutationFields = `
createUser(input: CreateUserInput!): User
updateUser(input: UpdateUserInput!): User
removeUser(input: RemoveUserInput!): User
`
// root mutation
const MutationType = `
type Mutation {
${UserMutationFields}
}
` |
Ok Nice. I guess you only need for the root objects (Query, Mutation and Subscription) ? |
@cedrelek yeah, I'm currently using this for root Query and Mutation, but I think it can be used with any type. |
I've run into the same problem and have to put in fake fields to my root Query/Mutation type. Since I define all my schemas in separate graphqls files, slicing things up differently as suggested above doesn't work as well for me. |
Any update on this issue ? |
Meanwhile, I used this package to merge my schema files ( and resolvers ) and avoid defining fake field https://github.com/okgrow/merge-graphql-schemas Pros
Cons
Do you have experience using this package ? |
The latest updates to the master branch enable this via Release coming soon |
Another case where this is super helpful: When you want to emulate ML-style algebraic data types you're screwed for variants that don't have any fields. For example, type Mutation {
createUser(email: String!, password: String!): CreateUserPayload!
}
type UserWithEmailAlreadyExists {}
type WeakPassword {}
type AuthPayload {
user: User!
token: AccessToken!
}
union CreateUserPayload = UserWithEmailAlreadyExists | WeakPassword | AuthPayload |
Update: this is possible as of type Mutation {
createUser(email: String!, password: String!): CreateUserPayload!
}
type UserWithEmailAlreadyExists
type WeakPassword
type AuthPayload {
user: User!
token: AccessToken!
}
union CreateUserPayload = UserWithEmailAlreadyExists | WeakPassword | AuthPayload GitHub doesn't syntax highlight it correctly but it does in fact work. |
Further update: that actually doesn't work. It parses the schema fine, but after starting the server I'm seeing:
|
Hello, I still get this error, and looking at the code the check is still there: https://github.com/graphql/graphql-js/blob/master/src/type/validate.js#L273 Is this resolved or no? |
...For now I solved this by commenting out that check. It looks like everything works afterwards, suggesting that the check is completely arbitrary and a waste of code. Note also that GraphQL spec allows empty types. My use case is the same as @samuela |
@alamothe where in the GraphQL spec does it say that empty types are allowed? Per the working draft:
|
Sorry my bad, it is a problem with the spec. |
Currently this is not possible:
It's needed when you want to split your schema into multiple files. Instead, you need to define at least one field:
It would be awesome to be able to define empty types to later extend them.
The text was updated successfully, but these errors were encountered: