1

How to add multiple queries/mutations from different entities to graphql schema?

I have file called User.graphql and defined schema:

import UserQueries, UserMutations from 'User.graphql'

schema {
  query: UserQueries,
  mutation: UserMutations
}

and it works. Now I would like to add another entity called Event and related Queries and Mutations. It suppose to look like below:

pseudocode:

schema {
  query: UserQueries & EventQueries,
  mutation: UserMutations & EventMutations
}

So, how to concat queries and mutations between entities like pseudocode above shows? Is it a good way and a proper architecture?

I attach also .js code

const userSchema = addResolversToSchema({
  schema,
  resolvers: {
    UserMutations,
    UserQueries
  }
})
Sheppard25
  • 493
  • 1
  • 7
  • 22
  • One way to go may be to introduce "namespaces", as described in the [GraphQL.NET documentation](https://graphql-dotnet.github.io/docs/getting-started/query-organization). That is, you create a top-level `type` for queries which has the two fields `user: UserQueries` and `event: EventQueries`. But this would not concatenate the queries and would break existing clients. – Flogex Aug 10 '20 at 07:45

0 Answers0