Search code examples
graphqlapollographql-jsgraphiql

Graphiql structure queries/mutations by categories


I am wondering is there any way of structuring graphql queries/mutations in a GraphiQL ide. Right now I have long list of queries/mutation in docs tab (see image below). What I want is to seperate them by categories (like users, customers, interns etc). Is this possible? or should I use some other tools?

:enter image description here


Solution

  • It may be helpful if you simulate namespace with nested type resolver like following.

    type UserQuery {
      users: [User]
      user(id: String): User
    }
    
    type InternQuery {
      intern: Intern
      interns: [Intern]
      internCustomers: [Customer]
    }
    
    type Query {
      userQuery: UserQuery
      internQuery: InternQuery
    }
    

    In your query's resolvers, userQuery and internQuery just need to return empty object, and put your other resolvers into UserQuery and InternQuery.