繁体   English   中英

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

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

嗨,我想在graphql中获取查询的类型名称。 它不应具有标量和枚举类型。

schema {
    query: Query
}

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

type Query {
    fetchLearningResource: LearningResource
}

当我运行fetchLearningResource查询时,我fetchLearningResource这里LearningResource一样获取它的类型。 有什么办法在GraphQL中做到这一点?

您应该在响应中找到作为字符串的查询的类型,搜索__typename

例如

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

编辑:

如果要在查询之前获取查询定义。 您可以从服务器获取自省查询。 以下是一些链接:

内省查询错误

检索整个架构问题

暂无
暂无

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

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