I'm trying to create tree-like structure for my queries, to get rid off queries like
peopleList, peopleSingle, peopleEdit, peopleAdd, peopleDelete companyList, companySingle, companyEdit, companyAdd, companyDelete etc.
In the end I would like to send query like this:
query test {
people {
list {
id
name
}
single(id: 123) {
id
name
}
}
company {
list {
id
name
}
single(id: 456) {
id
name
}
}
}
mutation test2 {
people {
create(data: $var) {
id
name
}
}
people {
edit(id: 123, data: $var) {
id
name
}
}
}
This is part of my query object on people module:
people: {
type: //What type this should be?
name: 'Root of People queries',
fields: () => ({
list: {
type: peopleType,
description: 'Returns all people in DB.',
resolve: () => {
// resolve method implementation
}
},
single: {
type: peopleType,
description: 'Single row from people table. Requires ID argument.',
args: {
id: { type: new GraphQLNonNull(GraphQLID) }
},
resolve: () => {
// resolve method implementation
}
}
})
}
I have tried to put this snippet into GraphQLObjectType and then combine them together in RootQuery (using GraphQLObjectType again) - didn't work.
Alternative method could be to create new Type - like peopleQueriesType, inside this type specify all my queries as fields and then create single query for this object. But this seems odd to me - polluting my code with unnecessary objects just to merge my queries in tree-like shape.
I have tried to look at Apollo server implementation, if it can do this kind of query structure, but couldn't find any help in documentation.
I'm using node.js + express + graphql-js on my server.