我想从服务器获取架构。
我可以获取具有类型的所有实体,但是无法获取属性。

获取所有类型:

query {
  __schema {
    queryType {
      fields {
        name
        type {
          kind
          ofType {
            kind
            name
          }
        }
      }
    }
  }
}

如何获取类型的属性:
__type(name: "Person") {
    kind
    name
    fields {
      name
      type {
        kind
        name
        description
      }
    }
  }

如何仅通过1个请求获得具有属性的所有类型?或更妙的是:我如何获得带有变异子,枚举,类型的整个架构...

最佳答案

更新

现在建议使用 graphql-cli 来获取和更新模式。

以下命令将帮助您入门:

# install via NPM
npm install -g graphql-cli

# Setup your .graphqlconfig file (configure endpoints + schema path)
graphql init

# Download the schema from the server
graphql get-schema

您甚至可以通过以下方式监听模式更改并不断更新模式:
graphql get-schema --watch



获取GraphQL模式的最简单方法是使用CLI工具get-graphql-schema

您可以通过NPM安装它:
npm install -g get-graphql-schema

有两种获取架构的方法。 1)GraphQL IDL格式或2)JSON自省(introspection)查询格式。

GraphQL IDL格式
get-graphql-schema ENDPOINT_URL > schema.graphql

JSON内省(introspection)格式
get-graphql-schema ENDPOINT_URL --json > schema.json

要么
get-graphql-schema ENDPOINT_URL -j > schema.json

有关更多信息,请引用以下教程:How to download the GraphQL IDL Schema

关于schema - 获取GraphQL整个架构查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37397886/

10-12 05:01