例子3{
user(id: 4) {
name
}
}例子4{
"user": {
"name": "Mark Zuckerberg"
}
}: 表示,而词法规则的产生式用双冒号 :: 表示。list,optCommentCharlist,opt NameContinue| A | B | C | D | E | F | G | H | I | J | K | L | M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
| a | b | c | d | e | f | g | h | i | j | k | l | m |
| n | o | p | q | r | s | t | u | v | w | x | y | z |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|
name,Name 和 NAME都指代不同的名称。下划线很重要,它表示other_name和othername是两个不同的名称。list| query | mutation | subscription |
|---|
例子5mutation {
likeStory(storyID: 12345) {
story {
likeCount
}
}
}例子6{
field
}list}Example № 7Example № 7{
id
firstName
lastName
}id , firstName 和 lastName 字段构成了一个选择集。选择集还可以包含片段引用。optNameArgumentsoptDirectivesoptSelectionSetopt示例#8{
me {
id
firstName
lastName
birthday {
month
day
}
friends {
name
}
}
}例子9# `me` could represent the currently logged in viewer.
{
me {
name
}
}
# `user` represents one of many users in a graph of data, referred to by a
# unique identifier.
{
user(id: 4) {
name
}
}id)及其特定的个人资料图片size:示例 10{
user(id: 4) {
id
name
profilePic(size: 100)
}
}例子11{
user(id: 4) {
id
name
profilePic(width: 100, height: 50)
}
}示例 12{
picture(width: 200, height: 100)
}例子13{
picture(height: 100, width: 200)
}示例 14{
user(id: 4) {
id
name
smallPic: profilePic(size: 64)
bigPic: profilePic(size: 1024)
}
}示例 15{
"user": {
"id": 4,
"name": "Mark Zuckerberg",
"smallPic": "https://cdn.site.io/pic-4-64.jpg",
"bigPic": "https://cdn.site.io/pic-4-1024.jpg"
}
}示例 16{
zuck: user(id: 4) {
id
name
}
}示例 17{
"zuck": {
"id": 4,
"name": "Mark Zuckerberg"
}
}opt示例 18query noFragments {
user(id: 4) {
friends(first: 10) {
id
name
profilePic(size: 50)
}
mutualFriends(first: 10) {
id
name
profilePic(size: 50)
}
}
}示例 19query withFragments {
user(id: 4) {
friends(first: 10) {
...friendFields
}
mutualFriends(first: 10) {
...friendFields
}
}
}
fragment friendFields on User {
id
name
profilePic(size: 50)
}... ),可以消耗片段。片段选择的所有字段将被添加到与片段调用相同级别的字段选择中。这是通过多个级别的片段扩展来实现的。示例 20query withNestedFragments {
user(id: 4) {
friends(first: 10) {
...friendFields
}
mutualFriends(first: 10) {
...friendFields
}
}
}
fragment friendFields on User {
id
name
...standardProfilePic
}
fragment standardProfilePic on User {
profilePic(size: 50)
}noFragments、withFragments、 和withNestedFragments都生成相同的响应对象。noFragments、withFragments、 和withNestedFragments都生成相同的响应对象。friendFields 可以在查询 的上下文中使用 User。示例 21query FragmentTyping {
profiles(handles: ["zuck", "coca-cola"]) {
handle
...userFragment
...pageFragment
}
}
fragment userFragment on User {
friends {
count
}
}
fragment pageFragment on Page {
likers {
count
}
}profiles 根字段返回一个列表,其中每个元素可以是 Page 或 User 。当 profiles 结果中的对象是 User 时,将存在 friends 而 likers 将不存在。相反,当结果是 Page 时,将存在 likers 而 friends 将不存在。示例 22{
"profiles": [
{
"handle": "zuck",
"friends": { "count": 1234 }
},
{
"handle": "coca-cola",
"likers": { "count": 90234512 }
}
]
}opt Directivesopt SelectionSetquery FragmentTyping示例中得到了演示。我们可以使用内联片段完成同样的事情。示例 23query inlineFragmentTyping {
profiles(handles: ["zuck", "coca-cola"]) {
handle
... on User {
friends {
count
}
}
... on Page {
likers {
count
}
}
}
}示例 24query inlineFragmentNoType($expandedInfo: Boolean) {
user(handle: "zuck") {
id
name
... @include(if: $expandedInfo) {
firstName
lastName
birthday
}
}
} Const:opt 0opt NonZeroDigitDigit list,opt0x123 和 123L 没有有效的词法表示。listopt Digit list| e | E |
|---|
| + | - |
|---|
0x1.2p3没有有效的词汇表示。| ture | false |
|---|
trueandfalse代表两个布尔值。list"list,opt"""| " | \ | / | b | f | n | r | t |
|---|
""") 括起来的字符序列。空格、行终止符、引号和反斜杠字符都可以不转义地使用,以启用逐字文本。字符必须都是有效的 SourceCharacter。示例 25mutation {
sendEmail(message: """
Hello,
World!
Yours,
GraphQL.
""")
}示例 26mutation {
sendEmail(message: "Hello,\n World!\n\nYours,\n GraphQL.")
}示例 27"""
This starts with and ends with an empty line,
which makes it easier to read.
"""反例#28"""This does not start with or end with any empty lines,
which makes it a little harder to read."""list"| Escaped Character | Code Point | Character Name |
|---|---|---|
| " | U+0022 | double quote |
| \ | U+005C | reverse solidus (back slash) |
| / | U+002F | solidus (forward slash) |
| b | U+0008 | backspace |
| f | U+000C | form feed |
| n | U+000A | line feed (new line) |
| r | U+000D | carriage return |
| t | U+0009 | horizontal tab |
listopt """""" 。rawValue)lines be the result of splitting rawValue by LineTerminator.commonIndent be null.line in lines:indent is less than length:示例 29{
field(arg: null)
field
}MOBILE_WEB)。建议枚举值“全部大写”。枚举值仅在已知精确枚举类型的上下文中使用。因此,没有必要在文字中提供枚举类型名称。Const ListValueConst:[ ]。列表文字的值可以是任何值文字或变量(例如[1, 2, 3])。Const:Const{ }。对象文字的值可以是任何输入值文字或变量(例如{ name: "Hello world", score: 1.0 })。我们将输入对象的文字表示称为“对象文字”。示例 30{
nearestThing(location: { lon: 12.43, lat: -53.211 })
}示例#31{
nearestThing(location: { lat: -53.211, lon: 12.43 })
}inputObject为不带字段的新输入对象值。字段name为 Name in field。value为评估``field中 Value 的结果。``向名为name 的inputObject添加一个包含值value的字段。````输入对象list)optDirectivesConstoptConst示例#32query getZuckProfile($devicePicSize: Int) {
user(id: 4) {
id
name
profilePic(size: $devicePicSize)
}
}profilePicof size 60:示例#33{
"devicePicSize": 60
}示例#34type Person
@addExternalFields(source: "profiles")
@excludeField(name: "photo") {
name: String
}示例 35type Person
@excludeField(name: "photo")
@addExternalFields(source: "profiles") {
name: String
}示例#36"""
A simple GraphQL schema which is well described.
"""
schema {
query: Query
}
"""
Root type for all your query operations
"""
type Query {
"""
Translates a string from a given language into a different language.
"""
translate(
"The original language that `text` is provided in."
fromLanguage: Language
"The translated language to be returned."
toLanguage: Language
"The text to be translated."
text: String
): String
}
"""
The set of languages supported by `translate`.
"""
enum Language {
"English"
EN
"French"
FR
"Chinese"
CH
}示例 37query {
myName
}示例#38type Query {
myName: String
}示例#39mutation {
setName(name: "Zuck") {
newName
}
}示例 40schema {
query: MyQueryRootType
mutation: MyMutationRootType
}
type MyQueryRootType {
someField: String
}
type MyMutationRootType {
setSomeField(to: String): String
}示例 41type Query {
someField: String
}Scalar. 标量表示原始值,如字符串或整数。通常,标量场的可能响应是可枚举的。GraphQLEnum在这些情况下提供了一种类型,其中该类型指定有效响应的空间。Object类型,它定义一组字段,其中每个字段是系统中的另一种类型,允许定义任意类型层次结构。Interface)和联合(Union)。Interface定义字段列表;Object类型和实现此接口的其他接口类型保证实现这些字段。每当一个字段声明它将返回一个接口类型时,它将在 执行期间返回一个有效的实现对象类型。Union定义了可能类型的列表;与接口类似,每当类型系统声明将返回联合时,就会返回可能的类型之一。Input Object类型允许模式准确定义所需的数据。List为此原因提供了该类型,并包装了另一个类型。Non-Null类型包装另一个类型,并表示结果值永远不会为空(并且字段错误不能导致空值)。类型):类型是 List 类型或 Non-Null 类型:unwrappedType为type的未包装类型。unwrappedType )类型是标量、枚举或输入对象类型:类型)类型是List类型或Non-Null类型:unwrappedType为type的未包装类型。unwrappedType )类型是标量、对象、接口、联合或枚举类型:__Schema,必须包含所有引用的内置标量。如果架构中的任何位置都没有引用内置标量类型(没有该类型的字段、参数或输入字段),则不得包含它。UUID,该标量在序列化为字符串时符合 RFC 4122。当查询 类型的字段时UUID,您可以依靠使用符合 RFC 4122 的解析器解析结果的能力。潜在有用的自定义标量的另一个示例是URL,它序列化为字符串,但由服务器保证是有效的 URL。UUID标量的 GraphQL 服务可以链接到 RFC 4122,或定义该 RFC 的合理子集的某个自定义文档。如果存在标量规范 URL ,则了解它的系统和工具应该符合其描述的规则。示例 42scalar UUID @specifiedBy(url: "https://tools.ietf.org/html/rfc4122")
scalar URL @specifiedBy(url: "https://tools.ietf.org/html/rfc3986")1.0。1浮点数1.0或返回123字符串"123"。在强制 可能丢失数据的情况下,引发字段错误更合适。例如,浮点数1.2应该引发字段错误,而不是被截断为1.1.0整数1或123.0字符串"123"。1.0对于整数输入值1。所有其他输入值(包括具有数字内容的字符串)都必须引发请求错误,指示类型不正确。如果输入值以其他方式表示有限 IEEE 754 无法表示的值(例如 NaN、Infinity 或超出可用精度的值),则必须引发请求错误。"true"此类示例可能包括返回布尔真值的字符串或"1"整数的字符串1。trueor false。如果支持,响应格式应使用内置布尔类型;否则,他们应该使用整数1和的表示0。true非零数字。"4")或整数(例如4或-4)输入值都应强制转换为 ID,以适合给定 GraphQL 服务所需的 ID 格式。任何其他输入值,包括浮点输入值(例如4.0),都必须引发请求错误,指示类型不正确。Person可以描述为:示例 43type Person {
name: String
age: Int
picture: Url
}name是一个将产生String值的字段,age是一个将产生Int值的字段,picture是一个将产生Url值的字段。Person:示例 44{
name
age
picture
}示例 45{
"name": "Mark Zuckerberg",
"age": 30,
"picture": "http://some.cdn/picture.jpg"
}示例 46{
age
name
}示例 47{
"age": 30,
"name": "Mark Zuckerberg"
}Person类型可能包括relationship:示例 48type Person {
name: String
age: Int
picture: Url
relationship: Person
}反例第 49 号{
name
relationship
}示例 50{
name
relationship {
name
}
}示例 51{
"name": "Mark Zuckerberg",
"relationship": {
"name": "Priscilla Chan"
}
}@skip 或 @include 指令跳过的字段或片段。使用 CollectFields() 算法可以正确产生这个顺序。{foo, bar}按该顺序查询两个字段,则生成的 JSON 序列化应包含{"foo": "...", "bar": "..."}相同的顺序。示例 52{
foo
...Frag
qux
}
fragment Frag on Query {
bar
baz
}示例 53{
"foo": 1,
"bar": 2,
"baz": 3,
"qux": 4
}示例 54{
foo
...Ignored
...Matching
bar
}
fragment Ignored on UnknownType {
qux
baz
}
fragment Matching on Query {
bar
qux
foo
}示例 55{
"foo": 1,
"bar": 2,
"qux": 3
}示例 56{
foo @skip(if: true)
bar
foo
}示例 57{
"bar": 1,
"foo": 2
}fieldType )返回true 的类型。argumentType )返回true 的类型。objectType。interfaceType 的每个接口,IsValidImplementation ( objectType , interfaceType )必须为 true。类型,实现类型):ImplementType声明它实现任何接口,则type也必须声明它实现这些接口。type 必须为ImplementType中定义的每个字段包含一个同名的字段。field为type上的命名字段。ImplementedField为ImplementedType上的命名字段。ImplementField中定义的每个参数, field必须包含一个同名的参数。 (字段上的命名参数必须接受与ImplementedField上的命名参数相同的类型(不变)。)field可以包含在implementedField中未定义的附加参数,但任何附加参数都不是必需的,例如不得为非空类型。ImplementField字段的返回类型的返回类型或其子类型(协变)的类型:fieldType为``field的返回类型。implementedFieldType为implementedField的返回类型。fieldType , ImplementedFieldType ) 必须为 true。字段类型,实现字段类型):fieldType是非空类型:nullableType为fieldType的展开可为空类型。implementedNullableType是 Non-Null 类型,则将 implementedNullableType 设置为implementedFieldType的展开的可空类型,否则直接将其设置为implementedFieldType。nullableType , implementedNullableType )。fieldType是 List 类型并且implementedFieldType也是 List 类型:itemType 为fieldType的展开项目类型。ImplementedItemType为ImplementedFieldType的展开项类型。itemType , implementedItemType )。fieldType 与ImplementedFieldType 的类型相同,则返回 true。fieldType是 Object 类型,implementedFieldType是 Union 类型,并且fieldType 是ImplementedFieldType的可能类型,则返回 true。fieldType是对象或接口类型,并且ImplementedFieldType是接口类型,并且fieldType声明它实现ImplementedFieldType,则返回 true。Person带有picture字段的类型可以接受参数来确定要返回的图像大小。示例 58type Person {
name: String
picture(size: Int): Url
}示例 59{
name
picture(size: 600)
}示例 60{
"name": "Mark Zuckerberg",
"picture": "http://some.cdn/picture_600.jpg"
}@deprecated指令用于指示字段已弃用:示例 61type ExampleType {
oldField: String @deprecated
}Story类型中:示例 62extend type Story {
isHiddenLocally: Boolean
}User类型中而不添加字段:示例 63extend type User @addedDirectiveNamedEntity可以描述所需的字段和类型,例如Person,或者Business然后可以实现该接口以保证该字段将始终存在。Business实现以下示例中的NamedEntity和接口。ValuedEntity示例 64interface NamedEntity {
name: String
}
interface ValuedEntity {
value: Int
}
type Person implements NamedEntity {
name: String
age: Int
}
type Business implements NamedEntity & ValuedEntity {
name: String
value: Int
employeeCount: Int
}Contact可能指的是NamedEntity。示例 65type Contact {
entity: NamedEntity
phoneNumber: String
address: String
}Contact可以选择公共字段的选择集。示例 66{
entity {
name
}
phoneNumber
}entity返回 a NamedEntity,并且name是在 上定义的NamedEntity,因此它是有效的。但是,以下内容不是针对 的有效选择集Contact:反例第 67 号{
entity {
name
age
}
phoneNumber
}entity引用了NamedEntity, 并且age未在该接口上定义。仅当 的结果为时,查询age才有效;这可以使用片段或内联片段来表达:entity``Person示例 68{
entity {
name
... on Person {
age
}
}
phoneNumber
}示例 69interface Node {
id: ID!
}
interface Resource implements Node {
id: ID!
url: String
}Image就无法实现:Resource``Node示例 70interface Node {
id: ID!
}
interface Resource implements Node {
id: ID!
url: String
}
interface Image implements Resource & Node {
id: ID!
url: String
thumbnail: String
}Node和Named实现它们自己和彼此:反例#71interface Node implements Named & Node {
id: ID!
name: String
}
interface Named implements Node & Named {
id: ID!
name: String
}fieldType )返回true 的类型。argumentType )返回 true 的类型。implementingType。对于声明为实现的每个接口,IsValidImplementation ( implementType , implementedType )必须为true。NamedEntity在此示例中,扩展数据字段与实现它的类型一起添加到类型中:示例 72extend interface NamedEntity {
nickname: String
}
extend type Person {
nickname: String
}
extend type Business {
nickname: String
}NamedEntity类型中而不添加字段:示例 73extend interface NamedEntity @addedDirective__typename除外),则不能在此类型上查询任何字段。示例 74union SearchResult = Photo | Person
type Person {
name: String
age: Int
}
type Photo {
height: Int
width: Int
}
type SearchQuery {
firstSearchResult: SearchResult
}反例#75{
firstSearchResult {
name
height
}
}示例 76{
firstSearchResult {
... on Person {
name
}
... on Photo {
height
}
}
}|字符来定义,以在表示较长的可能类型列表时帮助格式化:示例 77union SearchResult =
| Photo
| PersonDirection定义了一个名为的 Enum 类型:示例 78enum Direction {
NORTH
EAST
SOUTH
WEST
}Point2D在此示例中,称为描述x和输入的输入对象y:示例 79input Point2D {
x: Float
y: Float
}self或值为null。示例#80input Example {
self: Example
value: String
}self可能是空列表。示例#81input Example {
self: [Example!]!
value: String
}self无法为该字段提供有限值。反例#82input Example {
value: String
self: Example!
}First.second此示例也是无效的,因为通过和字段存在非空单数循环引用Second.first。反例#83input First {
second: Second!
value: String
}
input Second {
first: First!
value: String
}String以下是具有字段a和必填(非空)Int!字段的输入对象类型的输入强制示例b:示 例#84input ExampleInputObject {
a: String
b: Int!
}| 字面值 | 变量 | 强制价值 |
|---|---|---|
{ a: "abc", b: 123 } | {} | { a: "abc", b: 123 } |
{ a: null, b: 123 } | {} | { a: null, b: 123 } |
{ b: 123 } | {} | { b: 123 } |
{ a: $var, b: 123 } | { var: null } | { a: null, b: 123 } |
{ a: $var, b: 123 } | {} | { b: 123 } |
{ b: $var } | { var: 123 } | { b: 123 } |
$var | { var: { b: 123 } } | { b: 123 } |
"abc123" | {} | 错误:值不正确 |
$var | { var: "abc123" } | 错误:值不正确 |
{ a: "abc", b: "123" } | {} | 错误:字段b的值不正确`` |
{ a: "abc" } | {} | 错误:缺少必填字段b |
{ b: $var } | {} | 错误:缺少必填字段b。 |
$var | { var: { a: "abc" } } | 错误:缺少必填字段b |
{ a: "abc", b: null } | {} | 错误:b必须为非空。 |
{ b: $var } | { var: null } | 错误:b必须为非空。 |
{ b: 123, c: "xyz" } | {} | 错误:意外的字段c |
inputFieldType )返回 true 的类型。pets: [Pet]。允许嵌套列表:matrix: [[Int]].| 预期类型 | 提供的价值 | 强制价值 |
|---|---|---|
[Int] | [1, 2, 3] | [1, 2, 3] |
[Int] | [1, "b", true] | 错误:项目值不正确 |
[Int] | 1 | [1] |
[Int] | null | null |
[[Int]] | [[1], [2, 3]] | [[1], [2, 3]] |
[[Int]] | [1, 2, 3] | 错误:项目值不正确 |
[[Int]] | 1 | [[1]] |
[[Int]] | null | null |
name: String!。反例#85{
fieldWithNonNullArg
}反例#86{
fieldWithNonNullArg(nonNullArg: null)
}示例#87query withNullableVariable($var: String) {
fieldWithNonNullArg(nonNullArg: $var)
}[T!]),则该 List 可能不包含任何null项。但是,如果 Non-Null 的内部类型是 List(例如[T]!),则不接受null ,但接受空列表。| 预期类型 | 内在价值 | 强制结果 |
|---|---|---|
[Int] | [1, 2, 3] | [1, 2, 3] |
[Int] | null | null |
[Int] | [1, 2, null] | [1, 2, null] |
[Int] | [1, 2, Error] | [1, 2, null](已记录错误) |
[Int]! | [1, 2, 3] | [1, 2, 3] |
[Int]! | null | 错误:值不能为空 |
[Int]! | [1, 2, null] | [1, 2, null] |
[Int]! | [1, 2, Error] | [1, 2, null](已记录错误) |
[Int!] | [1, 2, 3] | [1, 2, 3] |
[Int!] | null | null |
[Int!] | [1, 2, null] | null(记录了强制错误) |
[Int!] | [1, 2, Error] | null(已记录错误) |
[Int!]! | [1, 2, 3] | [1, 2, 3] |
[Int!]! | null | 错误:值不能为空 |
[Int!]! | [1, 2, null] | 错误:项目不能为空 |
[Int!]! | [1, 2, Error] | 错误:项目中发生错误 |
| QUERY |
|---|
| MUTATION |
| SUBSCRIPTION |
| FIELD |
| FRAGMENT_DEFINITION |
| FRAGMENT_SPREAD |
| INLINE_FRAGMENT |
| VARIABLE_DEFINITION |
| 模式 |
|---|
| SCALAR |
| OBJECT |
| FIELD_DEFINITION |
| ARGUMENT_DEFINITION |
| INTERFACE |
| UNION |
| ENUM |
| ENUM_VALUE |
| INPUT_OBJECT |
| INPUT_FIELD_DEFINITION |
@skip和@include指令。@specifiedBy指令。示例#88directive @example on FIELD
fragment SomeFragment on SomeType {
field @example
}|以在表示较长的可能位置列表时帮助格式化:示例#89directive @example on
| FIELD
| FRAGMENT_SPREAD
| INLINE_FRAGMENT@example注释字段和参数定义:示例 90directive @example on FIELD_DEFINITION | ARGUMENT_DEFINITION
type SomeType {
field(arg: Int @example): String @example
}示例 91directive @delegateField(name: String!) repeatable on OBJECT | INTERFACE
type Book @delegateField(name: "pageCount") @delegateField(name: "author") {
id: ID!
}
extend type Book @delegateField(name: "index")反例第 92 号directive @invalidExample(arg: String @invalidExample) on ARGUMENT_DEFINITIONargumentType )返回true 的类型。directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT@skip 内置指令,并允许在执行期间进行条件排除,如if参数所描述的。experimentalField仅当变量$someTest具有值时才会被查询false。示例 93query myQuery($someTest: Boolean!) {
experimentalField @skip(if: $someTest)
}directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT@include 可以应用于字段、片段扩展和内联片段,它允许在执行过程中根据 if 参数的条件进行条件包含。$someTest 的值为 true 时,experimentalField 才会被查询。示例 94query myQuery($someTest: Boolean!) {
experimentalField @include(if: $someTest)
}directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE@deprecated 内置指令在类型系统定义语言中用于指示 GraphQL 服务架构中已弃用的部分,例如类型上已弃用的字段或已弃用的枚举值。oldField不推荐使用类型定义,而改用newField.示例 95type ExampleType {
newField: String
oldField: String @deprecated(reason: "Use `newField`.")
}directive @specifiedBy(url: String!) on SCALAR@specifiedBy 指令在类型系统定义语言中使用,以提供标量规范 URL,用于指定自定义标量类型的行为。URL 应指向人类可读的数据格式、序列化和强制规则规范。它不得出现在内置标量类型上。UUID在此示例中,使用指向相关 IETF 规范的 URL 定义了 的自定义标量类型。示例 96scalar UUID @specifiedBy(url: "https://tools.ietf.org/html/rfc4122")示例 97type User {
id: String
name: String
birthday: Date
}示例 98{
__type(name: "User") {
name
fields {
name
type {
name
}
}
}
}示例 99{
"__type": {
"name": "User",
"fields": [
{
"name": "id",
"type": { "name": "String" }
},
{
"name": "name",
"type": { "name": "String" }
},
{
"name": "birthday",
"type": { "name": "Date" }
}
]
}
}__typename: String!类型名称自省是通过任何对象、接口或联合上的元字段来完成的。它返回执行期间此时具体对象类型的名称。__typename它是隐式的,不会出现在任何定义类型的字段列表中。__typename不能作为根字段包含在订阅操作中。__schema,并且__type可从查询操作的根的类型访问。__schema: __Schema!
__type(name: String!): __Typedescription类型字段String,以允许类型设计者除了功能之外还可以发布文档。GraphQL 服务可以使用 Markdown 语法(由CommonMarkdescription指定)返回字段。因此,建议任何显示工具都使用兼容 CommonMark 的 Markdown 渲染器。descriptionisDeprecated: Boolean) 以及弃用原因的描述 ( deprecationReason: String)。type __Schema {
description: String
types: [__Type!]!
queryType: __Type!
mutationType: __Type
subscriptionType: __Type
directives: [__Directive!]!
}
type __Type {
kind: __TypeKind!
name: String
description: String
# must be non-null for OBJECT and INTERFACE, otherwise null.
fields(includeDeprecated: Boolean = false): [__Field!]
# must be non-null for OBJECT and INTERFACE, otherwise null.
interfaces: [__Type!]
# must be non-null for INTERFACE and UNION, otherwise null.
possibleTypes: [__Type!]
# must be non-null for ENUM, otherwise null.
enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
# must be non-null for INPUT_OBJECT, otherwise null.
inputFields: [__InputValue!]
# must be non-null for NON_NULL and LIST, otherwise null.
ofType: __Type
# may be non-null for custom SCALAR, otherwise null.
specifiedByURL: String
}
enum __TypeKind {
SCALAR
OBJECT
INTERFACE
UNION
ENUM
INPUT_OBJECT
LIST
NON_NULL
}
type __Field {
name: String!
description: String
args: [__InputValue!]!
type: __Type!
isDeprecated: Boolean!
deprecationReason: String
}
type __InputValue {
name: String!
description: String
type: __Type!
defaultValue: String
}
type __EnumValue {
name: String!
description: String
isDeprecated: Boolean!
deprecationReason: String
}
type __Directive {
name: String!
description: String
locations: [__DirectiveLocation!]!
args: [__InputValue!]!
isRepeatable: Boolean!
}
enum __DirectiveLocation {
QUERY
MUTATION
SUBSCRIPTION
FIELD
FRAGMENT_DEFINITION
FRAGMENT_SPREAD
INLINE_FRAGMENT
VARIABLE_DEFINITION
SCHEMA
SCALAR
OBJECT
FIELD_DEFINITION
ARGUMENT_DEFINITION
INTERFACE
UNION
ENUM
ENUM_VALUE
INPUT_OBJECT
INPUT_FIELD_DEFINITION
}__Schema类型从元字段返回__schema,并提供有关 GraphQL 服务架构的所有信息。description可能返回 String 或null。queryType是查询操作的根类型。mutationType是突变操作的根类型(如果支持)。否则为null。subscriptionType是订阅操作的根类型(如果支持)。否则为null。types必须返回此模式中包含的所有命名类型的集合。可以通过任何内省类型的字段找到的任何命名类型都必须包含在该集合中。directives必须返回此模式中可用的所有指令的集合,包括所有内置指令。__Type是类型自省系统的核心,它代表系统中的所有类型:命名类型(例如标量和对象类型)和类型修饰符(例如列表和非空类型)。ofType。该修改类型可以递归地成为修改类型,表示列表、不可空值及其组合,最终修改命名类型。__TypeKind。__Type给定枚举的每个可能值的预期字段__TypeKind:specifiedByURLkind必须返回__TypeKind.SCALAR。name必须返回一个字符串。description可能返回 String 或null。specifiedByURL可以为自定义标量返回一个 String (以 URL 的形式),否则必须为null。__Type、__Field等)是对象的示例。kind必须返回__TypeKind.OBJECT。name必须返回一个字符串。description可能返回 String 或null。fields必须返回可以为此类型选择的字段集。includeDeprecated接受默认为false 的参数。如果为true,则还会返回已弃用的字段。interfaces必须返 回对象实现的接口集(如果没有,则interfaces必须返回空集)。possibleTypes。类型可以成为联合的一部分,而无需修改该类型。kind必须返回__TypeKind.UNION。name必须返回一个字符串。description可能返回 String 或null。possibleTypes返回可以在此联合中表示的类型列表。它们必须是对象类型。possibleTypes。kind必须返回__TypeKind.INTERFACE。name必须返回一个字符串。description可能返回 String 或null。fields必须返回该接口所需的字段集。includeDeprecated接受默认为false 的参数。如果为true,则还会返回已弃用的字段。interfaces必须返回对象实现的接口集(如果没有,则interfaces必须返回空集)。possibleTypes返回实现此接口的类型列表。它们必须是对象类型。kind必须返回__TypeKind.ENUM。name必须返回一个字符串。description可能返回 String 或null。enumValues必须以 的列表形式返回枚举值集__EnumValue。必须至少有一个,并且它们必须具有唯一的名称。includeDeprecated接受默认为false 的参数。如果为true,则还会返回已弃用的枚举值。Point可以定义为:示例 100input Point {
x: Int
y: Int
}kind必须返回__TypeKind.INPUT_OBJECT。name必须返回一个字符串。description可能返回 String 或null。inputFields必须以 的列表形式返回输入字段集__InputValue。ofType,该实例定义列表中每个项目的类型。ofType本身可以是修改类型,允许表示列表的列表或非空列表。kind必须返回__TypeKind.LIST。ofType必须返回任何类型。ofType字段中包装另一个类型实例。非 null 类型不允许null作为响应,并指示参数和输入对象字段所需的输入。ofType字段中的修改类型本身可以是修改的列表类型,允许表示非空列表。但是,它不能是修改的 Non-Null 类型,以避免出现冗余的 Non-Null 的 Non-Null。kind必须返回__TypeKind.NON_NULL。ofType必须返回除非空之外的任何类型。__Field类型表示对象或接口类型中的每个字段。name必须返回一个字符串description可能返回 String 或 nullargs``__InputValue返回表示该字段接受的参数的列表。type必须返回一个__Type表示该字段返回值的类型。isDeprecated如果不应再使用此字段,则返回 true ,否则返回 false。deprecationReason(可选)提供不推荐使用该字段的原因。__InputValue类型表示字段和指令参数以及inputFields输入对象的类型。name必须返回一个字符串description可能返回 String 或 nulltype必须返回__Type表示此输入值期望的类型。defaultValue在运行时未提供值的情况下,可能会返回此输入值使用的默认值的字符串编码(使用 GraphQL 语言)。如果此输入值没有默认值,则返回 null。__EnumValue类型表示枚举的可能值之一。name必须返回一个字符串description可能返回 String 或nullisDeprecated如果不应再使用此枚举值,则返回true ,否则返回 false。deprecationReason(可选)提供不推荐使用此枚举值的原因。__Directive类型表示服务支持的指令。__DirectiveLocation:name必须返回一个字符串description可能返回 String 或nulllocations``__DirectiveLocation返回一个表示该指令可能放置的有效位置的列表。args``__InputValue返回表示该指令接受的参数的列表。isRepeatable必须返回一个布尔值,指示该指令是否可以在单个位置重复使用。示例 101type Query {
dog: Dog
}
enum DogCommand {
SIT
DOWN
HEEL
}
type Dog implements Pet {
name: String!
nickname: String
barkVolume: Int
doesKnowCommand(dogCommand: DogCommand!): Boolean!
isHouseTrained(atOtherHomes: Boolean): Boolean!
owner: Human
}
interface Sentient {
name: String!
}
interface Pet {
name: String!
}
type Alien implements Sentient {
name: String!
homePlanet: String
}
type Human implements Sentient {
name: String!
pets: [Pet!]
}
enum CatCommand {
JUMP
}
type Cat implements Pet {
name: String!
nickname: String
doesKnowCommand(catCommand: CatCommand!): Boolean!
meowVolume: Int
}
union CatOrDog = Cat | Dog
union DogOrHuman = Dog | Human
union HumanOrAlien = Human | Alien定义。定义必须是 ExecutableDefinition(它不能是 TypeSystemDefinitionOrExtension)。反例#102query getDogName {
dog {
name
color
}
}
extend type Dog {
color: String
}操作。operationName 为操作的名称。操作名称存在操作为名为operationName的文档中的所有操作定义。操作必须是一组操作。示例 103query getDogName {
dog {
name
}
}
query getOwnerName {
dog {
owner {
name
}
}
}反例第 104 号query getName {
dog {
name
}
}
query getName {
dog {
owner {
name
}
}
}反例#105query dogOperation {
dog {
name
}
}
mutation dogOperation {
mutateDog {
id
}
}操作为文档中的所有操作定义。anonymous为文档中的所有匿名操作定义。操作是大于 1 的集合:匿名必须为空。示例 106{
dog {
name
}
}反例第 107 号{
dog {
name
}
}
query getName {
dog {
owner {
name
}
}
}订阅subscriptionType为schema中的根订阅类型。SelectionSet成为subscription上的顶级选择集。variableValues为空集。groupedFieldSet 为 CollectFields ( subscriptionType , SelectionSet , variableValues )的结果。groupedFieldSet必须只有一个条目,该条目不能是内省字段。示例 108subscription sub {
newMessage {
body
sender
}
}示例 109subscription sub {
...newMessageFields
}
fragment newMessageFields on Subscription {
newMessage {
body
sender
}
}反例 110subscription sub {
newMessage {
body
sender
}
disallowedSecondRootField
}反例第 111 号subscription sub {
...multipleSubscriptions
}
fragment multipleSubscriptions on Subscription {
newMessage {
body
sender
}
disallowedSecondRootField
}反例 112subscription sub {
__typename
}选择。fieldName为选择的目 标字段``fieldName必须在范围内的类型上定义反例 113fragment fieldNotDefined on Dog {
meowVolume
}
fragment aliasedLyingFieldTargetNotDefined on Dog {
barkVolume: kawVolume
}示例 114fragment interfaceFieldSelection on Pet {
name
}反例 115fragment definedOnImplementorsButNotInterface on Pet {
nickname
}__typename除外。联合类型选择集中的字段只能通过片段间接查询。示例 116fragment inDirectFieldSelectionOnUnion on CatOrDog {
__typename
... on Pet {
name
}
... on Dog {
barkVolume
}
}