获取 GraphQL 整个架构查询 [英] Get GraphQL whole schema query
问题描述
我想从服务器获取架构.我可以获取具有类型的所有实体,但无法获取属性.
获取所有类型:
查询{__模式{查询类型{字段{名称类型 {种类类型{种类名称}}}}}}
如何获取类型的属性:
__type(name: "Person") {种类名称字段{名称类型 {种类名称描述}}}
如何仅在 1 个请求中获取具有属性的所有类型?或者更好:我怎样才能获得带有突变器、枚举、类型的整个模式......
更新
使用 graphql-cli
现在是获得并更新您的架构.
以下命令将帮助您入门:
# 通过 NPM 安装npm install -g graphql-cli# 设置你的 .graphqlconfig 文件(配置端点 + 模式路径)图形初始化# 从服务器下载模式graphql 获取架构
您甚至可以通过运行以下命令来监听架构更改并持续更新架构:
graphql get-schema --watch
<小时><块引用>
如果您只想下载 GraphQL 架构,请使用以下方法:
获取 GraphQL 架构的最简单方法是使用 CLI 工具 get-graphql-schema一>.
你可以通过 NPM 安装:
npm install -g get-graphql-schema
有两种方法可以获取您的架构.1) GraphQL IDL 格式或 2)JSON 内省查询格式.
GraphQL IDL 格式
get-graphql-schema ENDPOINT_URL >模式.graphql
JSON 内省格式
get-graphql-schema ENDPOINT_URL --json >架构.json
或
get-graphql-schema ENDPOINT_URL -j >架构.json
更多信息可以参考以下教程:如何下载GraphQL IDL Schema
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.
Getting all types:
query {
__schema {
queryType {
fields {
name
type {
kind
ofType {
kind
name
}
}
}
}
}
}
How to get the properties for type:
__type(name: "Person") {
kind
name
fields {
name
type {
kind
name
description
}
}
}
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 ...
Update
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
In case you just want to download the GraphQL schema, use the following approach:
The easiest way to get a GraphQL schema is using the CLI tool get-graphql-schema.
You can install it via NPM:
npm install -g get-graphql-schema
There are two ways to get your schema. 1) GraphQL IDL format or 2) JSON introspection query format.
GraphQL IDL format
get-graphql-schema ENDPOINT_URL > schema.graphql
JSON introspection format
get-graphql-schema ENDPOINT_URL --json > schema.json
or
get-graphql-schema ENDPOINT_URL -j > schema.json
For more information you can refer to the following tutorial: How to download the GraphQL IDL Schema
这篇关于获取 GraphQL 整个架构查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!