简体   繁体   English

如何在graphql中获取查询的类型名称

[英]How to get the type names of the query in graphql

Hi I want to get the type names of the query in graphql. 嗨,我想在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 . 当我运行fetchLearningResource查询时,我fetchLearningResource这里LearningResource一样获取它的类型。 Any way to do this in GraphQL ? 有什么办法在GraphQL中做到这一点?

You should find the Type of the Query as a string in the Response, search for __typename . 您应该在响应中找到作为字符串的查询的类型,搜索__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 检索整个架构问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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