Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yehgdotnet/4d346ee5337a7c19082265a4b3977c94 to your computer and use it in GitHub Desktop.
Save yehgdotnet/4d346ee5337a7c19082265a4b3977c94 to your computer and use it in GitHub Desktop.
Append this string after https://examplegqlapi.com/?query= to test for introspection query
query%20IntrospectionQuery%20%7B%0A%20%20%20%20__schema%20%7B%0A%20%20%20%20%20%20queryType%20%7B%20name%20%7D%0A%20%20%20%20%20%20mutationType%20%7B%20name%20%7D%0A%20%20%20%20%20%20types%20%7B%0A%20%20%20%20%20%20%20%20...FullType%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20directives%20%7B%0A%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20description%0A%20%20%20%20%20%20%20%20locations%0A%20%20%20%20%20%20%20%20args%20%7B%0A%20%20%20%20%20%20%20%20%20%20...InputValue%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20fragment%20FullType%20on%20__Type%20%7B%0A%20%20%20%20kind%0A%20%20%20%20name%0A%20%20%20%20description%0A%20%20%20%20fields%28includeDeprecated%3A%20true%29%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20description%0A%20%20%20%20%20%20args%20%7B%0A%20%20%20%20%20%20%20%20...InputValue%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20type%20%7B%0A%20%20%20%20%20%20%20%20...TypeRef%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20isDeprecated%0A%20%20%20%20%20%20deprecationReason%0A%20%20%20%20%7D%0A%20%20%20%20inputFields%20%7B%0A%20%20%20%20%20%20...InputValue%0A%20%20%20%20%7D%0A%20%20%20%20interfaces%20%7B%0A%20%20%20%20%20%20...TypeRef%0A%20%20%20%20%7D%0A%20%20%20%20enumValues%28includeDeprecated%3A%20true%29%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20description%0A%20%20%20%20%20%20isDeprecated%0A%20%20%20%20%20%20deprecationReason%0A%20%20%20%20%7D%0A%20%20%20%20possibleTypes%20%7B%0A%20%20%20%20%20%20...TypeRef%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20fragment%20InputValue%20on%20__InputValue%20%7B%0A%20%20%20%20name%0A%20%20%20%20description%0A%20%20%20%20type%20%7B%20...TypeRef%20%7D%0A%20%20%20%20defaultValue%0A%20%20%7D%0A%20%20fragment%20TypeRef%20on%20__Type%20%7B%0A%20%20%20%20kind%0A%20%20%20%20name%0A%20%20%20%20ofType%20%7B%0A%20%20%20%20%20%20kind%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20ofType%20%7B%0A%20%20%20%20%20%20%20%20kind%0A%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20ofType%20%7B%0A%20%20%20%20%20%20%20%20%20%20kind%0A%20%20%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20%20%20ofType%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20kind%0A%20%20%20%20%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20%20%20%20%20ofType%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20kind%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20ofType%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20kind%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ofType%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20kind%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D
@yehgdotnet
Copy link
Author

https://alligator.io/graphql/introspection-queries/

__type

First let’s run a query to enquire about the Film type using the
built-in __type:

query FilmType {
  __type(name: "Film") {
    kind
    name
    fields {
      name
      description
      type {
        name
      }
    }
  }
}
  • Kind gives us the enum value for the type, like OBJECT, SCALAR
    or INTERFACE.
  • Name gives us the name of the type.
  • Description, well, gives us the description!

And here’s what the response looks like:

{
  "data": {
    "__type": {
      "kind": "OBJECT",
      "name": "Film",
      "fields": [
        {
          "name": "title",
          "description": "The title of this film.",
          "type": {
            "name": "String"
          }
        },
        {
          "name": "episodeID",
          "description": "The episode number of this film.",
          "type": {
            "name": "Int"
          }
        },
        ...

Notice the use of the built-in __type (of type __Type) here to get
information on the type of a particular object or interface.


Here’s another example using a fragment to learn even more about a
particular type:

query LearnAboutFilm {
  __type(name: "Film") {
    ...AboutType
  }
}

fragment AboutType on __Type {
  fields {
    name
    description
    args {
      name
      description
    }
  }
  interfaces {
    name
    description
  }
  inputFields {
    name
    description
  }
  possibleTypes {
    kind
    name
    fields {
      name
      description
      type {
        kind
        name
        description
      }
    }
  }
}

__schema

With __schema we can ask the server about the schema itself. Let’s
look at an example:

query LearnAboutSchema {
  __schema {
    types {
      name
      kind
    }
    queryType {
      fields {
        name
        description
      }
    }
  }
}

And the response:

{
  "data": {
    "__schema": {
      "types": [
        {
          "name": "Root",
          "kind": "OBJECT"
        },
        {
          "name": "String",
          "kind": "SCALAR"
        },
        {
          "name"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment