[GraphQL] Tools

Introspection

GraphQL allows clients to ask a server for information about its schema. GraphQL calls this introspection.

We can ask GraphQL for this information by querying the __schema meta-field, which is always available on the root type of a Query per the spec.

1
2
3
4
5
6
7
query {
__schema {
types {
name
}
}
}

Example:

1
2
3
4
5
6
7
8
9
10
11
type Query {
author(id: ID!): Author
}

type Author {
posts: [Post!]!
}

type Post {
title: String!
}

If we were to send the introspection query mentioned above, we would get the following result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
"data": {
"__schema": {
"types": [
{
"name": "Query"
},
{
"name": "Author"
},
{
"name": "Post"
},
{
"name": "ID"
},
{
"name": "String"
},
{
"name": "__Schema"
},
{
"name": "__Type"
},
{
"name": "__TypeKind"
},
{
"name": "__Field"
},
{
"name": "__InputValue"
},
{
"name": "__EnumValue"
},
{
"name": "__Directive"
},
{
"name": "__DirectiveLocation"
}
]
}
}
}

If we query a single type with __type:

1
2
3
4
5
6
{
__type(name: "Author") {
name
description
}
}

We’ll get:

1
2
3
4
5
6
7
8
{
"data": {
"__type": {
"name": "Author",
"description": "The author of a post.",
}
}
}

Playground

GraphQL Playground