Graphql-tools: how to make modularize mutations?

Created on 25 Dec 2016  路  5Comments  路  Source: ardatan/graphql-tools

Most helpful comment

In the root file, define:

type Mutation {
  someRootField
}

In some other file, define:

extend type Mutation {
  anotherField
}

At the end you'll end up with:

type Mutation {
  someRootField
  anotherField
}

You can merge the resolver functions as usual, since that's just merging all of the fields in an object with a regular JavaScript function.

All 5 comments

You can use extend type for modularization.

@radiegtya Without more information it's pretty hard to answer such a question. You may have more luck asking on our slack channel.

@veeramarni could you please elaborate on the extend type?

Form the documentation its is clear how you can 'modularize' queries into separate files with the help of makeExecutableSchema but to me the separation of mutation in different files is not clear.

As if two times a type is encountered, their definitions aren't merged, but instead overwritten.

Therefore how can we separate mutations in a similar way to separate queries?

In the root file, define:

type Mutation {
  someRootField
}

In some other file, define:

extend type Mutation {
  anotherField
}

At the end you'll end up with:

type Mutation {
  someRootField
  anotherField
}

You can merge the resolver functions as usual, since that's just merging all of the fields in an object with a regular JavaScript function.

You can also use an undefined type in schema.js and extend it in the resource schema file.

schema.js

const RootMutation = `
    type Mutation
`;

const schema = `
    schema {
        mutation: Mutation
    }
`;

resource.js

const User = `
    extend type Mutation {
      addUser(email: String): Boolean!
    }
`;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

BassT picture BassT  路  3Comments

confuser picture confuser  路  4Comments

brennantaylor picture brennantaylor  路  4Comments

udisun picture udisun  路  3Comments

ghost picture ghost  路  3Comments