13.Introspection Schema内省图式
Relay Modern uses Babel Relay Plugin which requires you to provide your GraphQL schema data.
Relay Modern使用Babel Relay Plugin,它要求您提供GraphQL模式数据。
Graphene comes with a Django management command to dump your schema data to schema.json
which is compatible with babel-relay-plugin.
Graphene附带了一个Django管理命令,可以将模式数据转储到与babel-relay-plugin兼容的schema.json
。
Usage 使用
Include graphene_django
to INSTALLED_APPS
in your project settings:
在项目设置中添加graphene_django
到INSTALLED_APPS
:
INSTALLED_APPS += ('graphene_django')
Assuming your Graphene schema is at tutorial.quickstart.schema
, run the command:
假设你的Graphene 模式是tutorial.quickstart.schema
,运行命令:
./manage.py graphql_schema --schema tutorial.quickstart.schema --out schema.json
It dumps your full introspection schema to schema.json
inside your project root directory. Point babel-relay-plugin
to this file and you’re ready to use Relay with Graphene GraphQL implementation.
它将您的全部自省模式转储到 schema.json
在项目根目录中。将babel-relay-plugin
指向这个文件,就可以在Graphene GraphQL实现中使用Relay了。
The schema file is sorted to create a reproducible canonical representation.
对模式文件进行排序以创建可复制的规范表示。
GraphQL SDL Representation GraphQL SDL表示法
The schema can also be exported as a GraphQL SDL file by changing the file extension :
通过更改文件扩展名,也可以将架构导出为GraphQL SDL文件:
./manage.py graphql_schema --schema tutorial.quickstart.schema --out schema.graphql
When exporting the schema as a .graphql
file the --indent
option is ignored.
将架构导出为“.graphql”文件时,“--indent”选项将被忽略。
Advanced Usage 高级用法
The --indent
option can be used to specify the number of indentation spaces to be used in the output. Defaults to None which displays all data on a single line.
--indent
选项可用于指定输出中要使用的缩进空格数。默认为“无”,在一行上显示所有数据。
The --watch
option can be used to run ./manage.py graphql_schema
in watch mode, where it will automatically output a new schema every time there are file changes in your project
--watch
选项可用于运行./manage.py graphql_schema
处于监视模式,在这种模式下,每当项目中发生文件更改时,它都会自动输出一个新的模式
To simplify the command to ./manage.py graphql_schema
, you can specify the parameters in your settings.py:
将命令简化为./manage.py graphql_schema
,可以指定settings.py:
GRAPHENE = {
'SCHEMA': 'tutorial.quickstart.schema',
'SCHEMA_OUTPUT': 'data/schema.json', # defaults to schema.json,
'SCHEMA_INDENT': 2, # Defaults to None (displays all data on a single line)
}
Running ./manage.py graphql_schema
dumps your schema to <project root>/data/schema.json
.
正在运行./manage.py graphql_schema
将架构转储到<project root>/data/schema.json
.
Help 帮助
Run ./manage.py graphql_schema -h
for command usage.
运行./manage.py graphql_schema -h
以了解命令用法。