Graphql-js: Allow empty or missing `type Mutation` when `extend type Mutation` exists

Created on 15 Jun 2017  路  4Comments  路  Source: graphql/graphql-js

Feature Request

For modularity, all my mutations use extend type Mutation. The problem is that somewhere I have to define type Mutation and it's not allowed to be empty (e.g. type Mutation {} is not allowed).

An easy workaround is to add a null mutation, type Mutation { null: Boolean }, but it would be nice to either omit type Mutation {...} or leave it empty, type Mutation {} ,when extend type Mutation exists.

The same applies for type Query.

Most helpful comment

Thanks for the comment. What if you only allow an empty type Mutation {} if extend type Mutation{...} exists? Would the following produce an invalid schema?

type Mutation {}
extend type Mutation {
  someMutation($input: SomeInput!): SomePayload
}

As a best practices question, on the server side do you recommend having every mutation for the entire app inside of type Mutation {...} and not using extend at all? I've found it useful to keep the schema and resolvers for each part of my app together in the same place, and then merge the multiple schemas and resolvers in a centralized location.

All 4 comments

Unfortunately this would allow you to produce invalid schema, which is something we've worked to prevent.

Since the type extension syntax is designed for client-side extension of schema, I'm not sure this is a typical use case that would warrant allowing for producing of invalid schema.

I'm closing this issue, but happy to continue conversation or hear other approaches which would not allow invalid schema to be produced.

Thanks for the comment. What if you only allow an empty type Mutation {} if extend type Mutation{...} exists? Would the following produce an invalid schema?

type Mutation {}
extend type Mutation {
  someMutation($input: SomeInput!): SomePayload
}

As a best practices question, on the server side do you recommend having every mutation for the entire app inside of type Mutation {...} and not using extend at all? I've found it useful to keep the schema and resolvers for each part of my app together in the same place, and then merge the multiple schemas and resolvers in a centralized location.

Too bad this did not get an answer by @leebyron as this really matters when trying to modularize your app & GraphQL schema server-side.

@mxmlnglt We support empty object types since v0.12.0 just write type Mutation in SDL. Note: you should completely omit curly brackets since type Mutation {} is a syntax error. It would work with any type, interface, enum, enum, etc.

Was this page helpful?
0 / 5 - 0 ratings