0

Hi I want to get the type names of the query in graphql. It should not have scalar and enumerated types.

schema {
    query: Query
}

type LearningResource{
    id: ID
    name: String
    type: String
    children: [LearningResource]
}

type Query {
    fetchLearningResource: LearningResource
}

When I run fetchLearningResource query then I want to get the type of it like here LearningResource. Any way to do this in GraphQL ?

N Sharma
  • 33,489
  • 95
  • 256
  • 444

1 Answers1

0

You should find the Type of the Query as a string in the Response, search for __typename.

E.g.

response =>

{
   fetchLearningResource: {
      id: <id>
      name: "name"
      type: "type"
      children: [...]
      __typename: "LearningResource"
   }
}

EDIT:

If you want to fetch the query definition before you query. You could get the introspection query from the server. Here are some links:

introspection query error

retrieve whole schema question

Locco0_0
  • 3,420
  • 5
  • 30
  • 42
  • I don't have an response, before getting response I need to get the type of that query. I need to do something – N Sharma Feb 26 '18 at 10:55
  • Please explain better what you would like to do and why you need the query response type – Locco0_0 Feb 26 '18 at 12:36
  • I want to extract the type of the query then want to perform some action, like finding mapping against that type in database – N Sharma Feb 27 '18 at 16:30
  • I don't think this is easily possible. I will update my answer with some links – Locco0_0 Feb 28 '18 at 07:39