Reputation: 333
Say I have a structure like this:
src/
├── user/
│ ├── mutation.js
│ ├── query.js
├── cars/
│ ├── mutation.js
│ ├── query.js
└── schema.js
How can I create a Schema from user's mutation.js and query.js, and cars' mutation.js and query.js combined inside schema.js?
Upvotes: 0
Views: 200
Reputation: 333
@Hangindev is right, to concatenate all mutations and queries I need to export GraphQLObjectType fields, like so:
const userMutation = {
addUser: {
type: UserType,
args: {
username: {type: GraphQLString},
email: {type: GraphQLString},
},
resolve(parent, args) {
let author = new User({
username: args.username,
email: args.email,
});
return author.save();
}
},
}
module.exports = userMutation
and adding them later into the Schema:
const Mutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
...userMutation,
...foodPostMutation
}
})
const Query = new GraphQLObjectType({
name: 'Query',
fields: {
...userQuery,
...foodPostQuery
}
})
module.exports = new GraphQLSchema({
query: Query,
mutation: Mutation
})
Upvotes: 1