What is Introspection in GraphQL?

Image for post
Image for post

What is Introspection in GraphQL

Why is Introspection Useful?

Image for post
Image for post

Provides clients a deep view of the schema

Build Awesome Tools

Self Documentation

Introspection Queries

Query schema’s type

query getSchmemaTypes {
__schema {
types {
name
}
}
}
{
"data": {
"__schema": {
"types": [
{
"name": "AcceptEnterpriseAdministratorInvitationInput"
},
{
"name": "AcceptEnterpriseAdministratorInvitationPayload"
},
{
"name": "AcceptTopicSuggestionInput"
},
{
"name": "AcceptTopicSuggestionPayload"
}
......
]
}
}
}

Query supported queries and mutations

query getSupportedQueries {
__schema {
queryType {
fields{
name
}
}
}
}
{
"data": {
"__schema": {
"queryType": {
"fields": [
{
"name": "codeOfConduct"
},
{
"name": "codesOfConduct"
},
{
"name": "enterprise"
},
{
"name": "enterpriseAdministratorInvitation"
},
{
"name": "enterpriseAdministratorInvitationByToken"
},
{
"name": "license"
},
{
"name": "licenses"
},
{
"name": "marketplaceCategories"
},
{
"name": "marketplaceCategory"
},
{
"name": "marketplaceListing"
},
{
"name": "marketplaceListings"
},
{
"name": "meta"
},
{
"name": "node"
},
{
"name": "nodes"
},
{
"name": "organization"
},
{
"name": "rateLimit"
},
{
"name": "relay"
},
{
"name": "repository"
},
{
"name": "repositoryOwner"
},
.....
}
}
}
}

Query Property Types

query getRepositoryOwnerType {
__type(name:"RepositoryOwner") {
description
fields {
name
}
}
}
{
"data": {
"__type": {
"description": "Represents an owner of a Repository.",
"fields": [
{
"name": "avatarUrl"
},
{
"name": "id"
},
{
"name": "login"
},
{
"name": "repositories"
},
{
"name": "repository"
},
{
"name": "resourcePath"
},
{
"name": "url"
}
]
}
}
}

Query Directives

query getDirectives {
__schema {
directives {
name
description
}
}
}
{
"data": {
"__schema": {
"directives": [
{
"name": "include",
"description": "Directs the executor to include this field or fragment only when the `if` argument is true."
},
{
"name": "skip",
"description": "Directs the executor to skip this field or fragment when the `if` argument is true."
},
{
"name": "deprecated",
"description": "Marks an element of a GraphQL schema as no longer supported."
}
]
}
}
}

Conclusion

Written by

Software Consultant, Author, Speaker, React Native|React|GraphQL Dev & Indian Classical Musician http://adhithiravichandran.com/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store