简体   繁体   中英

How to get the type names of the query in graphql

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 ?

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

Eg

 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

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