获取GraphQL整个架构查询 [英] Get GraphQL whole schema query

查看:46
本文介绍了获取GraphQL整个架构查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to get the schema from the server. I can get all entities with the types but I'm unable to get the properties.

获取所有类型:

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

如何获取类型的属性

__type(name: "Person") {
    kind
    name
    fields {
      name
      type {
        kind
        name
        description
      }
    }
  }

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

How can I get all types with the properties in only 1 request? Or ever better: How can I get the whole schema with the mutators, enums, types ...

推荐答案

更新

现在建议使用 graphql-cli 并更新您的架构.

Using graphql-cli is now the recommended workflow to get and update your schema.

以下命令将帮助您入门:

The following commands will get you started:

# 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

您甚至可以通过运行以下命令监听模式更改并不断更新模式:

You can even listen for schema changes and continuously update your schema by running:

graphql get-schema --watch


如果只想下载GraphQL模式,请使用以下方法:

In case you just want to download the GraphQL schema, use the following approach:

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

The easiest way to get a GraphQL schema is using the CLI tool get-graphql-schema.

您可以通过NPM安装它:

You can install it via NPM:

npm install -g get-graphql-schema

有两种获取模式的方法.1) GraphQL IDL 格式或2)JSON自省查询格式.

There are two ways to get your schema. 1) GraphQL IDL format or 2) JSON introspection query format.

get-graphql-schema ENDPOINT_URL > schema.graphql

JSON自省格式

get-graphql-schema ENDPOINT_URL --json > schema.json

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

有关更多信息,您可以参考以下教程:如何下载GraphQL IDL模式

For more information you can refer to the following tutorial: How to download the GraphQL IDL Schema

这篇关于获取GraphQL整个架构查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆