0

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

Peter Jack
  • 847
  • 5
  • 14
  • 29

1 Answers1

0

You could try leaving introspection on. [docs]

Dan
  • 179
  • 1
  • 1
  • 13
  • can you explain, any example ? @Dan – Peter Jack Jun 08 '21 at 11:51
  • Most graphql servers come with a Graphiql interface for testing and building queries. These interfaces can autocomplete inputs because graph is strong typed. The way these interfaces get the data they need for autocomplete is by doing introspection queries the graph server auto-generates. I don't know much about them but they could be used if it's necessary. IDK what OP is trying to do tho.. – Dan Jun 11 '21 at 20:39