Из спецификации:
Сервер GraphQL поддерживает самоанализ по своей схеме.Эта схема запрашивается с использованием самого GraphQL, создавая мощную платформу для создания инструментов ... Система самоанализа схемы доступна из мета-полей __schema и __type, которые доступны из типа корня операции запроса.
Такие инструменты, как GraphQL Playground и GraphiQL, используют самоанализ для получения информации о схеме.Вам не нужны никакие дополнительные инструменты или библиотеки для выполнения запроса самоанализа - поскольку это всего лишь запрос GraphQL, вы сделаете запрос так же, как и любой другой запрос к конечной точке (например, с использованием requests
).
Вот полный самоанализ запроса от graphql-core
:
introspection_query = """
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
"""