
{"id":5167,"date":"2024-12-03T17:59:34","date_gmt":"2024-12-03T22:59:34","guid":{"rendered":"https:\/\/ikriv.com\/blog\/?p=5167"},"modified":"2024-12-03T17:59:34","modified_gmt":"2024-12-03T22:59:34","slug":"how-do-you-retrieve-graphql-schema","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=5167","title":{"rendered":"How do you retrieve GraphQL schema"},"content":{"rendered":"<p>Just recording my amazement here. Suppose you have a GraphQL server. How do you ask it what&#8217;s the query schema?<\/p>\n<p>You would expect something like calling <a href=\"\">https:\/\/myserver\/graphql\/schema<\/a>? Nah, that would be too REST&#8217;y.<\/p>\n<p>So, maybe it&#8217;s sending something like <code>query { __schema }<\/code> to the GraphQL endpoint? Well, sort of, but it&#8217;s <em>much<\/em> more complicated than that. With GraphQL you need to tell it <em>exactly<\/em> what you want. And you want a bunch of things, including query names, field names, and recursive description of the types involved.<\/p>\n<p>Actually, GraphQL can&#8217;t really handle recursive, the best you can do is to ask for types N levels down. The actual schema query is below, it goes 8 levels deep when querying for types. Fascinating, no?<\/p>\n<p>Source: https:\/\/stackoverflow.com\/questions\/37397886\/get-graphql-whole-schema-query<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nquery IntrospectionQuery {\r\n  __schema {\r\n    queryType {\r\n      name\r\n    }\r\n    mutationType {\r\n      name\r\n    }\r\n    subscriptionType {\r\n      name\r\n    }\r\n    types {\r\n      ...FullType\r\n    }\r\n    directives {\r\n      name\r\n      description\r\n      locations\r\n      args {\r\n        ...InputValue\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nfragment FullType on __Type {\r\n  kind\r\n  name\r\n  description\r\n  fields(includeDeprecated: true) {\r\n    name\r\n    description\r\n    args {\r\n      ...InputValue\r\n    }\r\n    type {\r\n      ...TypeRef\r\n    }\r\n    isDeprecated\r\n    deprecationReason\r\n  }\r\n  inputFields {\r\n    ...InputValue\r\n  }\r\n  interfaces {\r\n    ...TypeRef\r\n  }\r\n  enumValues(includeDeprecated: true) {\r\n    name\r\n    description\r\n    isDeprecated\r\n    deprecationReason\r\n  }\r\n  possibleTypes {\r\n    ...TypeRef\r\n  }\r\n}\r\n\r\nfragment InputValue on __InputValue {\r\n  name\r\n  description\r\n  type {\r\n    ...TypeRef\r\n  }\r\n  defaultValue\r\n}\r\n\r\nfragment TypeRef on __Type {\r\n  kind\r\n  name\r\n  ofType {\r\n    kind\r\n    name\r\n    ofType {\r\n      kind\r\n      name\r\n      ofType {\r\n        kind\r\n        name\r\n        ofType {\r\n          kind\r\n          name\r\n          ofType {\r\n            kind\r\n            name\r\n            ofType {\r\n              kind\r\n              name\r\n              ofType {\r\n                kind\r\n                name\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Just recording my amazement here. Suppose you have a GraphQL server. How do you ask it what&#8217;s the query schema? You would expect something like calling https:\/\/myserver\/graphql\/schema? Nah, that would <a href=\"https:\/\/ikriv.com\/blog\/?p=5167\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[4],"tags":[],"class_list":["entry","author-ikriv","post-5167","post","type-post","status-publish","format-standard","category-hack"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5167"}],"version-history":[{"count":5,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5167\/revisions"}],"predecessor-version":[{"id":5172,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5167\/revisions\/5172"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}