简体   繁体   中英

How to get all graphql schema query, mutation, subscribe

I am using nodejs with graphql and graphql-compose so i define scheme as

schemaComposer.Query.addFields({
  Me: MyResolvers,
  Info: MyInfoResolvers,
  Post: PostResolvers
})

schemaComposer.Mutation.addFields({
    Login: MyLoginResolvers,
    Register: RegisterResolvers
})

schemaComposer.Subscription.addFields({
    Subscribe: Mysubscribe
})

So any function to get all query, mutation and subscribe to list array example i need print to

[
  { operator: "Me", name: "Query" }
  { operator: "Info", name: "Query" }
  { operator: "Post", name: "Query" }
  { operator: "Login", name: "Mutation" }
  { operator: "Register", name: "Mutation" }
  { operator: "Subscribe", name: "Subscription" }
]


or Object is best
{
   Query: ["Me", "Info", "Post"],
   Mutation: ["Login", "Register"],
   Subscription: ["Subscribe"]
}

I can parse the query from request using parse function from graphql library to get operator and name using

import { parse } from "graphql"



const query:any = parse(context.req.body?.query)
const operator = query.definitions[0]?.operation
const name = query.definitions[0]?.selectionSet?.selections[0]?.name?.value

Now i need list all defined query, mutation, subscribe in schema? is it possible?

Thanks

You could try leaving introspection on. [docs]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM