{"componentChunkName":"component---src-templates-doc-tsx","path":"/learn/introspection/","result":{"data":{"doc":{"frontmatter":{"title":"Introspection","date":null,"permalink":"/learn/introspection/","byline":null,"guestBio":null,"sublinks":null,"layout":"docs"},"id":"2911ba27-f601-585a-a70f-3ad2cb78f9f3","rawMarkdownBody":"\nIt's often useful to ask a GraphQL schema for information about what\nqueries it supports. GraphQL allows us to do so using the introspection\nsystem!\n\nFor our Star Wars example, the file\n[starWarsIntrospection-test.js](https://github.com/graphql/graphql-js/blob/master/src/__tests__/starWarsIntrospection-test.js)\ncontains a number of queries demonstrating the introspection system, and is a\ntest file that can be run to exercise the reference implementation's\nintrospection system.\n\nWe designed the type system, so we know what types are available, but if\nwe didn't, we can ask GraphQL, by querying the `__schema` field, always\navailable on the root type of a Query. Let's do so now, and ask what types\nare available.\n\n```graphql\n# { \"graphiql\": true }\n{\n  __schema {\n    types {\n      name\n    }\n  }\n}\n```\n\nWow, that's a lot of types! What are they? Let's group them:\n\n - **Query, Character, Human, Episode, Droid** - These are the ones that we\ndefined in our type system.\n - **String, Boolean** - These are built-in scalars that the type system\nprovided.\n - **\\_\\_Schema, \\_\\_Type, \\_\\_TypeKind, \\_\\_Field, \\_\\_InputValue,\n\\_\\_EnumValue, \\_\\_Directive** - These all are preceded with a double\nunderscore, indicating that they are part of the introspection system.\n\nNow, let's try and figure out a good place to start exploring what queries are\navailable. When we designed our type system, we specified what type all queries\nwould start at; let's ask the introspection system about that!\n\n```graphql\n# { \"graphiql\": true }\n{\n  __schema {\n    queryType {\n      name\n    }\n  }\n}\n```\n\nAnd that matches what we said in the type system section, that\nthe `Query` type is where we will start! Note that the naming here\nwas just by convention; we could have named our `Query` type anything\nelse, and it still would have been returned here had we specified it\nwas the starting type for queries. Naming it `Query`, though, is a useful\nconvention.\n\nIt is often useful to examine one specific type. Let's take a look at\nthe `Droid` type:\n\n```graphql\n# { \"graphiql\": true }\n{\n  __type(name: \"Droid\") {\n    name\n  }\n}\n```\n\nWhat if we want to know more about Droid, though? For example, is it\nan interface or an object?\n\n```graphql\n# { \"graphiql\": true }\n{\n  __type(name: \"Droid\") {\n    name\n    kind\n  }\n}\n```\n\n`kind` returns a `__TypeKind` enum, one of whose values is `OBJECT`. If\nwe asked about `Character` instead we'd find that it is an interface:\n\n```graphql\n# { \"graphiql\": true }\n{\n  __type(name: \"Character\") {\n    name\n    kind\n  }\n}\n```\n\nIt's useful for an object to know what fields are available, so let's\nask the introspection system about `Droid`:\n\n```graphql\n# { \"graphiql\": true }\n{\n  __type(name: \"Droid\") {\n    name\n    fields {\n      name\n      type {\n        name\n        kind\n      }\n    }\n  }\n}\n\n\n\n\n```\n\nThose are our fields that we defined on `Droid`!\n\n`id` looks a bit weird there, it has no name for the type. That's\nbecause it's a \"wrapper\" type of kind `NON_NULL`. If we queried for\n`ofType` on that field's type, we would find the `ID` type there,\ntelling us that this is a non-null ID.\n\nSimilarly, both `friends` and `appearsIn` have no name, since they are the\n`LIST` wrapper type. We can query for `ofType` on those types, which will\ntell us what these are lists of.\n\n```graphql\n# { \"graphiql\": true }\n{\n  __type(name: \"Droid\") {\n    name\n    fields {\n      name\n      type {\n        name\n        kind\n        ofType {\n          name\n          kind\n        }\n      }\n    }\n  }\n}\n\n\n\n\n\n```\n\nLet's end with a feature of the introspection system particularly useful\nfor tooling; let's ask the system for documentation!\n\n```graphql\n# { \"graphiql\": true }\n{\n  __type(name: \"Droid\") {\n    name\n    description\n  }\n}\n```\n\nSo we can access the documentation about the type system using introspection,\nand create documentation browsers, or rich IDE experiences.\n\nThis has just scratched the surface of the introspection system; we can\nquery for enum values, what interfaces a type implements, and more. We\ncan even introspect on the introspection system itself. The specification goes\ninto more detail about this topic in the \"Introspection\" section, and the [introspection](https://github.com/graphql/graphql-js/blob/master/src/type/introspection.js)\nfile in GraphQL.js contains code implementing a specification-compliant GraphQL\nquery introspection system.\n"},"nextDoc":{"frontmatter":{"title":"GraphQL Best Practices","permalink":"/learn/best-practices/"}}},"pageContext":{"permalink":"/learn/introspection/","nextPermalink":"/learn/best-practices/","sideBarData":[{"name":"Learn","links":[{"fileAbsolutePath":"/opt/build/repo/src/content/learn/Introduction.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Introduction to GraphQL","permalink":"/learn/","next":"/learn/queries/","category":"Learn","sublinks":null,"sidebarTitle":"Introduction","date":null},"id":"7106674b-2f21-5d84-b8c3-c89c7e2b5561"},{"fileAbsolutePath":"/opt/build/repo/src/content/learn/Learn-Queries.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Queries and Mutations","permalink":"/learn/queries/","next":"/learn/schema/","category":"Learn","sublinks":"Fields,Arguments,Aliases,Fragments,Operation Name,Variables,Directives,Mutations,Inline Fragments","sidebarTitle":null,"date":null},"id":"d9731a25-3fbf-5586-ae79-95daca042058"},{"fileAbsolutePath":"/opt/build/repo/src/content/learn/Learn-Schema.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Schemas and Types","permalink":"/learn/schema/","next":"/learn/validation/","category":"Learn","sublinks":"Type System,Type Language,Object Types and Fields,Arguments,The Query and Mutation Types,Scalar Types,Enumeration Types,Lists and Non-Null,Interfaces,Union Types,Input Types","sidebarTitle":null,"date":null},"id":"6a9e1e57-c0ff-542e-a525-c28f658ad0a7"},{"fileAbsolutePath":"/opt/build/repo/src/content/learn/Learn-Validation.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Validation","permalink":"/learn/validation/","next":"/learn/execution/","category":"Learn","sublinks":null,"sidebarTitle":null,"date":null},"id":"f69c6420-bf79-56a6-b7af-09fbe09f7565"},{"fileAbsolutePath":"/opt/build/repo/src/content/learn/Learn-Execution.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Execution","permalink":"/learn/execution/","next":"/learn/introspection/","category":"Learn","sublinks":null,"sidebarTitle":null,"date":null},"id":"4d6ab3f1-c361-55eb-9800-797f90c3d8f6"},{"fileAbsolutePath":"/opt/build/repo/src/content/learn/Learn-Introspection.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Introspection","permalink":"/learn/introspection/","next":"/learn/best-practices/","category":"Learn","sublinks":null,"sidebarTitle":null,"date":null},"id":"2911ba27-f601-585a-a70f-3ad2cb78f9f3"}]},{"name":"Best Practices","links":[{"fileAbsolutePath":"/opt/build/repo/src/content/learn/BestPractice-Introduction.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"GraphQL Best Practices","permalink":"/learn/best-practices/","next":"/learn/thinking-in-graphs/","category":"Best Practices","sublinks":null,"sidebarTitle":"Introduction","date":null},"id":"2f5369f2-a0d4-5f71-972e-6569092db7a4"},{"fileAbsolutePath":"/opt/build/repo/src/content/learn/BestPractice-ThinkingInGraphs.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Thinking in Graphs","permalink":"/learn/thinking-in-graphs/","next":"/learn/serving-over-http/","category":"Best Practices","sublinks":null,"sidebarTitle":null,"date":null},"id":"692af90e-5600-50bd-bdd7-9048bc299512"},{"fileAbsolutePath":"/opt/build/repo/src/content/learn/BestPractice-ServingOverHTTP.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Serving over HTTP","permalink":"/learn/serving-over-http/","next":"/learn/authorization/","category":"Best Practices","sublinks":null,"sidebarTitle":null,"date":null},"id":"fbee8a12-2a83-51c2-b7f3-068438a89b9b"},{"fileAbsolutePath":"/opt/build/repo/src/content/learn/BestPractice-Authorization.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Authorization","permalink":"/learn/authorization/","next":"/learn/pagination/","category":"Best Practices","sublinks":null,"sidebarTitle":null,"date":null},"id":"2439b6ee-f2a2-5bbe-97d2-0f185a0b4aa8"},{"fileAbsolutePath":"/opt/build/repo/src/content/learn/BestPractice-Pagination.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Pagination","permalink":"/learn/pagination/","next":"/learn/global-object-identification/","category":"Best Practices","sublinks":null,"sidebarTitle":null,"date":null},"id":"5602cb49-7976-5673-8868-32155bd8b94e"},{"fileAbsolutePath":"/opt/build/repo/src/content/learn/BestPractice-NodeInterface.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Global Object Identification","permalink":"/learn/global-object-identification/","next":"/learn/caching/","category":"Best Practices","sublinks":null,"sidebarTitle":null,"date":null},"id":"62587b8a-8864-5487-b7db-8aacf4d0e464"},{"fileAbsolutePath":"/opt/build/repo/src/content/learn/BestPractice-Caching.md","parent":{"relativeDirectory":"learn","sourceInstanceName":"content"},"frontmatter":{"title":"Caching","permalink":"/learn/caching/","next":null,"category":"Best Practices","sublinks":null,"sidebarTitle":null,"date":null},"id":"64807002-e363-5637-aafc-4af37aa77f71"}]}],"sourcePath":"src/content/learn/Learn-Introspection.md"}},"staticQueryHashes":["1581580458"]}