CINXE.COM
GraphQL
<!DOCTYPE html> <!-- Built with spec-md https://spec-md.com --> <html> <head><meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"><title>GraphQL</title> <style>/** * prism.js default theme for JavaScript, CSS and HTML * Based on dabblet (http://dabblet.com) * @author Lea Verou */ code[class*="language-"], pre[class*="language-"] { color: black; background: none; text-shadow: 0 1px white; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; font-size: 1em; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; -moz-tab-size: 4; -o-tab-size: 4; tab-size: 4; -webkit-hyphens: none; -moz-hyphens: none; -ms-hyphens: none; hyphens: none; } pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection, code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection { text-shadow: none; background: #b3d4fc; } pre[class*="language-"]::selection, pre[class*="language-"] ::selection, code[class*="language-"]::selection, code[class*="language-"] ::selection { text-shadow: none; background: #b3d4fc; } @media print { code[class*="language-"], pre[class*="language-"] { text-shadow: none; } } /* Code blocks */ pre[class*="language-"] { padding: 1em; margin: .5em 0; overflow: auto; } :not(pre) > code[class*="language-"], pre[class*="language-"] { background: #f5f2f0; } /* Inline code */ :not(pre) > code[class*="language-"] { padding: .1em; border-radius: .3em; white-space: normal; } .token.comment, .token.prolog, .token.doctype, .token.cdata { color: slategray; } .token.punctuation { color: #999; } .token.namespace { opacity: .7; } .token.property, .token.tag, .token.boolean, .token.number, .token.constant, .token.symbol, .token.deleted { color: #905; } .token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted { color: #690; } .token.operator, .token.entity, .token.url, .language-css .token.string, .style .token.string { color: #9a6e3a; /* This background color was intended by the author of this theme. */ background: hsla(0, 0%, 100%, .5); } .token.atrule, .token.attr-value, .token.keyword { color: #07a; } .token.function, .token.class-name { color: #DD4A68; } .token.regex, .token.important, .token.variable { color: #e90; } .token.important, .token.bold { font-weight: bold; } .token.italic { font-style: italic; } .token.entity { cursor: help; }</style> <style>:root{color:#333;font-family:Cambria,"Palatino Linotype",Palatino,"Liberation Serif",serif;font-size:15px;line-height:1.5;--mono-font-size: 13px;--indent: 1rem;--list-indent: 1.5rem;--dfn-indent: 0rem}@media (min-width: 720px){:root{font-size:17px;--mono-font-size: 15px;--indent: 2rem;--list-indent: 2rem;--dfn-indent: 2rem}}body{margin:3rem 0 3rem}article{margin:0 1rem}@media (min-width: 720px){body{margin:6rem auto 3rem;max-width:800px;padding-left:75px;padding-right:clamp(0px,calc((100vw - 800px) * .25),75px)}}.source-link{display:none}@media screen and (min-width: 720px){.source-link{display:block;position:absolute;width:18px;fill:#ccc;opacity:.3}.source-link:hover{opacity:1}}.outdated-selection-link,.selection-link{position:absolute;display:block;color:#fff;--selection-background-color: #cacee0;background:var(--selection-background-color);border-radius:4px;font-size:36px;height:23px;line-height:48px;text-align:center;text-decoration:none;width:25px;user-select:none;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none}.outdated-selection-link:hover,.selection-link:hover{text-decoration:none}.outdated-selection-link:before,.selection-link:before{border:5px solid transparent;content:"";height:0;margin-top:-5px;margin-right:-5px;position:absolute;right:1px;top:50%;width:0}@media (max-width: 719px){.outdated-selection-link:before,.selection-link:before{border-bottom-color:var(--selection-background-color);border-top:0;right:50%;top:1px}}@media (min-width: 720px){.outdated-selection-link:before,.selection-link:before{border-left-color:var(--selection-background-color);border-right:0;right:1px;top:50%}}.selection-link:hover{--selection-background-color: #3b5998}.outdated-selection-link{--selection-background-color: #f0babe;font-size:21px;font-weight:800;line-height:27px}.outdated-selection-link:hover:after{content:"This selection content has changed since this link was created.";font:9pt/11pt Cambria,"Palatino Linotype",Palatino,"Liberation Serif",serif;position:absolute;display:block;white-space:nowrap;padding:2px 5px 1px;top:-20px;background:black;color:#fff}a{color:#3b5998;text-decoration:none}a:hover{text-decoration:underline}img{max-width:100%}dl{margin:1rem 0 1rem var(--dfn-indent)}dd{margin:.25em 0 .5em var(--indent)}dd+dd{margin-top:1rem}dfn,.spec-ref{font-style:italic}dfn>a,.spec-ref>a{color:inherit}h1,h2,h3,h4,h5,h6{font-weight:bold;margin:3em 0 1em;position:relative}@media (min-width: 720px){header>h1{margin:6em 0 3em}}h1{font-size:1.5em;margin-top:5em}h2,h3{font-size:1.25em}h4,h5,h6{font-size:1em}section{padding-top:1rem;margin-top:-1rem}section.subsec>h6{margin-top:2em}section.subsec>h6>a{color:#333}section .spec-secid{margin-right:1ex}@media (min-width: 720px){section .spec-secid{position:absolute;right:100%;text-align:right;white-space:nowrap}}footer{font-size:75%;opacity:.5;text-align:center;margin-top:12rem}.spec-toc{margin:1rem 0 3rem}.spec-toc .title{content:"Contents";display:block;font-weight:bold;margin:5em 0 1em}.spec-toc .spec-secid{margin-right:1ex}.spec-toc ol{list-style:none;padding-left:0;margin-top:0;margin-bottom:0}.spec-toc ol ol{list-style:none;padding-left:2ex;margin-bottom:.25em}.spec-toc li{position:relative;padding:5px 0 0 30px;margin:-5px 0 0 -30px}.spec-toc a{color:#333}.spec-toc a:hover{text-decoration:none}.spec-toc a .spec-secid{color:#3b5998}.spec-toc a:hover .spec-secid{text-decoration:underline}.spec-toc .toggle{display:none}.spec-toc .toggle+label{cursor:pointer;left:6px;opacity:1;padding:5px 6px 5px 7px;position:absolute;top:6px;transform:rotate(0deg);transition:all .18s ease-in-out}.spec-toc .toggle+label:after{border-color:transparent transparent transparent #bbc;border-style:solid;border-width:6px 0 6px 7px;content:" ";display:block;height:0;width:0}@media (pointer: fine){.spec-toc .toggle+label{left:10px;padding:3px 5px 3px 6px;top:8px}}.spec-toc .toggle:checked+label{transform:rotate(90deg)}@media (hover: hover){.spec-toc li:not(:hover)>.toggle:checked+label{opacity:0}}.spec-toc .toggle:not(:checked)~ol{max-height:0;overflow:hidden;margin:0}.spec-sidebar-toggle{display:none}.spec-sidebar-toggle+label>.spec-sidebar-button{position:fixed;right:0;top:0;padding:10px 15px;font-size:30px;color:#000000b3;z-index:2;cursor:pointer;user-select:none;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none}.spec-sidebar-toggle:checked+label:after{content:"";position:fixed;top:0;left:0;width:100vw;height:100vh;z-index:0}.spec-sidebar{display:none;position:fixed;right:0;top:0;width:min(320px,calc(100vw - 48px));font-size:14px;line-height:1.75;overflow-y:scroll;height:100%;padding:0 0 5rem 30px;box-sizing:border-box;background:#f0f0f0;box-shadow:inset 1px 0 rgba(0,0,0,.05),-4px 0 8px -2px rgba(0,0,0,.04);overscroll-behavior:contain}.spec-sidebar{user-select:none;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none}.spec-sidebar-toggle:checked~.spec-sidebar{display:block}.spec-sidebar .viewing>a:after{color:#8b9;content:"\2022";margin-left:1ex}@media (min-width: 1220px){.spec-sidebar-toggle+label{display:none}.spec-sidebar{display:block;box-shadow:inset 1px 0 rgba(0,0,0,.05),inset 4px 0 8px -2px rgba(0,0,0,.08)!important}body{padding-right:345px}}.spec-note{background:#FEFEF3;border-left:solid 4px #F4E925;margin:1rem -1rem;min-width:70vw;padding:8px 1rem 12px calc(1rem - 4px);width:-moz-fit-content;width:-webkit-fit-content;width:fit-content}@media (min-width: 720px){.spec-note{min-width:416px}}.spec-note>a:first-child{color:#6c6613;display:block;font:italic 11pt/18pt Cambria,"Palatino Linotype",Palatino,"Liberation Serif",serif;opacity:.6;user-select:none}.spec-todo{color:#666;margin:1em 0 1em 5em;min-height:1em}.spec-todo::before{content:"todo";display:block;float:left;margin-left:-5em;text-transform:uppercase}.spec-index ol{list-style-type:none;margin:0 0 0 var(--indent);padding:0;column-width:210px;column-gap:var(--indent)}.spec-index ol li{width:min-content;white-space:nowrap}pre,code{font-family:Consolas,Monaco,"Andale Mono","Ubuntu Mono",monospace;font-size:var(--mono-font-size);font-weight:inherit}code{background:rgba(0,0,0,.03);margin:-2px -1px;padding:3px 3px;white-space:pre-wrap}pre>code{background:none;font-weight:inherit;margin:0;padding:0;white-space:pre}pre{background:#FAFAFA;border-left:solid 4px #E9E9E9;margin:1rem -1rem;min-width:70vw;padding:12px 1rem 12px calc(1rem - 4px);width:-moz-fit-content;width:-webkit-fit-content;width:fit-content;max-width:calc(100vw - 2rem);overflow-y:scroll}@media (min-width: 720px){pre{min-width:40ch}}.spec-example{background:#FAFAFF;border-left:solid 4px #BBBBFF;padding-top:8px}.spec-counter-example{background:#FFFAFA;border-left:solid 4px #FFBBBB;padding-top:8px}.spec-example>a,.spec-counter-example>a{display:block;font:italic 11pt/18pt Cambria,"Palatino Linotype",Palatino,"Liberation Serif",serif;opacity:.6;user-select:none}.spec-counter-example>a{color:#98593b}table{border-collapse:collapse}th{background-color:#f9f9f9}td,th{border:1px solid #D0D0D0;padding:.4em;vertical-align:baseline}ol,ul{padding-left:var(--list-indent)}li>ol,li>ul{margin-top:.25em;margin-bottom:.5em}li+li{margin-top:.25em}li.task{list-style-type:none;position:relative}li.task>input:first-child{margin-left:0;position:absolute;transform:translateX(calc(-100% - 1ch))}ins{background-color:#00c81e14;text-decoration:none}del{background-color:#c8000014}.spec-added,.spec-removed{border-left:4px solid;margin-left:-18px;padding-left:14px}.spec-added{border-color:#396}.spec-removed{border-color:#933;text-decoration:line-through}.spec-keyword{font-weight:bold}.spec-string{font-family:Consolas,Monaco,monospace;font-size:85%;white-space:pre}var{font-style:italic}*[data-name]{transition:.15s background ease-out;border-radius:2px;padding:0 3px;margin:0 -3px}.spec-semantic,.spec-algo{margin:1rem 0 1rem var(--dfn-indent)}.spec-semantic>.spec-nt::after,.spec-algo>.spec-call:first-child::after{content:":";font-style:normal;font-weight:bold;margin-left:1ex}.spec-semantic ol,.spec-semantic ol ol ol ol,.spec-algo ol,.spec-algo ol ol ol ol{list-style-type:decimal}.spec-semantic ol ol,.spec-semantic ol ol ol ol ol,.spec-algo ol ol,.spec-algo ol ol ol ol ol{list-style-type:lower-alpha}.spec-semantic ol ol ol,.spec-semantic ol ol ol ol ol ol,.spec-algo ol ol ol,.spec-algo ol ol ol ol ol ol{list-style-type:lower-roman}.spec-call>a{color:inherit}.spec-production{margin:1rem 0 1rem var(--dfn-indent)}.spec-production>.spec-nt::after{content:":";font-style:normal;font-weight:bold;margin:0 1ex}.spec-semantic.d2>.spec-nt::after,.spec-production.d2>.spec-nt::after{content:"::"}.spec-semantic.d3>.spec-nt::after,.spec-production.d3>.spec-nt::after{content:":::"}.spec-production>.spec-rhs{line-height:1.1;margin:.25em 0 .5em calc(2 * var(--indent));text-indent:calc(-1 * var(--indent))}.spec-semantic>.spec-rhs{display:inline-block;text-indent:calc(-1 * var(--indent));margin-left:calc(1ex + var(--indent))}.spec-rhs>*{text-indent:0}.spec-oneof{display:inline}.spec-oneof::before{content:"one of";font-style:normal;font-weight:bold}.spec-oneof-grid{max-width:calc(100vw - 2rem);overflow:scroll;margin:-1ex -1rem;padding:1ex 1rem}.spec-oneof-grid>table{margin-left:var(--indent)}.spec-oneof .spec-rhs{border:none;margin:0;padding:0 0 0 1rem;vertical-align:baseline;white-space:pre}.spec-oneof .spec-rhs:first-child{padding:0}.spec-rhs .spec-constrained:not(:first-child),.spec-rhs .spec-quantified:not(:first-child),.spec-rhs .spec-nt:not(:first-child),.spec-rhs .spec-t:not(:first-child),.spec-rhs .spec-rx:not(:first-child),.spec-rhs .spec-prose:not(:first-child),.spec-rhs .spec-empty:not(:first-child),.spec-rhs .spec-lookahead:not(:first-child){margin-left:1ex;display:inline-block}.spec-condition{font-size:85%}.spec-condition::before{content:"[if "}.spec-condition.not::before{content:"[if not "}.spec-condition::after{content:"]"}.spec-empty,.spec-prose{color:#666}.spec-nt{font-style:italic}.spec-nt>a{color:inherit}.spec-quantifiers,.spec-params{font-size:65%;font-style:normal;vertical-align:sub}.spec-quantifier.list{color:#3348d3}.spec-quantifier.optional{color:#83238e}.spec-params,.spec-condition{color:#1c7758}.spec-params::before{content:"["}.spec-params::after{content:"]"}.spec-quantifier:not(:last-child)::after,.spec-param:not(:last-child)::after{color:#666;content:", "}.spec-param.conditional::before{content:"?"}.spec-param.negated::before{content:"!"}.spec-t,.spec-rx{color:#333;font-family:monospace;font-weight:bold}.spec-butnot::before{color:#666;content:"but not";font-family:Cambria,"Palatino Linotype",Palatino,"Liberation Serif",serif;font-weight:normal;margin-right:1ex}.spec-butnot>*:not(:first-child)::before{color:#666;content:"or";font-family:Cambria,"Palatino Linotype",Palatino,"Liberation Serif",serif;font-weight:normal;margin-right:1ex}.spec-rhs .spec-oneof::before,.spec-rhs .spec-butnot::before{margin-left:1ex}.spec-lookahead>*{margin:0!important}.spec-lookahead>*:not(:first-child)::before{color:#666;content:", ";font-family:Cambria,"Palatino Linotype",Palatino,"Liberation Serif",serif;font-style:normal;font-weight:normal}.spec-lookahead::before{color:#666;content:"[lookahead = ";font-family:Cambria,"Palatino Linotype",Palatino,"Liberation Serif",serif;font-style:normal;font-weight:normal}.spec-lookahead.not::before{content:"[lookahead \2260 "}.spec-lookahead.set::before{content:"[lookahead \2208 {";margin-right:0}.spec-lookahead.set.not::before{content:"[lookahead \2209 {"}.spec-lookahead.ntset::before{content:"[lookahead \2208 ";margin-right:0}.spec-lookahead.ntset.not::before{content:"[lookahead \2209 "}.spec-lookahead::after{color:#666;content:"]"}.spec-lookahead.set::after{content:"}]"}.token.atrule,.token.attr-value,.token.keyword,.token.property,.token.selector,.token.attr-name,.token.builtin,.token.entity,.token.url,.token.inserted{color:#1b1994b0;background:none}.token.tag,.token.boolean,.token.number,.token.string,.token.char,.token.constant,.token.symbol,.token.regex,.token.important,.token.variable,.token.function,.token.class-name,.token.deleted{color:#a20764bd}.token.comment,.token.prolog,.token.doctype,.token.cdata,.token.description{color:inherit;opacity:.3}.token.punctuation{color:inherit;opacity:.5}.token.operator,.token.namespace{color:inherit;opacity:.7}</style> <script>(function(){var r,a=[];document.addEventListener("readystatechange",function(){document.readyState==="interactive"&&u()});function u(){var n=document.querySelector('label[for="spec-sidebar-toggle"]');n.addEventListener("scroll",o),n.addEventListener("touchmove",o);function o(d){d.preventDefault()}for(var t=document.getElementsByTagName("section"),e=0;e<t.length;e++)t[e].getAttribute("secid")&&a.push(t[e]);var i=window.scrollY,c=!1;window.addEventListener("scroll",function(d){i=window.scrollY,c||(c=!0,window.requestAnimationFrame(function(){s(i),c=!1}))})}function s(n){for(var o=n+document.documentElement.clientHeight/4,t,e=a.length-1;e>=0;e--)if(a[e].offsetTop<o){t=a[e];break}var i=t&&t.getAttribute("secid");i!==r&&(r&&l(r,!1),i&&l(i,!0),r=i)}function l(n,o){document.getElementById("_sidebar_"+n).className=o?"viewing":"";for(var t=n.split(".");t.length;){var e=document.getElementById("_toggle_"+t.join("."));e&&(e.checked=o),t.pop()}}s(window.scrollY);})();</script> <script>(function(){var n=document.getElementsByTagName("style")[0].sheet,e;function u(){e&&(n.deleteRule(e),e=void 0)}function d(t){u(),e=n.insertRule('*[data-name="'+t+'"] { background: rgba(230,215,0,0.12); }',n.cssRules.length)}document.documentElement.addEventListener("mouseover",function(t){var a=t.target.attributes["data-name"];a&&d(a.value)});document.documentElement.addEventListener("mouseout",u);})();</script> <script>(function(){var R="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",o,p,r,g;document.addEventListener("selectionchange",E);window.addEventListener("resize",C);window.addEventListener("hashchange",x);window.addEventListener("load",x);function S(n){y(new URL(n.target.href))}function x(){y(window.location)}function y(n){var e=n.hash.match(/^#sel-([A-Za-z0-9-_]+)$/);if(!!e){g=e[1],r=k(g);var t=r.getBoundingClientRect(),d=Math.max(20,Math.floor((window.innerHeight-t.height)*.4));window.scrollTo(0,window.scrollY+t.y-d);var c=document.getSelection();c.empty(),c.addRange(r),C()}}function E(n){var e=document.getSelection();if(e.isCollapsed)o&&(o.parentNode.removeChild(o),o=null);else{var t=e.getRangeAt(0);(!r||t.compareBoundaryPoints(Range.START_TO_START,r)!==0||t.compareBoundaryPoints(Range.END_TO_END,r)!==0)&&(r=t,g=B(r),C())}}function C(){if(!!r){p||(p=document.getElementsByTagName("article")[0]),o||(o=document.createElement("a"),document.body.appendChild(o)),o.href="#sel-"+g,o.onclick=S,o.className=r.isOutdated?"outdated-selection-link":"selection-link",o.innerText=r.isOutdated?"!":"\u201F";var n=window.innerWidth<720,e=r.getBoundingClientRect();if(n)o.style.left=Math.floor(e.x+e.width/2+window.scrollX-13)+"px",o.style.top=Math.floor(e.bottom+window.scrollY+10)+"px";else{var t=p.getBoundingClientRect().x;o.style.left=Math.floor(t+window.scrollX-37)+"px",o.style.top=Math.floor(e.y+window.scrollY-3)+"px"}}}function B(n){var e="",t=N(n.startContainer),d=N(n.endContainer),c=M(t,d);return l(c),l(t.slice(c.length).concat(n.startOffset)),l(d.slice(c.length).concat(n.endOffset)),i(L(n.toString())),e;function i(a){do e+=R[a&31|(a>31?32:0)],a>>=5;while(a>0)}function l(a){i(a.length);for(var h=0;h<a.length;h++)i(a[h])}}function k(n){for(var e=new Array(64),t=0;t<64;t++)e[R.charCodeAt(t)]=t;var d=0,c=m(),i=m(),l=m(),a=w(),h=i.pop(),P=O(c.concat(i)),T=l.pop(),A=O(c.concat(l)),u=document.createRange();return u.setStart(P,h),u.setEnd(A,T),u.isOutdated=a!==void 0&&a!==L(u.toString()),u;function w(){for(var s=0,v=0;d<n.length;){var f=e[n.charCodeAt(d++)];if(s|=(f&31)<<v,v+=5,f<32)return s}}function m(){var s=w();if(s!=null){for(var v=new Array(s),f=0;f<s;f++)v[f]=w();return v}}}function N(n){for(var e=[];n!=document.body;){var t=n.parentNode;e.push(Array.prototype.indexOf.call(t.childNodes,n)),n=t}return e.reverse()}function O(n){for(var e=document.body,t=0;t<n.length&&e;t++)e=e.childNodes[n[t]];return e}function M(n,e){for(var t=0;t<n.length&&t<e.length&&n[t]===e[t];)t++;return n.slice(0,t)}function L(n){for(var e=2166136261,t=0;t<n.length;++t)e^=n.charCodeAt(t),e+=(e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24);return(e>>15^e)&32767}})();</script> <script>(function(){var a,i,t;document.addEventListener("pointerover",c);document.addEventListener("pointerleave",u);window.addEventListener("resize",d);var s={OL:1,UL:1};function c(r){var e=r.target;if(e.nodeType===Node.ELEMENT_NODE){for(;e&&!e.getAttribute("data-source");){if(s[e.nodeName])return;e=e.parentElement}e&&e!==a&&(a=e,d())}}function d(){if(!!a){i||(i=document.getElementsByTagName("article")[0]),t||(t=document.createElement("a"),t.className="source-link",t.target="_blank",t.innerHTML='<svg viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>',document.body.appendChild(t)),t.href=i.getAttribute("data-source-base")+a.getAttribute("data-source");var r=v(a),e=document.createRange();r.nodeType===Node.TEXT_NODE?e.setStart(r,0):e.selectNode(r);var n=e.getBoundingClientRect();e.detach();var o=n.y+n.height/2-9,l=i.getBoundingClientRect().x-95;t.style.left=Math.floor(window.scrollX+l)+"px",t.style.top=Math.floor(window.scrollY+o)+"px"}}function v(r){e:for(;r;){for(var e=r.childNodes,n=0;e&&n<e.length;n++){var o=e[n];if(o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE&&!/^\s*$/.test(o.data)){r=o;continue e}}return r}}function u(){t&&(t.parentNode.removeChild(t),t=null)}})();</script> </head> <body><article data-source-base="https://github.com/graphql/graphql-spec/blame/October2021/"> <header> <h1>GraphQL</h1> <section id="intro"> <p data-source="spec/GraphQL.md#L3"><em>October 2021 Edition</em></p> <section id="sec-Introduction" class="subsec"> <h6 data-source="spec/GraphQL.md#L5"><a href="#sec-Introduction" title="link to this subsection">Introduction</a></h6> <p data-source="spec/GraphQL.md#L7-L15">This is the specification for GraphQL, a query language and execution engine originally created at Facebook in 2012 for describing the capabilities and requirements of data models for client-server applications. The development of this open standard started in 2015. This specification was licensed under OWFa 1.0 in 2017. The <a href="https://graphql.org/foundation/">GraphQL Foundation</a> was formed in 2019 as a neutral focal point for organizations who support the GraphQL ecosystem, and the <a href="https://graphql.org/community/">GraphQL Specification Project</a> was established also in 2019 as the Joint Development Foundation Projects, LLC, GraphQL Series.</p> <p data-source="spec/GraphQL.md#L17-L20">If your organization benefits from GraphQL, please consider <a href="https://graphql.org/foundation/join/#graphql-foundation">becoming a member</a> and helping us to sustain the activities that support the health of our neutral ecosystem.</p> <p data-source="spec/GraphQL.md#L22-L27">The GraphQL Specification Project has evolved and may continue to evolve in future editions of this specification. Previous editions of the GraphQL specification can be found at permalinks that match their <a href="https://github.com/graphql/graphql-spec/releases">release tag</a>. The latest working draft release can be found at <a href="https://spec.graphql.org/draft">https://spec.graphql.org/draft</a>.</p> </section> <section id="sec-Copyright-notice" class="subsec"> <h6 data-source="spec/GraphQL.md#L30"><a href="#sec-Copyright-notice" title="link to this subsection">Copyright notice</a></h6> <p data-source="spec/GraphQL.md#L32">Copyright © 2015-2018, Facebook, Inc.</p> <p data-source="spec/GraphQL.md#L34">Copyright © 2019-present, GraphQL contributors</p> <p data-source="spec/GraphQL.md#L36-L46">THESE MATERIALS ARE PROVIDED “AS IS.” The parties expressly disclaim any warranties (express, implied, or otherwise), including implied warranties of merchantability, non-infringement, fitness for a particular purpose, or title, related to the materials. The entire risk as to implementing or otherwise using the materials is assumed by the implementer and user. IN NO EVENT WILL THE PARTIES BE LIABLE TO ANY OTHER PARTY FOR LOST PROFITS OR ANY FORM OF INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER FROM ANY CAUSES OF ACTION OF ANY KIND WITH RESPECT TO THIS DELIVERABLE OR ITS GOVERNING AGREEMENT, WHETHER BASED ON BREACH OF CONTRACT, TORT (INCLUDING NEGLIGENCE), OR OTHERWISE, AND WHETHER OR NOT THE OTHER MEMBER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p> </section> <section id="sec-Licensing" class="subsec"> <h6 data-source="spec/GraphQL.md#L49"><a href="#sec-Licensing" title="link to this subsection">Licensing</a></h6> <p data-source="spec/GraphQL.md#L51-L56">The GraphQL Specification Project is made available by the <a href="https://www.jointdevelopment.org/">Joint Development Foundation</a>. The current <a href="https://github.com/graphql/graphql-wg">Working Group</a> charter, which includes the IP policy governing all working group deliverables (including specifications, source code, and datasets) may be found at <a href="https://technical-charter.graphql.org">https://technical-charter.graphql.org</a>.</p> <p data-source="spec/GraphQL.md#L58">Currently, the licenses governing GraphQL Specification Project deliverables are:</p> <table> <thead> <tr data-source="spec/GraphQL.md#L60"> <th>Deliverable</th> <th>License</th> </tr> </thead> <tbody> <tr data-source="spec/GraphQL.md#L62"> <td>Specifications</td> <td><a href="http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0">Open Web Foundation Agreement 1.0 Mode</a> (Patent and Copyright)</td> </tr> <tr data-source="spec/GraphQL.md#L63"> <td>Source code</td> <td><a href="https://opensource.org/licenses/MIT">MIT License</a></td> </tr> <tr data-source="spec/GraphQL.md#L64"> <td>Data sets</td> <td><a href="https://creativecommons.org/publicdomain/zero/1.0/">CC0 1.0</a></td> </tr> </tbody> </table> </section> <section id="sec-Conformance" class="subsec"> <h6 data-source="spec/GraphQL.md#L67"><a href="#sec-Conformance" title="link to this subsection">Conformance</a></h6> <p data-source="spec/GraphQL.md#L69-L71">A conforming implementation of GraphQL must fulfill all normative requirements. Conformance requirements are described in this document via both descriptive assertions and key words with clearly defined meanings.</p> <p data-source="spec/GraphQL.md#L73-L77">The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative portions of this document are to be interpreted as described in <a href="https://tools.ietf.org/html/rfc2119">IETF RFC 2119</a>. These key words may appear in lowercase and still retain their meaning unless explicitly declared as non-normative.</p> <p data-source="spec/GraphQL.md#L79-L81">A conforming implementation of GraphQL may provide additional functionality, but must not where explicitly disallowed or would otherwise result in non-conformance.</p> </section> <section id="sec-Conforming-Algorithms" class="subsec"> <h6 data-source="spec/GraphQL.md#L84"><a href="#sec-Conforming-Algorithms" title="link to this subsection">Conforming Algorithms</a></h6> <p data-source="spec/GraphQL.md#L86-L91">Algorithm steps phrased in imperative grammar (e.g. “Return the result of calling resolver”) are to be interpreted with the same level of requirement as the algorithm it is contained within. Any algorithm referenced within an algorithm step (e.g. “Let completedResult be the result of calling CompleteValue()”) is to be interpreted as having at least the same level of requirement as the algorithm containing that step.</p> <p data-source="spec/GraphQL.md#L93-L97">Conformance requirements expressed as algorithms can be fulfilled by an implementation of this specification in any way as long as the perceived result is equivalent. Algorithms described in this document are written to be easy to understand. Implementers are encouraged to include equivalent but optimized implementations.</p> <p data-source="spec/GraphQL.md#L99-L101">See <a href="#sec-Appendix-Notation-Conventions">Appendix A</a> for more details about the definition of algorithms and other notational conventions used in this document.</p> </section> <section id="sec-Non-Normative-Portions" class="subsec"> <h6 data-source="spec/GraphQL.md#L104"><a href="#sec-Non-Normative-Portions" title="link to this subsection">Non-Normative Portions</a></h6> <p data-source="spec/GraphQL.md#L106-L107">All contents of this document are normative except portions explicitly declared as non-normative.</p> <p data-source="spec/GraphQL.md#L109-L113">Examples in this document are non-normative, and are presented to aid understanding of introduced concepts and the behavior of normative portions of the specification. Examples are either introduced explicitly in prose (e.g. “for example”) or are set apart in example or counter-example blocks, like this:</p> <pre id="example-fed99" class="spec-example" data-source="spec/GraphQL.md#L115-L117"><a href="#example-fed99">Example № 1</a><code>This is an example of a non-normative example. </code></pre> <pre id="example-881bd" class="spec-counter-example" data-source="spec/GraphQL.md#L119-L121"><a href="#example-881bd">Counter Example № 2</a><code>This is an example of a non-normative counter-example. </code></pre> <p data-source="spec/GraphQL.md#L123-L126">Notes in this document are non-normative, and are presented to clarify intent, draw attention to potential edge-cases and pit-falls, and answer common questions that arise during implementation. Notes are either introduced explicitly in prose (e.g. “Note: “) or are set apart in a note block, like this:</p> <div id="note-c0129" class="spec-note" data-source="spec/GraphQL.md#L128"> <a href="#note-c0129">Note</a> This is an example of a non-normative note.</div> </section> </section> <nav class="spec-toc"> <div class="title">Contents</div> <ol> <li><a href="#sec-Overview"><span class="spec-secid">1</span>Overview</a></li> <li><a href="#sec-Language"><span class="spec-secid">2</span>Language</a><ol> <li><a href="#sec-Language.Source-Text"><span class="spec-secid">2.1</span>Source Text</a><ol> <li><a href="#sec-Unicode"><span class="spec-secid">2.1.1</span>Unicode</a></li> <li><a href="#sec-White-Space"><span class="spec-secid">2.1.2</span>White Space</a></li> <li><a href="#sec-Line-Terminators"><span class="spec-secid">2.1.3</span>Line Terminators</a></li> <li><a href="#sec-Comments"><span class="spec-secid">2.1.4</span>Comments</a></li> <li><a href="#sec-Insignificant-Commas"><span class="spec-secid">2.1.5</span>Insignificant Commas</a></li> <li><a href="#sec-Language.Source-Text.Lexical-Tokens"><span class="spec-secid">2.1.6</span>Lexical Tokens</a></li> <li><a href="#sec-Language.Source-Text.Ignored-Tokens"><span class="spec-secid">2.1.7</span>Ignored Tokens</a></li> <li><a href="#sec-Punctuators"><span class="spec-secid">2.1.8</span>Punctuators</a></li> <li><a href="#sec-Names"><span class="spec-secid">2.1.9</span>Names</a></li> </ol> </li> <li><a href="#sec-Document"><span class="spec-secid">2.2</span>Document</a></li> <li><a href="#sec-Language.Operations"><span class="spec-secid">2.3</span>Operations</a></li> <li><a href="#sec-Selection-Sets"><span class="spec-secid">2.4</span>Selection Sets</a></li> <li><a href="#sec-Language.Fields"><span class="spec-secid">2.5</span>Fields</a></li> <li><a href="#sec-Language.Arguments"><span class="spec-secid">2.6</span>Arguments</a></li> <li><a href="#sec-Field-Alias"><span class="spec-secid">2.7</span>Field Alias</a></li> <li><a href="#sec-Language.Fragments"><span class="spec-secid">2.8</span>Fragments</a><ol> <li><a href="#sec-Type-Conditions"><span class="spec-secid">2.8.1</span>Type Conditions</a></li> <li><a href="#sec-Inline-Fragments"><span class="spec-secid">2.8.2</span>Inline Fragments</a></li> </ol> </li> <li><a href="#sec-Input-Values"><span class="spec-secid">2.9</span>Input Values</a><ol> <li><a href="#sec-Int-Value"><span class="spec-secid">2.9.1</span>Int Value</a></li> <li><a href="#sec-Float-Value"><span class="spec-secid">2.9.2</span>Float Value</a></li> <li><a href="#sec-Boolean-Value"><span class="spec-secid">2.9.3</span>Boolean Value</a></li> <li><a href="#sec-String-Value"><span class="spec-secid">2.9.4</span>String Value</a></li> <li><a href="#sec-Null-Value"><span class="spec-secid">2.9.5</span>Null Value</a></li> <li><a href="#sec-Enum-Value"><span class="spec-secid">2.9.6</span>Enum Value</a></li> <li><a href="#sec-List-Value"><span class="spec-secid">2.9.7</span>List Value</a></li> <li><a href="#sec-Input-Object-Values"><span class="spec-secid">2.9.8</span>Input Object Values</a></li> </ol> </li> <li><a href="#sec-Language.Variables"><span class="spec-secid">2.10</span>Variables</a></li> <li><a href="#sec-Type-References"><span class="spec-secid">2.11</span>Type References</a></li> <li><a href="#sec-Language.Directives"><span class="spec-secid">2.12</span>Directives</a></li> </ol> </li> <li><a href="#sec-Type-System"><span class="spec-secid">3</span>Type System</a><ol> <li><a href="#sec-Type-System-Extensions"><span class="spec-secid">3.1</span>Type System Extensions</a></li> <li><a href="#sec-Descriptions"><span class="spec-secid">3.2</span>Descriptions</a></li> <li><a href="#sec-Schema"><span class="spec-secid">3.3</span>Schema</a><ol> <li><a href="#sec-Root-Operation-Types"><span class="spec-secid">3.3.1</span>Root Operation Types</a></li> <li><a href="#sec-Schema-Extension"><span class="spec-secid">3.3.2</span>Schema Extension</a></li> </ol> </li> <li><a href="#sec-Types"><span class="spec-secid">3.4</span>Types</a><ol> <li><a href="#sec-Wrapping-Types"><span class="spec-secid">3.4.1</span>Wrapping Types</a></li> <li><a href="#sec-Input-and-Output-Types"><span class="spec-secid">3.4.2</span>Input and Output Types</a></li> <li><a href="#sec-Type-Extensions"><span class="spec-secid">3.4.3</span>Type Extensions</a></li> </ol> </li> <li><a href="#sec-Scalars"><span class="spec-secid">3.5</span>Scalars</a><ol> <li><a href="#sec-Int"><span class="spec-secid">3.5.1</span>Int</a></li> <li><a href="#sec-Float"><span class="spec-secid">3.5.2</span>Float</a></li> <li><a href="#sec-String"><span class="spec-secid">3.5.3</span>String</a></li> <li><a href="#sec-Boolean"><span class="spec-secid">3.5.4</span>Boolean</a></li> <li><a href="#sec-ID"><span class="spec-secid">3.5.5</span>ID</a></li> <li><a href="#sec-Scalar-Extensions"><span class="spec-secid">3.5.6</span>Scalar Extensions</a></li> </ol> </li> <li><a href="#sec-Objects"><span class="spec-secid">3.6</span>Objects</a><ol> <li><a href="#sec-Field-Arguments"><span class="spec-secid">3.6.1</span>Field Arguments</a></li> <li><a href="#sec-Field-Deprecation"><span class="spec-secid">3.6.2</span>Field Deprecation</a></li> <li><a href="#sec-Object-Extensions"><span class="spec-secid">3.6.3</span>Object Extensions</a></li> </ol> </li> <li><a href="#sec-Interfaces"><span class="spec-secid">3.7</span>Interfaces</a><ol> <li><a href="#sec-Interface-Extensions"><span class="spec-secid">3.7.1</span>Interface Extensions</a></li> </ol> </li> <li><a href="#sec-Unions"><span class="spec-secid">3.8</span>Unions</a><ol> <li><a href="#sec-Union-Extensions"><span class="spec-secid">3.8.1</span>Union Extensions</a></li> </ol> </li> <li><a href="#sec-Enums"><span class="spec-secid">3.9</span>Enums</a><ol> <li><a href="#sec-Enum-Extensions"><span class="spec-secid">3.9.1</span>Enum Extensions</a></li> </ol> </li> <li><a href="#sec-Input-Objects"><span class="spec-secid">3.10</span>Input Objects</a><ol> <li><a href="#sec-Input-Object-Extensions"><span class="spec-secid">3.10.1</span>Input Object Extensions</a></li> </ol> </li> <li><a href="#sec-List"><span class="spec-secid">3.11</span>List</a></li> <li><a href="#sec-Non-Null"><span class="spec-secid">3.12</span>Non-Null</a><ol> <li><a href="#sec-Combining-List-and-Non-Null"><span class="spec-secid">3.12.1</span>Combining List and Non-Null</a></li> </ol> </li> <li><a href="#sec-Type-System.Directives"><span class="spec-secid">3.13</span>Directives</a><ol> <li><a href="#sec--skip"><span class="spec-secid">3.13.1</span>@skip</a></li> <li><a href="#sec--include"><span class="spec-secid">3.13.2</span>@include</a></li> <li><a href="#sec--deprecated"><span class="spec-secid">3.13.3</span>@deprecated</a></li> <li><a href="#sec--specifiedBy"><span class="spec-secid">3.13.4</span>@specifiedBy</a></li> </ol> </li> </ol> </li> <li><a href="#sec-Introspection"><span class="spec-secid">4</span>Introspection</a><ol> <li><a href="#sec-Type-Name-Introspection"><span class="spec-secid">4.1</span>Type Name Introspection</a></li> <li><a href="#sec-Schema-Introspection"><span class="spec-secid">4.2</span>Schema Introspection</a><ol> <li><a href="#sec-The-__Schema-Type"><span class="spec-secid">4.2.1</span>The __Schema Type</a></li> <li><a href="#sec-The-__Type-Type"><span class="spec-secid">4.2.2</span>The __Type Type</a></li> <li><a href="#sec-The-__Field-Type"><span class="spec-secid">4.2.3</span>The __Field Type</a></li> <li><a href="#sec-The-__InputValue-Type"><span class="spec-secid">4.2.4</span>The __InputValue Type</a></li> <li><a href="#sec-The-__EnumValue-Type"><span class="spec-secid">4.2.5</span>The __EnumValue Type</a></li> <li><a href="#sec-The-__Directive-Type"><span class="spec-secid">4.2.6</span>The __Directive Type</a></li> </ol> </li> </ol> </li> <li><a href="#sec-Validation"><span class="spec-secid">5</span>Validation</a><ol> <li><a href="#sec-Documents"><span class="spec-secid">5.1</span>Documents</a><ol> <li><a href="#sec-Executable-Definitions"><span class="spec-secid">5.1.1</span>Executable Definitions</a></li> </ol> </li> <li><a href="#sec-Validation.Operations"><span class="spec-secid">5.2</span>Operations</a><ol> <li><a href="#sec-Named-Operation-Definitions"><span class="spec-secid">5.2.1</span>Named Operation Definitions</a><ol> <li><a href="#sec-Operation-Name-Uniqueness"><span class="spec-secid">5.2.1.1</span>Operation Name Uniqueness</a></li> </ol> </li> <li><a href="#sec-Anonymous-Operation-Definitions"><span class="spec-secid">5.2.2</span>Anonymous Operation Definitions</a><ol> <li><a href="#sec-Lone-Anonymous-Operation"><span class="spec-secid">5.2.2.1</span>Lone Anonymous Operation</a></li> </ol> </li> <li><a href="#sec-Subscription-Operation-Definitions"><span class="spec-secid">5.2.3</span>Subscription Operation Definitions</a><ol> <li><a href="#sec-Single-root-field"><span class="spec-secid">5.2.3.1</span>Single root field</a></li> </ol> </li> </ol> </li> <li><a href="#sec-Validation.Fields"><span class="spec-secid">5.3</span>Fields</a><ol> <li><a href="#sec-Field-Selections"><span class="spec-secid">5.3.1</span>Field Selections</a></li> <li><a href="#sec-Field-Selection-Merging"><span class="spec-secid">5.3.2</span>Field Selection Merging</a></li> <li><a href="#sec-Leaf-Field-Selections"><span class="spec-secid">5.3.3</span>Leaf Field Selections</a></li> </ol> </li> <li><a href="#sec-Validation.Arguments"><span class="spec-secid">5.4</span>Arguments</a><ol> <li><a href="#sec-Argument-Names"><span class="spec-secid">5.4.1</span>Argument Names</a></li> <li><a href="#sec-Argument-Uniqueness"><span class="spec-secid">5.4.2</span>Argument Uniqueness</a><ol> <li><a href="#sec-Required-Arguments"><span class="spec-secid">5.4.2.1</span>Required Arguments</a></li> </ol> </li> </ol> </li> <li><a href="#sec-Validation.Fragments"><span class="spec-secid">5.5</span>Fragments</a><ol> <li><a href="#sec-Fragment-Declarations"><span class="spec-secid">5.5.1</span>Fragment Declarations</a><ol> <li><a href="#sec-Fragment-Name-Uniqueness"><span class="spec-secid">5.5.1.1</span>Fragment Name Uniqueness</a></li> <li><a href="#sec-Fragment-Spread-Type-Existence"><span class="spec-secid">5.5.1.2</span>Fragment Spread Type Existence</a></li> <li><a href="#sec-Fragments-On-Composite-Types"><span class="spec-secid">5.5.1.3</span>Fragments On Composite Types</a></li> <li><a href="#sec-Fragments-Must-Be-Used"><span class="spec-secid">5.5.1.4</span>Fragments Must Be Used</a></li> </ol> </li> <li><a href="#sec-Fragment-Spreads"><span class="spec-secid">5.5.2</span>Fragment Spreads</a><ol> <li><a href="#sec-Fragment-spread-target-defined"><span class="spec-secid">5.5.2.1</span>Fragment spread target defined</a></li> <li><a href="#sec-Fragment-spreads-must-not-form-cycles"><span class="spec-secid">5.5.2.2</span>Fragment spreads must not form cycles</a></li> <li><a href="#sec-Fragment-spread-is-possible"><span class="spec-secid">5.5.2.3</span>Fragment spread is possible</a><ol> <li><a href="#sec-Object-Spreads-In-Object-Scope"><span class="spec-secid">5.5.2.3.1</span>Object Spreads In Object Scope</a></li> <li><a href="#sec-Abstract-Spreads-in-Object-Scope"><span class="spec-secid">5.5.2.3.2</span>Abstract Spreads in Object Scope</a></li> <li><a href="#sec-Object-Spreads-In-Abstract-Scope"><span class="spec-secid">5.5.2.3.3</span>Object Spreads In Abstract Scope</a></li> <li><a href="#sec-Abstract-Spreads-in-Abstract-Scope"><span class="spec-secid">5.5.2.3.4</span>Abstract Spreads in Abstract Scope</a></li> </ol> </li> </ol> </li> </ol> </li> <li><a href="#sec-Values"><span class="spec-secid">5.6</span>Values</a><ol> <li><a href="#sec-Values-of-Correct-Type"><span class="spec-secid">5.6.1</span>Values of Correct Type</a></li> <li><a href="#sec-Input-Object-Field-Names"><span class="spec-secid">5.6.2</span>Input Object Field Names</a></li> <li><a href="#sec-Input-Object-Field-Uniqueness"><span class="spec-secid">5.6.3</span>Input Object Field Uniqueness</a></li> <li><a href="#sec-Input-Object-Required-Fields"><span class="spec-secid">5.6.4</span>Input Object Required Fields</a></li> </ol> </li> <li><a href="#sec-Validation.Directives"><span class="spec-secid">5.7</span>Directives</a><ol> <li><a href="#sec-Directives-Are-Defined"><span class="spec-secid">5.7.1</span>Directives Are Defined</a></li> <li><a href="#sec-Directives-Are-In-Valid-Locations"><span class="spec-secid">5.7.2</span>Directives Are In Valid Locations</a></li> <li><a href="#sec-Directives-Are-Unique-Per-Location"><span class="spec-secid">5.7.3</span>Directives Are Unique Per Location</a></li> </ol> </li> <li><a href="#sec-Validation.Variables"><span class="spec-secid">5.8</span>Variables</a><ol> <li><a href="#sec-Variable-Uniqueness"><span class="spec-secid">5.8.1</span>Variable Uniqueness</a></li> <li><a href="#sec-Variables-Are-Input-Types"><span class="spec-secid">5.8.2</span>Variables Are Input Types</a></li> <li><a href="#sec-All-Variable-Uses-Defined"><span class="spec-secid">5.8.3</span>All Variable Uses Defined</a></li> <li><a href="#sec-All-Variables-Used"><span class="spec-secid">5.8.4</span>All Variables Used</a></li> <li><a href="#sec-All-Variable-Usages-are-Allowed"><span class="spec-secid">5.8.5</span>All Variable Usages are Allowed</a></li> </ol> </li> </ol> </li> <li><a href="#sec-Execution"><span class="spec-secid">6</span>Execution</a><ol> <li><a href="#sec-Executing-Requests"><span class="spec-secid">6.1</span>Executing Requests</a><ol> <li><a href="#sec-Validating-Requests"><span class="spec-secid">6.1.1</span>Validating Requests</a></li> <li><a href="#sec-Coercing-Variable-Values"><span class="spec-secid">6.1.2</span>Coercing Variable Values</a></li> </ol> </li> <li><a href="#sec-Executing-Operations"><span class="spec-secid">6.2</span>Executing Operations</a><ol> <li><a href="#sec-Query"><span class="spec-secid">6.2.1</span>Query</a></li> <li><a href="#sec-Mutation"><span class="spec-secid">6.2.2</span>Mutation</a></li> <li><a href="#sec-Subscription"><span class="spec-secid">6.2.3</span>Subscription</a><ol> <li><a href="#sec-Source-Stream"><span class="spec-secid">6.2.3.1</span>Source Stream</a></li> <li><a href="#sec-Response-Stream"><span class="spec-secid">6.2.3.2</span>Response Stream</a></li> <li><a href="#sec-Unsubscribe"><span class="spec-secid">6.2.3.3</span>Unsubscribe</a></li> </ol> </li> </ol> </li> <li><a href="#sec-Executing-Selection-Sets"><span class="spec-secid">6.3</span>Executing Selection Sets</a><ol> <li><a href="#sec-Normal-and-Serial-Execution"><span class="spec-secid">6.3.1</span>Normal and Serial Execution</a></li> <li><a href="#sec-Field-Collection"><span class="spec-secid">6.3.2</span>Field Collection</a></li> </ol> </li> <li><a href="#sec-Executing-Fields"><span class="spec-secid">6.4</span>Executing Fields</a><ol> <li><a href="#sec-Coercing-Field-Arguments"><span class="spec-secid">6.4.1</span>Coercing Field Arguments</a></li> <li><a href="#sec-Value-Resolution"><span class="spec-secid">6.4.2</span>Value Resolution</a></li> <li><a href="#sec-Value-Completion"><span class="spec-secid">6.4.3</span>Value Completion</a></li> <li><a href="#sec-Handling-Field-Errors"><span class="spec-secid">6.4.4</span>Handling Field Errors</a></li> </ol> </li> </ol> </li> <li><a href="#sec-Response"><span class="spec-secid">7</span>Response</a><ol> <li><a href="#sec-Response-Format"><span class="spec-secid">7.1</span>Response Format</a><ol> <li><a href="#sec-Data"><span class="spec-secid">7.1.1</span>Data</a></li> <li><a href="#sec-Errors"><span class="spec-secid">7.1.2</span>Errors</a></li> </ol> </li> <li><a href="#sec-Serialization-Format"><span class="spec-secid">7.2</span>Serialization Format</a><ol> <li><a href="#sec-JSON-Serialization"><span class="spec-secid">7.2.1</span>JSON Serialization</a></li> <li><a href="#sec-Serialized-Map-Ordering"><span class="spec-secid">7.2.2</span>Serialized Map Ordering</a></li> </ol> </li> </ol> </li> <li><a href="#sec-Appendix-Notation-Conventions"><span class="spec-secid">A</span>Appendix: Notation Conventions</a><ol> <li><a href="#sec-Context-Free-Grammar"><span class="spec-secid">A.1</span>Context-Free Grammar</a></li> <li><a href="#sec-Lexical-and-Syntactical-Grammar"><span class="spec-secid">A.2</span>Lexical and Syntactical Grammar</a></li> <li><a href="#sec-Grammar-Notation"><span class="spec-secid">A.3</span>Grammar Notation</a></li> <li><a href="#sec-Grammar-Semantics"><span class="spec-secid">A.4</span>Grammar Semantics</a></li> <li><a href="#sec-Algorithms"><span class="spec-secid">A.5</span>Algorithms</a></li> </ol> </li> <li><a href="#sec-Appendix-Grammar-Summary"><span class="spec-secid">B</span>Appendix: Grammar Summary</a><ol> <li><a href="#sec-Appendix-Grammar-Summary.Source-Text"><span class="spec-secid">B.1</span>Source Text</a></li> <li><a href="#sec-Appendix-Grammar-Summary.Ignored-Tokens"><span class="spec-secid">B.2</span>Ignored Tokens</a></li> <li><a href="#sec-Appendix-Grammar-Summary.Lexical-Tokens"><span class="spec-secid">B.3</span>Lexical Tokens</a></li> <li><a href="#sec-Document-Syntax"><span class="spec-secid">B.4</span>Document Syntax</a></li> </ol> </li> <li><a href="#index"><span class="spec-secid">§</span>Index</a></li> </ol> </nav> </header> <section id="sec-Overview" secid="1"> <h1 data-source="spec/Section%201%20--%20Overview.md#L1"><span class="spec-secid" title="link to this section"><a href="#sec-Overview">1</a></span>Overview</h1> <p data-source="spec/Section%201%20--%20Overview.md#L3-L5">GraphQL is a query language designed to build client applications by providing an intuitive and flexible syntax and system for describing their data requirements and interactions.</p> <p data-source="spec/Section%201%20--%20Overview.md#L7-L8">For example, this GraphQL request will receive the name of the user with id 4 from the Facebook implementation of GraphQL.</p> <pre id="example-85684" class="spec-example" data-language="graphql" data-source="spec/Section%201%20--%20Overview.md#L10-L16"><a href="#example-85684">Example № 3</a><code><span class="token punctuation">{</span> <span class="token property-query">user</span><span class="token punctuation">(</span><span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%201%20--%20Overview.md#L18">Which produces the resulting data (in JSON):</p> <pre id="example-90fe6" class="spec-example" data-language="json" data-source="spec/Section%201%20--%20Overview.md#L20-L26"><a href="#example-90fe6">Example № 4</a><code><span class="token punctuation">{</span> <span class="token property">"user"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Mark Zuckerberg"</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%201%20--%20Overview.md#L28-L35">GraphQL is not a programming language capable of arbitrary computation, but is instead a language used to make requests to application services that have capabilities defined in this specification. GraphQL does not mandate a particular programming language or storage system for application services that implement it. Instead, application services take their capabilities and map them to a uniform language, type system, and philosophy that GraphQL encodes. This provides a unified interface friendly to product development and a powerful platform for tool-building.</p> <p data-source="spec/Section%201%20--%20Overview.md#L37">GraphQL has a number of design principles:</p> <ul> <li data-source="spec/Section%201%20--%20Overview.md#L39-L42"><strong>Product-centric</strong>: GraphQL is unapologetically driven by the requirements of views and the front-end engineers that write them. GraphQL starts with their way of thinking and requirements and builds the language and runtime necessary to enable that.</li> <li data-source="spec/Section%201%20--%20Overview.md#L44-L48"><strong>Hierarchical</strong>: Most product development today involves the creation and manipulation of view hierarchies. To achieve congruence with the structure of these applications, a GraphQL request itself is structured hierarchically. The request is shaped just like the data in its response. It is a natural way for clients to describe data requirements.</li> <li data-source="spec/Section%201%20--%20Overview.md#L50-L55"><strong>Strong-typing</strong>: Every GraphQL service defines an application-specific type system. Requests are executed within the context of that type system. Given a GraphQL operation, tools can ensure that it is both syntactically correct and valid within that type system before execution, i.e. at development time, and the service can make certain guarantees about the shape and nature of the response.</li> <li data-source="spec/Section%201%20--%20Overview.md#L57-L64"><strong>Client-specified response</strong>: Through its type system, a GraphQL service publishes the capabilities that its clients are allowed to consume. It is the client that is responsible for specifying exactly how it will consume those published capabilities. These requests are specified at field-level granularity. In the majority of client-server applications written without GraphQL, the service determines the shape of data returned from its various endpoints. A GraphQL response, on the other hand, contains exactly what a client asks for and no more.</li> <li data-source="spec/Section%201%20--%20Overview.md#L66-L69"><strong>Introspective</strong>: GraphQL is introspective. A GraphQL service’s type system can be queryable by the GraphQL language itself, as will be described in this specification. GraphQL introspection serves as a powerful platform for building common tools and client software libraries.</li> </ul> <p data-source="spec/Section%201%20--%20Overview.md#L71-L76">Because of these principles, GraphQL is a powerful and productive environment for building client applications. Product developers and designers building applications against working GraphQL services—supported with quality tools—can quickly become productive without reading extensive documentation and with little or no formal training. To enable that experience, there must be those that build those services and tools.</p> <p data-source="spec/Section%201%20--%20Overview.md#L78-L86">The following formal specification serves as a reference for those builders. It describes the language and its grammar, the type system and the introspection system used to query it, and the execution and validation engines with the algorithms to power them. The goal of this specification is to provide a foundation and framework for an ecosystem of GraphQL tools, client libraries, and service implementations—spanning both organizations and platforms—that has yet to be built. We look forward to working with the community in order to do that. </p> </section> <section id="sec-Language" secid="2"> <h1 data-source="spec/Section%202%20--%20Language.md#L1"><span class="spec-secid" title="link to this section"><a href="#sec-Language">2</a></span>Language</h1> <p data-source="spec/Section%202%20--%20Language.md#L3-L6">Clients use the GraphQL query language to make requests to a GraphQL service. We refer to these request sources as documents. A document may contain operations (queries, mutations, and subscriptions) as well as fragments, a common unit of composition allowing for data requirement reuse.</p> <p data-source="spec/Section%202%20--%20Language.md#L8-L12">A GraphQL document is defined as a syntactic grammar where terminal symbols are tokens (indivisible lexical units). These tokens are defined in a lexical grammar which matches patterns of source characters. In this document, syntactic grammar productions are distinguished with a colon <code>:</code> while lexical grammar productions are distinguished with a double-colon <code>::</code>.</p> <p data-source="spec/Section%202%20--%20Language.md#L14-L17">The source text of a GraphQL document must be a sequence of <span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span>. The character sequence must be described by a sequence of <span class="spec-nt"><a href="#Token" data-name="Token">Token</a></span> and <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span> lexical grammars. The lexical token sequence, omitting <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span>, must be described by a single <span class="spec-nt"><a href="#Document" data-name="Document">Document</a></span> syntactic grammar.</p> <div id="note-e800c" class="spec-note" data-source="spec/Section%202%20--%20Language.md#L19-L21"> <a href="#note-e800c">Note</a> See <a href="#sec-Appendix-Notation-Conventions">Appendix A</a> for more information about the lexical and syntactic grammar and other notational conventions used throughout this document.</div> <section id="sec-Language.Lexical-Analysis-Syntactic-Parse" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L23"><a href="#sec-Language.Lexical-Analysis-Syntactic-Parse" title="link to this subsection">Lexical Analysis & Syntactic Parse</a></h6> <p data-source="spec/Section%202%20--%20Language.md#L25-L30">The source text of a GraphQL document is first converted into a sequence of lexical tokens, <span class="spec-nt"><a href="#Token" data-name="Token">Token</a></span>, and ignored tokens, <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span>. The source text is scanned from left to right, repeatedly taking the next possible sequence of code-points allowed by the lexical grammar productions as the next token. This sequence of lexical tokens are then scanned from left to right to produce an abstract syntax tree (AST) according to the <span class="spec-nt"><a href="#Document" data-name="Document">Document</a></span> syntactical grammar.</p> <p data-source="spec/Section%202%20--%20Language.md#L32-L34">Lexical grammar productions in this document use <em>lookahead restrictions</em> to remove ambiguity and ensure a single valid lexical analysis. A lexical token is only valid if not followed by a character in its lookahead restriction.</p> <p data-source="spec/Section%202%20--%20Language.md#L36-L40">For example, an <span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span> has the restriction <span class="spec-lookahead ntset not"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span></span>, so cannot be followed by a <span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span>. Because of this, the sequence <span class="spec-t">123</span> cannot represent the tokens (<span class="spec-t">12</span>, <span class="spec-t">3</span>) since <span class="spec-t">12</span> is followed by the <span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span> <span class="spec-t">3</span> and so must only represent a single token. Use <span class="spec-nt"><a href="#WhiteSpace" data-name="WhiteSpace">WhiteSpace</a></span> or other <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span> between characters to represent multiple tokens.</p> <div id="note-ba22f" class="spec-note" data-source="spec/Section%202%20--%20Language.md#L42-L44"> <a href="#note-ba22f">Note</a> This typically has the same behavior as a “<a href="https://en.wikipedia.org/wiki/Maximal_munch">maximal munch</a>” longest possible match, however some lookahead restrictions include additional constraints.</div> </section> <section id="sec-Language.Source-Text" secid="2.1"> <h2 data-source="spec/Section%202%20--%20Language.md#L47"><span class="spec-secid" title="link to this section"><a href="#sec-Language.Source-Text">2.1</a></span>Source Text</h2> <div class="spec-production d2" id="SourceCharacter" data-source="spec/Section%202%20--%20Language.md#L49-L53"> <span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span><div class="spec-rhs"><span class="spec-prose">U+0009</span></div> <div class="spec-rhs"><span class="spec-prose">U+000A</span></div> <div class="spec-rhs"><span class="spec-prose">U+000D</span></div> <div class="spec-rhs"><span class="spec-prose">U+0020–U+FFFF</span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L55-L61">GraphQL documents are expressed as a sequence of <a href="https://unicode.org/standard/standard.html">Unicode</a> code points (informally referred to as <em>“characters”</em> through most of this specification). However, with few exceptions, most of GraphQL is expressed only in the original non-control ASCII range so as to be as widely compatible with as many existing tools, languages, and serialization formats as possible and avoid display issues in text editors and source control.</p> <div id="note-3e8b0" class="spec-note" data-source="spec/Section%202%20--%20Language.md#L63-L64"> <a href="#note-3e8b0">Note</a> Non-ASCII Unicode characters may appear freely within <span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span> and <span class="spec-nt"><a href="#Comment" data-name="Comment">Comment</a></span> portions of GraphQL.</div> <section id="sec-Unicode" secid="2.1.1"> <h3 data-source="spec/Section%202%20--%20Language.md#L67"><span class="spec-secid" title="link to this section"><a href="#sec-Unicode">2.1.1</a></span>Unicode</h3> <div class="spec-production d2" id="UnicodeBOM" data-source="spec/Section%202%20--%20Language.md#L69"> <span class="spec-nt"><a href="#UnicodeBOM" data-name="UnicodeBOM">UnicodeBOM</a></span><div class="spec-rhs"><span class="spec-prose">Byte Order Mark (U+FEFF)</span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L71-L74">The “Byte Order Mark” is a special Unicode character which may appear at the beginning of a file containing Unicode which programs may use to determine the fact that the text stream is Unicode, what endianness the text stream is in, and which of several Unicode encodings to interpret.</p> </section> <section id="sec-White-Space" secid="2.1.2"> <h3 data-source="spec/Section%202%20--%20Language.md#L77"><span class="spec-secid" title="link to this section"><a href="#sec-White-Space">2.1.2</a></span>White Space</h3> <div class="spec-production d2" id="WhiteSpace" data-source="spec/Section%202%20--%20Language.md#L79-L81"> <span class="spec-nt"><a href="#WhiteSpace" data-name="WhiteSpace">WhiteSpace</a></span><div class="spec-rhs"><span class="spec-prose">Horizontal Tab (U+0009)</span></div> <div class="spec-rhs"><span class="spec-prose">Space (U+0020)</span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L83-L87">White space is used to improve legibility of source text and act as separation between tokens, and any amount of white space may appear before or after any token. White space between tokens is not significant to the semantic meaning of a GraphQL Document, however white space characters may appear within a <span class="spec-nt"><span data-name="String">String</span></span> or <span class="spec-nt"><a href="#Comment" data-name="Comment">Comment</a></span> token.</p> <div id="note-e49cd" class="spec-note" data-source="spec/Section%202%20--%20Language.md#L89-L91"> <a href="#note-e49cd">Note</a> GraphQL intentionally does not consider Unicode “Zs” category characters as white-space, avoiding misinterpretation by text editors and source control tools.</div> </section> <section id="sec-Line-Terminators" secid="2.1.3"> <h3 data-source="spec/Section%202%20--%20Language.md#L94"><span class="spec-secid" title="link to this section"><a href="#sec-Line-Terminators">2.1.3</a></span>Line Terminators</h3> <div class="spec-production d2" id="LineTerminator" data-source="spec/Section%202%20--%20Language.md#L96-L99"> <span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span><div class="spec-rhs"><span class="spec-prose">New Line (U+000A)</span></div> <div class="spec-rhs"><span class="spec-prose">Carriage Return (U+000D)</span><span class="spec-lookahead not"><span class="spec-prose">New Line (U+000A)</span></span></div> <div class="spec-rhs"><span class="spec-prose">Carriage Return (U+000D)</span><span class="spec-prose">New Line (U+000A)</span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L101-L104">Like white space, line terminators are used to improve the legibility of source text and separate lexical tokens, any amount may appear before or after any other token and have no significance to the semantic meaning of a GraphQL Document. Line terminators are not found within any other token.</p> <div id="note-2b19e" class="spec-note" data-source="spec/Section%202%20--%20Language.md#L106-L108"> <a href="#note-2b19e">Note</a> Any error reporting which provides the line number in the source of the offending syntax should use the preceding amount of <span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span> to produce the line number.</div> </section> <section id="sec-Comments" secid="2.1.4"> <h3 data-source="spec/Section%202%20--%20Language.md#L111"><span class="spec-secid" title="link to this section"><a href="#sec-Comments">2.1.4</a></span>Comments</h3> <div class="spec-production d2" id="Comment" data-source="spec/Section%202%20--%20Language.md#L113"> <span class="spec-nt"><a href="#Comment" data-name="Comment">Comment</a></span><div class="spec-rhs"><span class="spec-t">#</span><span class="spec-quantified"><span class="spec-nt"><a href="#CommentChar" data-name="CommentChar">CommentChar</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead ntset not"><span class="spec-nt"><a href="#CommentChar" data-name="CommentChar">CommentChar</a></span></span></div> </div> <div class="spec-production d2" id="CommentChar" data-source="spec/Section%202%20--%20Language.md#L115"> <span class="spec-nt"><a href="#CommentChar" data-name="CommentChar">CommentChar</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span><span class="spec-butnot"><span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span></span></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L117-L118">GraphQL source documents may contain single-line comments, starting with the <span class="spec-t">#</span> marker.</p> <p data-source="spec/Section%202%20--%20Language.md#L120-L123">A comment can contain any Unicode code point in <span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span> except <span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span> so a comment always consists of all code points starting with the <span class="spec-t">#</span> character up to but not including the <span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span> (or end of the source).</p> <p data-source="spec/Section%202%20--%20Language.md#L125-L127">Comments are <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span> like white space and may appear after any token, or before a <span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span>, and have no significance to the semantic meaning of a GraphQL Document.</p> </section> <section id="sec-Insignificant-Commas" secid="2.1.5"> <h3 data-source="spec/Section%202%20--%20Language.md#L130"><span class="spec-secid" title="link to this section"><a href="#sec-Insignificant-Commas">2.1.5</a></span>Insignificant Commas</h3> <div class="spec-production d2" id="Comma" data-source="spec/Section%202%20--%20Language.md#L132"> <span class="spec-nt"><a href="#Comma" data-name="Comma">Comma</a></span><div class="spec-rhs"><span class="spec-t">,</span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L134-L136">Similar to white space and line terminators, commas (<span class="spec-t">,</span>) are used to improve the legibility of source text and separate lexical tokens but are otherwise syntactically and semantically insignificant within GraphQL Documents.</p> <p data-source="spec/Section%202%20--%20Language.md#L138-L142">Non-significant comma characters ensure that the absence or presence of a comma does not meaningfully alter the interpreted syntax of the document, as this can be a common user-error in other languages. It also allows for the stylistic use of either trailing commas or line terminators as list delimiters which are both often desired for legibility and maintainability of source code.</p> </section> <section id="sec-Language.Source-Text.Lexical-Tokens" secid="2.1.6"> <h3 data-source="spec/Section%202%20--%20Language.md#L145"><span class="spec-secid" title="link to this section"><a href="#sec-Language.Source-Text.Lexical-Tokens">2.1.6</a></span>Lexical Tokens</h3> <div class="spec-production d2" id="Token" data-source="spec/Section%202%20--%20Language.md#L147-L152"> <span class="spec-nt"><a href="#Token" data-name="Token">Token</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Punctuator" data-name="Punctuator">Punctuator</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L154-L156">A GraphQL document is comprised of several kinds of indivisible lexical tokens defined here in a lexical grammar by patterns of source Unicode characters. Lexical tokens may be separated by <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span> tokens.</p> <p data-source="spec/Section%202%20--%20Language.md#L158">Tokens are later used as terminal symbols in GraphQL syntactic grammar rules.</p> </section> <section id="sec-Language.Source-Text.Ignored-Tokens" secid="2.1.7"> <h3 data-source="spec/Section%202%20--%20Language.md#L161"><span class="spec-secid" title="link to this section"><a href="#sec-Language.Source-Text.Ignored-Tokens">2.1.7</a></span>Ignored Tokens</h3> <div class="spec-production d2" id="Ignored" data-source="spec/Section%202%20--%20Language.md#L163-L168"> <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#UnicodeBOM" data-name="UnicodeBOM">UnicodeBOM</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#WhiteSpace" data-name="WhiteSpace">WhiteSpace</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#Comment" data-name="Comment">Comment</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#Comma" data-name="Comma">Comma</a></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L170-L172"><span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span> tokens are used to improve readability and provide separation between lexical tokens, but are otherwise insignificant and not referenced in syntactical grammar productions.</p> <p data-source="spec/Section%202%20--%20Language.md#L174-L179">Any amount of <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span> may appear before and after every lexical token. No ignored regions of a source document are significant, however <span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span> which appear in <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span> may also appear within a lexical <span class="spec-nt"><a href="#Token" data-name="Token">Token</a></span> in a significant way, for example a <span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span> may contain white space characters. No <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span> may appear <em>within</em> a <span class="spec-nt"><a href="#Token" data-name="Token">Token</a></span>, for example no white space characters are permitted between the characters defining a <span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span>.</p> </section> <section id="sec-Punctuators" secid="2.1.8"> <h3 data-source="spec/Section%202%20--%20Language.md#L182"><span class="spec-secid" title="link to this section"><a href="#sec-Punctuators">2.1.8</a></span>Punctuators</h3> <div class="spec-production d2" id="Punctuator" data-source="spec/Section%202%20--%20Language.md#L184"> <span class="spec-nt"><a href="#Punctuator" data-name="Punctuator">Punctuator</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">!</span></td><td class="spec-rhs"><span class="spec-t">$</span></td><td class="spec-rhs"><span class="spec-t">&</span></td><td class="spec-rhs"><span class="spec-t">(</span></td><td class="spec-rhs"><span class="spec-t">)</span></td><td class="spec-rhs"><span class="spec-t">...</span></td><td class="spec-rhs"><span class="spec-t">:</span></td><td class="spec-rhs"><span class="spec-t">=</span></td><td class="spec-rhs"><span class="spec-t">@</span></td><td class="spec-rhs"><span class="spec-t">[</span></td><td class="spec-rhs"><span class="spec-t">]</span></td><td class="spec-rhs"><span class="spec-t">{</span></td><td class="spec-rhs"><span class="spec-t">|</span></td><td class="spec-rhs"><span class="spec-t">}</span></td></tr> </table></div></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L186-L188">GraphQL documents include punctuation in order to describe structure. GraphQL is a data description language and not a programming language, therefore GraphQL lacks the punctuation often used to describe mathematical expressions.</p> </section> <section id="sec-Names" secid="2.1.9"> <h3 data-source="spec/Section%202%20--%20Language.md#L191"><span class="spec-secid" title="link to this section"><a href="#sec-Names">2.1.9</a></span>Names</h3> <div class="spec-production d2" id="Name" data-source="spec/Section%202%20--%20Language.md#L193-L194"> <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#NameContinue" data-name="NameContinue">NameContinue</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead ntset not"><span class="spec-nt"><a href="#NameContinue" data-name="NameContinue">NameContinue</a></span></span></div> </div> <div class="spec-production d2" id="NameStart" data-source="spec/Section%202%20--%20Language.md#L196-L198"> <span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Letter" data-name="Letter">Letter</a></span></div> <div class="spec-rhs"><span class="spec-t">_</span></div> </div> <div class="spec-production d2" id="NameContinue" data-source="spec/Section%202%20--%20Language.md#L200-L203"> <span class="spec-nt"><a href="#NameContinue" data-name="NameContinue">NameContinue</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Letter" data-name="Letter">Letter</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span></div> <div class="spec-rhs"><span class="spec-t">_</span></div> </div> <div class="spec-production d2" id="Letter" data-source="spec/Section%202%20--%20Language.md#L205-L209"> <span class="spec-nt"><a href="#Letter" data-name="Letter">Letter</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">A</span></td><td class="spec-rhs"><span class="spec-t">B</span></td><td class="spec-rhs"><span class="spec-t">C</span></td><td class="spec-rhs"><span class="spec-t">D</span></td><td class="spec-rhs"><span class="spec-t">E</span></td><td class="spec-rhs"><span class="spec-t">F</span></td><td class="spec-rhs"><span class="spec-t">G</span></td><td class="spec-rhs"><span class="spec-t">H</span></td><td class="spec-rhs"><span class="spec-t">I</span></td><td class="spec-rhs"><span class="spec-t">J</span></td><td class="spec-rhs"><span class="spec-t">K</span></td><td class="spec-rhs"><span class="spec-t">L</span></td><td class="spec-rhs"><span class="spec-t">M</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">N</span></td><td class="spec-rhs"><span class="spec-t">O</span></td><td class="spec-rhs"><span class="spec-t">P</span></td><td class="spec-rhs"><span class="spec-t">Q</span></td><td class="spec-rhs"><span class="spec-t">R</span></td><td class="spec-rhs"><span class="spec-t">S</span></td><td class="spec-rhs"><span class="spec-t">T</span></td><td class="spec-rhs"><span class="spec-t">U</span></td><td class="spec-rhs"><span class="spec-t">V</span></td><td class="spec-rhs"><span class="spec-t">W</span></td><td class="spec-rhs"><span class="spec-t">X</span></td><td class="spec-rhs"><span class="spec-t">Y</span></td><td class="spec-rhs"><span class="spec-t">Z</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">a</span></td><td class="spec-rhs"><span class="spec-t">b</span></td><td class="spec-rhs"><span class="spec-t">c</span></td><td class="spec-rhs"><span class="spec-t">d</span></td><td class="spec-rhs"><span class="spec-t">e</span></td><td class="spec-rhs"><span class="spec-t">f</span></td><td class="spec-rhs"><span class="spec-t">g</span></td><td class="spec-rhs"><span class="spec-t">h</span></td><td class="spec-rhs"><span class="spec-t">i</span></td><td class="spec-rhs"><span class="spec-t">j</span></td><td class="spec-rhs"><span class="spec-t">k</span></td><td class="spec-rhs"><span class="spec-t">l</span></td><td class="spec-rhs"><span class="spec-t">m</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">n</span></td><td class="spec-rhs"><span class="spec-t">o</span></td><td class="spec-rhs"><span class="spec-t">p</span></td><td class="spec-rhs"><span class="spec-t">q</span></td><td class="spec-rhs"><span class="spec-t">r</span></td><td class="spec-rhs"><span class="spec-t">s</span></td><td class="spec-rhs"><span class="spec-t">t</span></td><td class="spec-rhs"><span class="spec-t">u</span></td><td class="spec-rhs"><span class="spec-t">v</span></td><td class="spec-rhs"><span class="spec-t">w</span></td><td class="spec-rhs"><span class="spec-t">x</span></td><td class="spec-rhs"><span class="spec-t">y</span></td><td class="spec-rhs"><span class="spec-t">z</span></td></tr> </table></div></div> </div> <div class="spec-production d2" id="Digit" data-source="spec/Section%202%20--%20Language.md#L211-L212"> <span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">0</span></td><td class="spec-rhs"><span class="spec-t">1</span></td><td class="spec-rhs"><span class="spec-t">2</span></td><td class="spec-rhs"><span class="spec-t">3</span></td><td class="spec-rhs"><span class="spec-t">4</span></td><td class="spec-rhs"><span class="spec-t">5</span></td><td class="spec-rhs"><span class="spec-t">6</span></td><td class="spec-rhs"><span class="spec-t">7</span></td><td class="spec-rhs"><span class="spec-t">8</span></td><td class="spec-rhs"><span class="spec-t">9</span></td></tr> </table></div></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L214-L216">GraphQL Documents are full of named things: operations, fields, arguments, types, directives, fragments, and variables. All names must follow the same grammatical form.</p> <p data-source="spec/Section%202%20--%20Language.md#L218-L220">Names in GraphQL are case-sensitive. That is to say <code>name</code>, <code>Name</code>, and <code>NAME</code> all refer to different names. Underscores are significant, which means <code>other_name</code> and <code>othername</code> are two different names.</p> <p data-source="spec/Section%202%20--%20Language.md#L222-L224">A <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span> must not be followed by a <span class="spec-nt"><a href="#NameContinue" data-name="NameContinue">NameContinue</a></span>. In other words, a <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span> token is always the longest possible valid sequence. The source characters <span class="spec-t">a1</span> cannot be interpreted as two tokens since <span class="spec-t">a</span> is followed by the <span class="spec-nt"><a href="#NameContinue" data-name="NameContinue">NameContinue</a></span> <span class="spec-t">1</span>.</p> <div id="note-46408" class="spec-note" data-source="spec/Section%202%20--%20Language.md#L226-L228"> <a href="#note-46408">Note</a> Names in GraphQL are limited to the Latin <acronym>ASCII</acronym> subset of <span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span> in order to support interoperation with as many other systems as possible.</div> <section id="sec-Names.Reserved-Names" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L230"><a href="#sec-Names.Reserved-Names" title="link to this subsection">Reserved Names</a></h6> <p data-source="spec/Section%202%20--%20Language.md#L232-L234">Any <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span> within a GraphQL type system must not start with two underscores <span class="spec-string">"__"</span> unless it is part of the <a href="#sec-Introspection">introspection system</a> as defined by this specification.</p> </section> </section> </section> <section id="sec-Document" secid="2.2"> <h2 data-source="spec/Section%202%20--%20Language.md#L237"><span class="spec-secid" title="link to this section"><a href="#sec-Document">2.2</a></span>Document</h2> <div class="spec-production" id="Document" data-source="spec/Section%202%20--%20Language.md#L239"> <span class="spec-nt"><a href="#Document" data-name="Document">Document</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Definition" data-name="Definition">Definition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production" id="Definition" data-source="spec/Section%202%20--%20Language.md#L241-L243"> <span class="spec-nt"><a href="#Definition" data-name="Definition">Definition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ExecutableDefinition" data-name="ExecutableDefinition">ExecutableDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#TypeSystemDefinitionOrExtension" data-name="TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></span></div> </div> <div class="spec-production" id="ExecutableDocument" data-source="spec/Section%202%20--%20Language.md#L245"> <span class="spec-nt"><a href="#ExecutableDocument" data-name="ExecutableDocument">ExecutableDocument</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#ExecutableDefinition" data-name="ExecutableDefinition">ExecutableDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production" id="ExecutableDefinition" data-source="spec/Section%202%20--%20Language.md#L247-L249"> <span class="spec-nt"><a href="#ExecutableDefinition" data-name="ExecutableDefinition">ExecutableDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#OperationDefinition" data-name="OperationDefinition">OperationDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#FragmentDefinition" data-name="FragmentDefinition">FragmentDefinition</a></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L251-L253">A GraphQL Document describes a complete file or request string operated on by a GraphQL service or client. A document contains multiple definitions, either executable or representative of a GraphQL type system.</p> <p data-source="spec/Section%202%20--%20Language.md#L255-L259">Documents are only executable by a GraphQL service if they are <span class="spec-nt"><a href="#ExecutableDocument" data-name="ExecutableDocument">ExecutableDocument</a></span> and contain at least one <span class="spec-nt"><a href="#OperationDefinition" data-name="OperationDefinition">OperationDefinition</a></span>. A Document which contains <span class="spec-nt"><a href="#TypeSystemDefinitionOrExtension" data-name="TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></span> must not be executed; GraphQL execution services which receive a Document containing these should return a descriptive error.</p> <p data-source="spec/Section%202%20--%20Language.md#L261-L262">GraphQL services which only seek to execute GraphQL requests and not construct a new GraphQL schema may choose to only permit <span class="spec-nt"><a href="#ExecutableDocument" data-name="ExecutableDocument">ExecutableDocument</a></span>.</p> <p data-source="spec/Section%202%20--%20Language.md#L264-L267">Documents which do not contain <span class="spec-nt"><a href="#OperationDefinition" data-name="OperationDefinition">OperationDefinition</a></span> or do contain <span class="spec-nt"><a href="#TypeSystemDefinitionOrExtension" data-name="TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></span> may still be parsed and validated to allow client tools to represent many GraphQL uses which may appear across many individual files.</p> <p data-source="spec/Section%202%20--%20Language.md#L269-L275">If a Document contains only one operation, that operation may be unnamed. If that operation is a query without variables or directives then it may also be represented in the shorthand form, omitting both the <span class="spec-t">query</span> keyword as well as the operation name. Otherwise, if a GraphQL Document contains multiple operations, each operation must be named. When submitting a Document with multiple operations to a GraphQL service, the name of the desired operation to be executed must also be provided.</p> </section> <section id="sec-Language.Operations" secid="2.3"> <h2 data-source="spec/Section%202%20--%20Language.md#L278"><span class="spec-secid" title="link to this section"><a href="#sec-Language.Operations">2.3</a></span>Operations</h2> <div class="spec-production" id="OperationDefinition" data-source="spec/Section%202%20--%20Language.md#L280-L282"> <span class="spec-nt"><a href="#OperationDefinition" data-name="OperationDefinition">OperationDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#OperationType" data-name="OperationType">OperationType</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#VariableDefinitions" data-name="VariableDefinitions">VariableDefinitions</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span></div> </div> <div class="spec-production" id="OperationType" data-source="spec/Section%202%20--%20Language.md#L284"> <span class="spec-nt"><a href="#OperationType" data-name="OperationType">OperationType</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">query</span></td><td class="spec-rhs"><span class="spec-t">mutation</span></td><td class="spec-rhs"><span class="spec-t">subscription</span></td></tr> </table></div></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L286">There are three types of operations that GraphQL models:</p> <ul> <li data-source="spec/Section%202%20--%20Language.md#L288">query – a read-only fetch.</li> <li data-source="spec/Section%202%20--%20Language.md#L289">mutation – a write followed by a fetch.</li> <li data-source="spec/Section%202%20--%20Language.md#L290-L291">subscription – a long-lived request that fetches data in response to source events.</li> </ul> <p data-source="spec/Section%202%20--%20Language.md#L293">Each operation is represented by an optional operation name and a selection set.</p> <p data-source="spec/Section%202%20--%20Language.md#L295-L296">For example, this mutation operation might “like” a story and then retrieve the new number of likes:</p> <pre id="example-ed6a8" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L298-L306"><a href="#example-ed6a8">Example № 5</a><code><span class="token keyword">mutation</span> <span class="token punctuation">{</span> <span class="token property-query">likeStory</span><span class="token punctuation">(</span><span class="token attr-name">storyID</span><span class="token punctuation">:</span> <span class="token number">12345</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">story</span> <span class="token punctuation">{</span> <span class="token property">likeCount</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <section id="sec-Language.Operations.Query-shorthand" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L308"><a href="#sec-Language.Operations.Query-shorthand" title="link to this subsection">Query shorthand</a></h6> <p data-source="spec/Section%202%20--%20Language.md#L310-L313">If a document contains only one operation and that operation is a query which defines no variables and contains no directives then that operation may be represented in a short-hand form which omits the <span class="spec-t">query</span> keyword and operation name.</p> <p data-source="spec/Section%202%20--%20Language.md#L315">For example, this unnamed query operation is written via query shorthand.</p> <pre id="example-63b18" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L317-L321"><a href="#example-63b18">Example № 6</a><code><span class="token punctuation">{</span> <span class="token property">field</span> <span class="token punctuation">}</span> </code></pre> <div id="note-5e20f" class="spec-note" data-source="spec/Section%202%20--%20Language.md#L323"> <a href="#note-5e20f">Note</a> many examples below will use the query short-hand syntax.</div> </section> </section> <section id="sec-Selection-Sets" secid="2.4"> <h2 data-source="spec/Section%202%20--%20Language.md#L326"><span class="spec-secid" title="link to this section"><a href="#sec-Selection-Sets">2.4</a></span>Selection Sets</h2> <div class="spec-production" id="SelectionSet" data-source="spec/Section%202%20--%20Language.md#L328"> <span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#Selection" data-name="Selection">Selection</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <div class="spec-production" id="Selection" data-source="spec/Section%202%20--%20Language.md#L330-L333"> <span class="spec-nt"><a href="#Selection" data-name="Selection">Selection</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Field" data-name="Field">Field</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#FragmentSpread" data-name="FragmentSpread">FragmentSpread</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#InlineFragment" data-name="InlineFragment">InlineFragment</a></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L335-L337">An operation selects the set of information it needs, and will receive exactly that information and nothing more, avoiding over-fetching and under-fetching data.</p> <pre id="example-21649" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L339-L345"><a href="#example-21649">Example № 7</a><code><span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">firstName</span> <span class="token property">lastName</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L347-L348">In this query operation, the <code>id</code>, <code>firstName</code>, and <code>lastName</code> fields form a selection set. Selection sets may also contain fragment references.</p> </section> <section id="sec-Language.Fields" secid="2.5"> <h2 data-source="spec/Section%202%20--%20Language.md#L351"><span class="spec-secid" title="link to this section"><a href="#sec-Language.Fields">2.5</a></span>Fields</h2> <div class="spec-production" id="Field" data-source="spec/Section%202%20--%20Language.md#L353"> <span class="spec-nt"><a href="#Field" data-name="Field">Field</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Alias" data-name="Alias">Alias</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Arguments" data-name="Arguments">Arguments</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L355-L356">A selection set is primarily composed of fields. A field describes one discrete piece of information available to request within a selection set.</p> <p data-source="spec/Section%202%20--%20Language.md#L358-L362">Some fields describe complex data or relationships to other data. In order to further explore this data, a field may itself contain a selection set, allowing for deeply nested requests. All GraphQL operations must specify their selections down to fields which return scalar values to ensure an unambiguously shaped response.</p> <p data-source="spec/Section%202%20--%20Language.md#L364-L365">For example, this operation selects fields of complex data and relationships down to scalar values.</p> <pre id="example-100a3" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L367-L382"><a href="#example-100a3">Example № 8</a><code><span class="token punctuation">{</span> <span class="token object">me</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">firstName</span> <span class="token property">lastName</span> <span class="token object">birthday</span> <span class="token punctuation">{</span> <span class="token property">month</span> <span class="token property">day</span> <span class="token punctuation">}</span> <span class="token object">friends</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L384-L388">Fields in the top-level selection set of an operation often represent some information that is globally accessible to your application and its current viewer. Some typical examples of these top fields include references to a current logged-in viewer, or accessing certain types of data referenced by a unique identifier.</p> <pre id="example-e1984" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L390-L405"><a href="#example-e1984">Example № 9</a><code><span class="token comment"># `me` could represent the currently logged in viewer.</span> <span class="token punctuation">{</span> <span class="token object">me</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token comment"># `user` represents one of many users in a graph of data, referred to by a</span> <span class="token comment"># unique identifier.</span> <span class="token punctuation">{</span> <span class="token property-query">user</span><span class="token punctuation">(</span><span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-Language.Arguments" secid="2.6"> <h2 data-source="spec/Section%202%20--%20Language.md#L408"><span class="spec-secid" title="link to this section"><a href="#sec-Language.Arguments">2.6</a></span>Arguments</h2> <div class="spec-production" id="Arguments" data-source="spec/Section%202%20--%20Language.md#L410"> <span class="spec-nt"><a href="#Arguments" data-name="Arguments">Arguments</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-t">(</span><span class="spec-quantified"><span class="spec-nt"><a href="#Argument" data-name="Argument">Argument</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">)</span></div> </div> <div class="spec-production" id="Argument" data-source="spec/Section%202%20--%20Language.md#L412"> <span class="spec-nt"><a href="#Argument" data-name="Argument">Argument</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Value" data-name="Value">Value</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L414-L416">Fields are conceptually functions which return values, and occasionally accept arguments which alter their behavior. These arguments often map directly to function arguments within a GraphQL service’s implementation.</p> <p data-source="spec/Section%202%20--%20Language.md#L418-L419">In this example, we want to query a specific user (requested via the <code>id</code> argument) and their profile picture of a specific <code>size</code>:</p> <pre id="example-1a865" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L421-L429"><a href="#example-1a865">Example № 10</a><code><span class="token punctuation">{</span> <span class="token property-query">user</span><span class="token punctuation">(</span><span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">name</span> <span class="token property-query">profilePic</span><span class="token punctuation">(</span><span class="token attr-name">size</span><span class="token punctuation">:</span> <span class="token number">100</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L431">Many arguments can exist for a given field:</p> <pre id="example-34b2d" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L433-L441"><a href="#example-34b2d">Example № 11</a><code><span class="token punctuation">{</span> <span class="token property-query">user</span><span class="token punctuation">(</span><span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">name</span> <span class="token property-query">profilePic</span><span class="token punctuation">(</span><span class="token attr-name">width</span><span class="token punctuation">:</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token attr-name">height</span><span class="token punctuation">:</span> <span class="token number">50</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <section id="sec-Language.Arguments.Arguments-are-unordered" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L443"><a href="#sec-Language.Arguments.Arguments-are-unordered" title="link to this subsection">Arguments are unordered</a></h6> <p data-source="spec/Section%202%20--%20Language.md#L445-L446">Arguments may be provided in any syntactic order and maintain identical semantic meaning.</p> <p data-source="spec/Section%202%20--%20Language.md#L448">These two operations are semantically identical:</p> <pre id="example-7eba7" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L450-L454"><a href="#example-7eba7">Example № 12</a><code><span class="token punctuation">{</span> <span class="token property-query">picture</span><span class="token punctuation">(</span><span class="token attr-name">width</span><span class="token punctuation">:</span> <span class="token number">200</span><span class="token punctuation">,</span> <span class="token attr-name">height</span><span class="token punctuation">:</span> <span class="token number">100</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <pre id="example-c93a3" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L456-L460"><a href="#example-c93a3">Example № 13</a><code><span class="token punctuation">{</span> <span class="token property-query">picture</span><span class="token punctuation">(</span><span class="token attr-name">height</span><span class="token punctuation">:</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token attr-name">width</span><span class="token punctuation">:</span> <span class="token number">200</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Field-Alias" secid="2.7"> <h2 data-source="spec/Section%202%20--%20Language.md#L463"><span class="spec-secid" title="link to this section"><a href="#sec-Field-Alias">2.7</a></span>Field Alias</h2> <div class="spec-production" id="Alias" data-source="spec/Section%202%20--%20Language.md#L465"> <span class="spec-nt"><a href="#Alias" data-name="Alias">Alias</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-t">:</span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L467-L468">By default a field’s response key in the response object will use that field’s name. However, you can define a different response key by specifying an alias.</p> <p data-source="spec/Section%202%20--%20Language.md#L470-L471">In this example, we can fetch two profile pictures of different sizes and ensure the resulting response object will not have duplicate keys:</p> <pre id="example-34435" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L473-L482"><a href="#example-34435">Example № 14</a><code><span class="token punctuation">{</span> <span class="token property-query">user</span><span class="token punctuation">(</span><span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">name</span> <span class="token attr-name">smallPic</span><span class="token punctuation">:</span> <span class="token property-query">profilePic</span><span class="token punctuation">(</span><span class="token attr-name">size</span><span class="token punctuation">:</span> <span class="token number">64</span><span class="token punctuation">)</span> <span class="token attr-name">bigPic</span><span class="token punctuation">:</span> <span class="token property-query">profilePic</span><span class="token punctuation">(</span><span class="token attr-name">size</span><span class="token punctuation">:</span> <span class="token number">1024</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L484">which returns the result:</p> <pre id="example-6e98a" class="spec-example" data-language="json" data-source="spec/Section%202%20--%20Language.md#L486-L495"><a href="#example-6e98a">Example № 15</a><code><span class="token punctuation">{</span> <span class="token property">"user"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"id"</span><span class="token operator">:</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Mark Zuckerberg"</span><span class="token punctuation">,</span> <span class="token property">"smallPic"</span><span class="token operator">:</span> <span class="token string">"https://cdn.site.io/pic-4-64.jpg"</span><span class="token punctuation">,</span> <span class="token property">"bigPic"</span><span class="token operator">:</span> <span class="token string">"https://cdn.site.io/pic-4-1024.jpg"</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L497">The fields at the top level of an operation can also be given an alias:</p> <pre id="example-27d2f" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L499-L506"><a href="#example-27d2f">Example № 16</a><code><span class="token punctuation">{</span> <span class="token attr-name">zuck</span><span class="token punctuation">:</span> <span class="token property-query">user</span><span class="token punctuation">(</span><span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L508">which returns the result:</p> <pre id="example-768a2" class="spec-example" data-language="json" data-source="spec/Section%202%20--%20Language.md#L510-L517"><a href="#example-768a2">Example № 17</a><code><span class="token punctuation">{</span> <span class="token property">"zuck"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"id"</span><span class="token operator">:</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Mark Zuckerberg"</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-Language.Fragments" secid="2.8"> <h2 data-source="spec/Section%202%20--%20Language.md#L520"><span class="spec-secid" title="link to this section"><a href="#sec-Language.Fragments">2.8</a></span>Fragments</h2> <div class="spec-production" id="FragmentSpread" data-source="spec/Section%202%20--%20Language.md#L522"> <span class="spec-nt"><a href="#FragmentSpread" data-name="FragmentSpread">FragmentSpread</a></span><div class="spec-rhs"><span class="spec-t">...</span><span class="spec-nt"><a href="#FragmentName" data-name="FragmentName">FragmentName</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="FragmentDefinition" data-source="spec/Section%202%20--%20Language.md#L524"> <span class="spec-nt"><a href="#FragmentDefinition" data-name="FragmentDefinition">FragmentDefinition</a></span><div class="spec-rhs"><span class="spec-t">fragment</span><span class="spec-nt"><a href="#FragmentName" data-name="FragmentName">FragmentName</a></span><span class="spec-nt"><a href="#TypeCondition" data-name="TypeCondition">TypeCondition</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span></div> </div> <div class="spec-production" id="FragmentName" data-source="spec/Section%202%20--%20Language.md#L526"> <span class="spec-nt"><a href="#FragmentName" data-name="FragmentName">FragmentName</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-butnot"><span class="spec-t">on</span></span></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L528">Fragments are the primary unit of composition in GraphQL.</p> <p data-source="spec/Section%202%20--%20Language.md#L530-L533">Fragments allow for the reuse of common repeated selections of fields, reducing duplicated text in the document. Inline Fragments can be used directly within a selection to condition upon a type condition when querying against an interface or union.</p> <p data-source="spec/Section%202%20--%20Language.md#L535-L536">For example, if we wanted to fetch some common information about mutual friends as well as friends of some user:</p> <pre id="example-bcf38" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L538-L553"><a href="#example-bcf38">Example № 18</a><code><span class="token keyword">query</span> <span class="token definition-query function">noFragments</span> <span class="token punctuation">{</span> <span class="token property-query">user</span><span class="token punctuation">(</span><span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property-query">friends</span><span class="token punctuation">(</span><span class="token attr-name">first</span><span class="token punctuation">:</span> <span class="token number">10</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">name</span> <span class="token property-query">profilePic</span><span class="token punctuation">(</span><span class="token attr-name">size</span><span class="token punctuation">:</span> <span class="token number">50</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token property-query">mutualFriends</span><span class="token punctuation">(</span><span class="token attr-name">first</span><span class="token punctuation">:</span> <span class="token number">10</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">name</span> <span class="token property-query">profilePic</span><span class="token punctuation">(</span><span class="token attr-name">size</span><span class="token punctuation">:</span> <span class="token number">50</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L555-L556">The repeated fields could be extracted into a fragment and composed by a parent fragment or operation.</p> <pre id="example-72b4e" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L558-L575"><a href="#example-72b4e">Example № 19</a><code><span class="token keyword">query</span> <span class="token definition-query function">withFragments</span> <span class="token punctuation">{</span> <span class="token property-query">user</span><span class="token punctuation">(</span><span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property-query">friends</span><span class="token punctuation">(</span><span class="token attr-name">first</span><span class="token punctuation">:</span> <span class="token number">10</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">friendFields</span> <span class="token punctuation">}</span> <span class="token property-query">mutualFriends</span><span class="token punctuation">(</span><span class="token attr-name">first</span><span class="token punctuation">:</span> <span class="token number">10</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">friendFields</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">friendFields</span> <span class="token keyword">on</span> <span class="token class-name">User</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">name</span> <span class="token property-query">profilePic</span><span class="token punctuation">(</span><span class="token attr-name">size</span><span class="token punctuation">:</span> <span class="token number">50</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L577-L580">Fragments are consumed by using the spread operator (<code>...</code>). All fields selected by the fragment will be added to the field selection at the same level as the fragment invocation. This happens through multiple levels of fragment spreads.</p> <p data-source="spec/Section%202%20--%20Language.md#L582">For example:</p> <pre id="example-fb6c3" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L584-L605"><a href="#example-fb6c3">Example № 20</a><code><span class="token keyword">query</span> <span class="token definition-query function">withNestedFragments</span> <span class="token punctuation">{</span> <span class="token property-query">user</span><span class="token punctuation">(</span><span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property-query">friends</span><span class="token punctuation">(</span><span class="token attr-name">first</span><span class="token punctuation">:</span> <span class="token number">10</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">friendFields</span> <span class="token punctuation">}</span> <span class="token property-query">mutualFriends</span><span class="token punctuation">(</span><span class="token attr-name">first</span><span class="token punctuation">:</span> <span class="token number">10</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">friendFields</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">friendFields</span> <span class="token keyword">on</span> <span class="token class-name">User</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">name</span> <span class="token operator">...</span><span class="token fragment function">standardProfilePic</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">standardProfilePic</span> <span class="token keyword">on</span> <span class="token class-name">User</span> <span class="token punctuation">{</span> <span class="token property-query">profilePic</span><span class="token punctuation">(</span><span class="token attr-name">size</span><span class="token punctuation">:</span> <span class="token number">50</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L607-L608">The operations <code>noFragments</code>, <code>withFragments</code>, and <code>withNestedFragments</code> all produce the same response object.</p> <section id="sec-Type-Conditions" secid="2.8.1"> <h3 data-source="spec/Section%202%20--%20Language.md#L611"><span class="spec-secid" title="link to this section"><a href="#sec-Type-Conditions">2.8.1</a></span>Type Conditions</h3> <div class="spec-production" id="TypeCondition" data-source="spec/Section%202%20--%20Language.md#L613"> <span class="spec-nt"><a href="#TypeCondition" data-name="TypeCondition">TypeCondition</a></span><div class="spec-rhs"><span class="spec-t">on</span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L615-L616">Fragments must specify the type they apply to. In this example, <code>friendFields</code> can be used in the context of querying a <code>User</code>.</p> <p data-source="spec/Section%202%20--%20Language.md#L618-L619">Fragments cannot be specified on any input value (scalar, enumeration, or input object).</p> <p data-source="spec/Section%202%20--%20Language.md#L621">Fragments can be specified on object types, interfaces, and unions.</p> <p data-source="spec/Section%202%20--%20Language.md#L623-L624">Selections within fragments only return values when the concrete type of the object it is operating on matches the type of the fragment.</p> <p data-source="spec/Section%202%20--%20Language.md#L626">For example in this operation using the Facebook data model:</p> <pre id="example-80138" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L628-L648"><a href="#example-80138">Example № 21</a><code><span class="token keyword">query</span> <span class="token definition-query function">FragmentTyping</span> <span class="token punctuation">{</span> <span class="token property-query">profiles</span><span class="token punctuation">(</span><span class="token attr-name">handles</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"zuck"</span><span class="token punctuation">,</span> <span class="token string">"coca-cola"</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">handle</span> <span class="token operator">...</span><span class="token fragment function">userFragment</span> <span class="token operator">...</span><span class="token fragment function">pageFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">userFragment</span> <span class="token keyword">on</span> <span class="token class-name">User</span> <span class="token punctuation">{</span> <span class="token object">friends</span> <span class="token punctuation">{</span> <span class="token property">count</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">pageFragment</span> <span class="token keyword">on</span> <span class="token class-name">Page</span> <span class="token punctuation">{</span> <span class="token object">likers</span> <span class="token punctuation">{</span> <span class="token property">count</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L650-L653">The <code>profiles</code> root field returns a list where each element could be a <code>Page</code> or a <code>User</code>. When the object in the <code>profiles</code> result is a <code>User</code>, <code>friends</code> will be present and <code>likers</code> will not. Conversely when the result is a <code>Page</code>, <code>likers</code> will be present and <code>friends</code> will not.</p> <pre id="example-883a1" class="spec-example" data-language="json" data-source="spec/Section%202%20--%20Language.md#L655-L668"><a href="#example-883a1">Example № 22</a><code><span class="token punctuation">{</span> <span class="token property">"profiles"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"handle"</span><span class="token operator">:</span> <span class="token string">"zuck"</span><span class="token punctuation">,</span> <span class="token property">"friends"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"count"</span><span class="token operator">:</span> <span class="token number">1234</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token property">"handle"</span><span class="token operator">:</span> <span class="token string">"coca-cola"</span><span class="token punctuation">,</span> <span class="token property">"likers"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"count"</span><span class="token operator">:</span> <span class="token number">90234512</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-Inline-Fragments" secid="2.8.2"> <h3 data-source="spec/Section%202%20--%20Language.md#L671"><span class="spec-secid" title="link to this section"><a href="#sec-Inline-Fragments">2.8.2</a></span>Inline Fragments</h3> <div class="spec-production" id="InlineFragment" data-source="spec/Section%202%20--%20Language.md#L673"> <span class="spec-nt"><a href="#InlineFragment" data-name="InlineFragment">InlineFragment</a></span><div class="spec-rhs"><span class="spec-t">...</span><span class="spec-quantified"><span class="spec-nt"><a href="#TypeCondition" data-name="TypeCondition">TypeCondition</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L675-L678">Fragments can be defined inline within a selection set. This is done to conditionally include fields based on their runtime type. This feature of standard fragment inclusion was demonstrated in the <code>query FragmentTyping</code> example. We could accomplish the same thing using inline fragments.</p> <pre id="example-10b94" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L680-L696"><a href="#example-10b94">Example № 23</a><code><span class="token keyword">query</span> <span class="token definition-query function">inlineFragmentTyping</span> <span class="token punctuation">{</span> <span class="token property-query">profiles</span><span class="token punctuation">(</span><span class="token attr-name">handles</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"zuck"</span><span class="token punctuation">,</span> <span class="token string">"coca-cola"</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">handle</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">User</span> <span class="token punctuation">{</span> <span class="token object">friends</span> <span class="token punctuation">{</span> <span class="token property">count</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Page</span> <span class="token punctuation">{</span> <span class="token object">likers</span> <span class="token punctuation">{</span> <span class="token property">count</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L698-L700">Inline fragments may also be used to apply a directive to a group of fields. If the TypeCondition is omitted, an inline fragment is considered to be of the same type as the enclosing context.</p> <pre id="example-77377" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L702-L714"><a href="#example-77377">Example № 24</a><code><span class="token keyword">query</span> <span class="token definition-query function">inlineFragmentNoType</span><span class="token punctuation">(</span><span class="token variable">$expandedInfo</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property-query">user</span><span class="token punctuation">(</span><span class="token attr-name">handle</span><span class="token punctuation">:</span> <span class="token string">"zuck"</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">name</span> <span class="token operator">...</span> <span class="token directive function">@include</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token variable">$expandedInfo</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">firstName</span> <span class="token property">lastName</span> <span class="token property">birthday</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Input-Values" secid="2.9"> <h2 data-source="spec/Section%202%20--%20Language.md#L717"><span class="spec-secid" title="link to this section"><a href="#sec-Input-Values">2.9</a></span>Input Values</h2> <div class="spec-production" id="Value" data-source="spec/Section%202%20--%20Language.md#L719-L728"> <span class="spec-nt"><a href="#Value" data-name="Value">Value</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-condition not">Const</span><span class="spec-nt"><a href="#Variable" data-name="Variable">Variable</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#BooleanValue" data-name="BooleanValue">BooleanValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#NullValue" data-name="NullValue">NullValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#EnumValue" data-name="EnumValue">EnumValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ListValue" data-name="ListValue">ListValue</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ObjectValue" data-name="ObjectValue">ObjectValue</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L730-L731">Field and directive arguments accept input values of various literal primitives; input values can be scalars, enumeration values, lists, or input objects.</p> <p data-source="spec/Section%202%20--%20Language.md#L733-L734">If not defined as constant (for example, in <span class="spec-nt"><a href="#DefaultValue" data-name="DefaultValue">DefaultValue</a></span>), input values can be specified as a variable. List and inputs objects may also contain variables (unless defined to be constant).</p> <section id="sec-Int-Value" secid="2.9.1"> <h3 data-source="spec/Section%202%20--%20Language.md#L737"><span class="spec-secid" title="link to this section"><a href="#sec-Int-Value">2.9.1</a></span>Int Value</h3> <div class="spec-production d2" id="IntValue" data-source="spec/Section%202%20--%20Language.md#L739"> <span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#IntegerPart" data-name="IntegerPart">IntegerPart</a></span><span class="spec-lookahead set not"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-t">.</span><span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span></span></div> </div> <div class="spec-production d2" id="IntegerPart" data-source="spec/Section%202%20--%20Language.md#L741-L743"> <span class="spec-nt"><a href="#IntegerPart" data-name="IntegerPart">IntegerPart</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#NegativeSign" data-name="NegativeSign">NegativeSign</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">0</span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#NegativeSign" data-name="NegativeSign">NegativeSign</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#NonZeroDigit" data-name="NonZeroDigit">NonZeroDigit</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production d2" id="NegativeSign" data-source="spec/Section%202%20--%20Language.md#L745"> <span class="spec-nt"><a href="#NegativeSign" data-name="NegativeSign">NegativeSign</a></span><div class="spec-rhs"><span class="spec-t">-</span></div> </div> <div class="spec-production d2" id="NonZeroDigit" data-source="spec/Section%202%20--%20Language.md#L747"> <span class="spec-nt"><a href="#NonZeroDigit" data-name="NonZeroDigit">NonZeroDigit</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-butnot"><span class="spec-t">0</span></span></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L749-L750">An <span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span> is specified without a decimal point or exponent but may be negative (ex. <span class="spec-t">-123</span>). It must not have any leading <span class="spec-t">0</span>.</p> <p data-source="spec/Section%202%20--%20Language.md#L752-L756">An <span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span> must not be followed by a <span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span>. In other words, an <span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span> token is always the longest possible valid sequence. The source characters <span class="spec-t">12</span> cannot be interpreted as two tokens since <span class="spec-t">1</span> is followed by the <span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span> <span class="spec-t">2</span>. This also means the source <span class="spec-t">00</span> is invalid since it can neither be interpreted as a single token nor two <span class="spec-t">0</span> tokens.</p> <p data-source="spec/Section%202%20--%20Language.md#L758-L761">An <span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span> must not be followed by a <span class="spec-t">.</span> or <span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span>. If either <span class="spec-t">.</span> or <span class="spec-nt"><a href="#ExponentIndicator" data-name="ExponentIndicator">ExponentIndicator</a></span> follows then the token must only be interpreted as a possible <span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span>. No other <span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span> character can follow. For example the sequences <code>0x123</code> and <code>123L</code> have no valid lexical representations.</p> </section> <section id="sec-Float-Value" secid="2.9.2"> <h3 data-source="spec/Section%202%20--%20Language.md#L764"><span class="spec-secid" title="link to this section"><a href="#sec-Float-Value">2.9.2</a></span>Float Value</h3> <div class="spec-production d2" id="FloatValue" data-source="spec/Section%202%20--%20Language.md#L766-L769"> <span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#IntegerPart" data-name="IntegerPart">IntegerPart</a></span><span class="spec-nt"><a href="#FractionalPart" data-name="FractionalPart">FractionalPart</a></span><span class="spec-nt"><a href="#ExponentPart" data-name="ExponentPart">ExponentPart</a></span><span class="spec-lookahead set not"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-t">.</span><span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#IntegerPart" data-name="IntegerPart">IntegerPart</a></span><span class="spec-nt"><a href="#FractionalPart" data-name="FractionalPart">FractionalPart</a></span><span class="spec-lookahead set not"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-t">.</span><span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#IntegerPart" data-name="IntegerPart">IntegerPart</a></span><span class="spec-nt"><a href="#ExponentPart" data-name="ExponentPart">ExponentPart</a></span><span class="spec-lookahead set not"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-t">.</span><span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span></span></div> </div> <div class="spec-production d2" id="FractionalPart" data-source="spec/Section%202%20--%20Language.md#L771"> <span class="spec-nt"><a href="#FractionalPart" data-name="FractionalPart">FractionalPart</a></span><div class="spec-rhs"><span class="spec-t">.</span><span class="spec-quantified"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production d2" id="ExponentPart" data-source="spec/Section%202%20--%20Language.md#L773"> <span class="spec-nt"><a href="#ExponentPart" data-name="ExponentPart">ExponentPart</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ExponentIndicator" data-name="ExponentIndicator">ExponentIndicator</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Sign" data-name="Sign">Sign</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production d2" id="ExponentIndicator" data-source="spec/Section%202%20--%20Language.md#L775"> <span class="spec-nt"><a href="#ExponentIndicator" data-name="ExponentIndicator">ExponentIndicator</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">e</span></td><td class="spec-rhs"><span class="spec-t">E</span></td></tr> </table></div></div> </div> <div class="spec-production d2" id="Sign" data-source="spec/Section%202%20--%20Language.md#L777"> <span class="spec-nt"><a href="#Sign" data-name="Sign">Sign</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">+</span></td><td class="spec-rhs"><span class="spec-t">-</span></td></tr> </table></div></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L779-L781">A <span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span> includes either a decimal point (ex. <span class="spec-t">1.0</span>) or an exponent (ex. <span class="spec-t">1e50</span>) or both (ex. <span class="spec-t">6.0221413e23</span>) and may be negative. Like <span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span>, it also must not have any leading <span class="spec-t">0</span>.</p> <p data-source="spec/Section%202%20--%20Language.md#L783-L786">A <span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span> must not be followed by a <span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span>. In other words, a <span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span> token is always the longest possible valid sequence. The source characters <span class="spec-t">1.23</span> cannot be interpreted as two tokens since <span class="spec-t">1.2</span> is followed by the <span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span> <span class="spec-t">3</span>.</p> <p data-source="spec/Section%202%20--%20Language.md#L788-L789">A <span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span> must not be followed by a <span class="spec-t">.</span>. For example, the sequence <span class="spec-t">1.23.4</span> cannot be interpreted as two tokens (<span class="spec-t">1.2</span>, <span class="spec-t">3.4</span>).</p> <p data-source="spec/Section%202%20--%20Language.md#L791-L792">A <span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span> must not be followed by a <span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span>. For example the sequence <code>0x1.2p3</code> has no valid lexical representation.</p> <div id="note-dea61" class="spec-note" data-source="spec/Section%202%20--%20Language.md#L794-L796"> <a href="#note-dea61">Note</a> The numeric literals <span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span> and <span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span> both restrict being immediately followed by a letter (or other <span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span>) to reduce confusion or unexpected behavior since GraphQL only supports decimal numbers.</div> </section> <section id="sec-Boolean-Value" secid="2.9.3"> <h3 data-source="spec/Section%202%20--%20Language.md#L799"><span class="spec-secid" title="link to this section"><a href="#sec-Boolean-Value">2.9.3</a></span>Boolean Value</h3> <div class="spec-production" id="BooleanValue" data-source="spec/Section%202%20--%20Language.md#L801"> <span class="spec-nt"><a href="#BooleanValue" data-name="BooleanValue">BooleanValue</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">true</span></td><td class="spec-rhs"><span class="spec-t">false</span></td></tr> </table></div></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L803">The two keywords <code>true</code> and <code>false</code> represent the two boolean values.</p> </section> <section id="sec-String-Value" secid="2.9.4"> <h3 data-source="spec/Section%202%20--%20Language.md#L806"><span class="spec-secid" title="link to this section"><a href="#sec-String-Value">2.9.4</a></span>String Value</h3> <div class="spec-production d2" id="StringValue" data-source="spec/Section%202%20--%20Language.md#L808-L811"> <span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span><div class="spec-rhs"><span class="spec-t">""</span><span class="spec-lookahead not"><span class="spec-t">"</span></span></div> <div class="spec-rhs"><span class="spec-t">"</span><span class="spec-quantified"><span class="spec-nt"><a href="#StringCharacter" data-name="StringCharacter">StringCharacter</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">"</span></div> <div class="spec-rhs"><span class="spec-t">"""</span><span class="spec-quantified"><span class="spec-nt"><a href="#BlockStringCharacter" data-name="BlockStringCharacter">BlockStringCharacter</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">"""</span></div> </div> <div class="spec-production d2" id="StringCharacter" data-source="spec/Section%202%20--%20Language.md#L813-L816"> <span class="spec-nt"><a href="#StringCharacter" data-name="StringCharacter">StringCharacter</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span><span class="spec-butnot"><span class="spec-t">"</span><span class="spec-t">\</span><span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span></span></span></div> <div class="spec-rhs"><span class="spec-t">\u</span><span class="spec-nt"><a href="#EscapedUnicode" data-name="EscapedUnicode">EscapedUnicode</a></span></div> <div class="spec-rhs"><span class="spec-t">\</span><span class="spec-nt"><a href="#EscapedCharacter" data-name="EscapedCharacter">EscapedCharacter</a></span></div> </div> <div class="spec-production d2" id="EscapedUnicode" data-source="spec/Section%202%20--%20Language.md#L818"> <span class="spec-nt"><a href="#EscapedUnicode" data-name="EscapedUnicode">EscapedUnicode</a></span><div class="spec-rhs"><span class="spec-rx">/[0-9A-Fa-f]{4}/</span></div> </div> <div class="spec-production d2" id="EscapedCharacter" data-source="spec/Section%202%20--%20Language.md#L820"> <span class="spec-nt"><a href="#EscapedCharacter" data-name="EscapedCharacter">EscapedCharacter</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">"</span></td><td class="spec-rhs"><span class="spec-t">\</span></td><td class="spec-rhs"><span class="spec-t">/</span></td><td class="spec-rhs"><span class="spec-t">b</span></td><td class="spec-rhs"><span class="spec-t">f</span></td><td class="spec-rhs"><span class="spec-t">n</span></td><td class="spec-rhs"><span class="spec-t">r</span></td><td class="spec-rhs"><span class="spec-t">t</span></td></tr> </table></div></div> </div> <div class="spec-production d2" id="BlockStringCharacter" data-source="spec/Section%202%20--%20Language.md#L822-L824"> <span class="spec-nt"><a href="#BlockStringCharacter" data-name="BlockStringCharacter">BlockStringCharacter</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span><span class="spec-butnot"><span class="spec-t">"""</span><span class="spec-t">\"""</span></span></span></div> <div class="spec-rhs"><span class="spec-t">\"""</span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L826-L828">Strings are sequences of characters wrapped in quotation marks (U+0022). (ex. <span class="spec-t">"Hello World"</span>). White space and other otherwise-ignored characters are significant within a string value.</p> <p data-source="spec/Section%202%20--%20Language.md#L830-L833">The empty string <span class="spec-t">""</span> must not be followed by another <span class="spec-t">"</span> otherwise it would be interpreted as the beginning of a block string. As an example, the source <span class="spec-t">""""""</span> can only be interpreted as a single empty block string and not three empty strings.</p> <p data-source="spec/Section%202%20--%20Language.md#L835-L838">Non-ASCII Unicode characters are allowed within single-quoted strings. Since <span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span> must not contain some ASCII control characters, escape sequences must be used to represent these characters. The <span class="spec-t">\</span>, <span class="spec-t">"</span> characters also must be escaped. All other escape sequences are optional.</p> <section id="sec-String-Value.Block-Strings" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L840"><a href="#sec-String-Value.Block-Strings" title="link to this subsection">Block Strings</a></h6> <p data-source="spec/Section%202%20--%20Language.md#L842-L845">Block strings are sequences of characters wrapped in triple-quotes (<code>"""</code>). White space, line terminators, quote, and backslash characters may all be used unescaped to enable verbatim text. Characters must all be valid <span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span>.</p> <p data-source="spec/Section%202%20--%20Language.md#L847-L849">Since block strings represent freeform text often used in indented positions, the string value semantics of a block string excludes uniform indentation and blank initial and trailing lines via <span class="spec-call"><a href="#BlockStringValue()" data-name="BlockStringValue">BlockStringValue</a>()</span>.</p> <p data-source="spec/Section%202%20--%20Language.md#L851">For example, the following operation containing a block string:</p> <pre id="example-fe73f" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L853-L863"><a href="#example-fe73f">Example № 25</a><code><span class="token keyword">mutation</span> <span class="token punctuation">{</span> <span class="token property-query">sendEmail</span><span class="token punctuation">(</span><span class="token attr-name">message</span><span class="token punctuation">:</span> <span class="token string">""" Hello, World! Yours, GraphQL. """</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L865">Is identical to the standard quoted string:</p> <pre id="example-c6521" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L867-L871"><a href="#example-c6521">Example № 26</a><code><span class="token keyword">mutation</span> <span class="token punctuation">{</span> <span class="token property-query">sendEmail</span><span class="token punctuation">(</span><span class="token attr-name">message</span><span class="token punctuation">:</span> <span class="token string">"Hello,\n World!\n\nYours,\n GraphQL."</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L873-L876">Since block string values strip leading and trailing empty lines, there is no single canonical printed block string for a given value. Because block strings typically represent freeform text, it is considered easier to read if they begin and end with an empty line.</p> <pre id="example-8e831" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L878-L883"><a href="#example-8e831">Example № 27</a><code><span class="token string">""" This starts with and ends with an empty line, which makes it easier to read. """</span> </code></pre> <pre id="example-b874e" class="spec-counter-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L885-L888"><a href="#example-b874e">Counter Example № 28</a><code><span class="token string">"""This does not start with or end with any empty lines, which makes it a little harder to read."""</span> </code></pre> <div id="note-65771" class="spec-note" data-source="spec/Section%202%20--%20Language.md#L890-L892"> <a href="#note-65771">Note</a> If non-printable ASCII characters are needed in a string value, a standard quoted string with appropriate escape sequences must be used instead of a block string.</div> </section> <section id="sec-String-Value.Semantics" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L894"><a href="#sec-String-Value.Semantics" title="link to this subsection">Semantics</a></h6> <div class="spec-semantic d2" data-source="spec/Section%202%20--%20Language.md#L896-L898"> <span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span><div class="spec-rhs"><span class="spec-t">""</span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L898">Return an empty sequence.</li> </ol> </div> <div class="spec-semantic d2" data-source="spec/Section%202%20--%20Language.md#L900-L902"> <span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span><div class="spec-rhs"><span class="spec-t">"</span><span class="spec-quantified"><span class="spec-nt"><a href="#StringCharacter" data-name="StringCharacter">StringCharacter</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">"</span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L902">Return the sequence of all <span class="spec-nt"><a href="#StringCharacter" data-name="StringCharacter">StringCharacter</a></span> code points.</li> </ol> </div> <div class="spec-semantic d2" data-source="spec/Section%202%20--%20Language.md#L904-L906"> <span class="spec-nt"><a href="#StringCharacter" data-name="StringCharacter">StringCharacter</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span><span class="spec-butnot"><span class="spec-t">"</span><span class="spec-t">\</span><span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span></span></span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L906">Return the code point <span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span>.</li> </ol> </div> <div class="spec-semantic d2" data-source="spec/Section%202%20--%20Language.md#L908-L912"> <span class="spec-nt"><a href="#StringCharacter" data-name="StringCharacter">StringCharacter</a></span><div class="spec-rhs"><span class="spec-t">\u</span><span class="spec-nt"><a href="#EscapedUnicode" data-name="EscapedUnicode">EscapedUnicode</a></span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L910-L911">Let <var data-name="value">value</var> be the 16-bit hexadecimal value represented by the sequence of hexadecimal digits within <span class="spec-nt"><a href="#EscapedUnicode" data-name="EscapedUnicode">EscapedUnicode</a></span>.</li> <li data-source="spec/Section%202%20--%20Language.md#L912">Return the code point <var data-name="value">value</var>.</li> </ol> </div> <div class="spec-semantic d2" data-source="spec/Section%202%20--%20Language.md#L914-L917"> <span class="spec-nt"><a href="#StringCharacter" data-name="StringCharacter">StringCharacter</a></span><div class="spec-rhs"><span class="spec-t">\</span><span class="spec-nt"><a href="#EscapedCharacter" data-name="EscapedCharacter">EscapedCharacter</a></span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L916-L917">Return the code point represented by <span class="spec-nt"><a href="#EscapedCharacter" data-name="EscapedCharacter">EscapedCharacter</a></span> according to the table below.</li> </ol> </div> <table> <thead> <tr data-source="spec/Section%202%20--%20Language.md#L919"> <th>Escaped Character</th> <th>Code Point</th> <th>Character Name</th> </tr> </thead> <tbody> <tr data-source="spec/Section%202%20--%20Language.md#L921"> <td><span class="spec-t">"</span></td> <td>U+0022</td> <td>double quote</td> </tr> <tr data-source="spec/Section%202%20--%20Language.md#L922"> <td><span class="spec-t">\</span></td> <td>U+005C</td> <td>reverse solidus (back slash)</td> </tr> <tr data-source="spec/Section%202%20--%20Language.md#L923"> <td><span class="spec-t">/</span></td> <td>U+002F</td> <td>solidus (forward slash)</td> </tr> <tr data-source="spec/Section%202%20--%20Language.md#L924"> <td><span class="spec-t">b</span></td> <td>U+0008</td> <td>backspace</td> </tr> <tr data-source="spec/Section%202%20--%20Language.md#L925"> <td><span class="spec-t">f</span></td> <td>U+000C</td> <td>form feed</td> </tr> <tr data-source="spec/Section%202%20--%20Language.md#L926"> <td><span class="spec-t">n</span></td> <td>U+000A</td> <td>line feed (new line)</td> </tr> <tr data-source="spec/Section%202%20--%20Language.md#L927"> <td><span class="spec-t">r</span></td> <td>U+000D</td> <td>carriage return</td> </tr> <tr data-source="spec/Section%202%20--%20Language.md#L928"> <td><span class="spec-t">t</span></td> <td>U+0009</td> <td>horizontal tab</td> </tr> </tbody> </table> <div class="spec-semantic d2" data-source="spec/Section%202%20--%20Language.md#L930-L935"> <span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span><div class="spec-rhs"><span class="spec-t">"""</span><span class="spec-quantified"><span class="spec-nt"><a href="#BlockStringCharacter" data-name="BlockStringCharacter">BlockStringCharacter</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">"""</span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L932-L934">Let <var data-name="rawValue">rawValue</var> be the Unicode character sequence of all <span class="spec-nt"><a href="#BlockStringCharacter" data-name="BlockStringCharacter">BlockStringCharacter</a></span> Unicode character values (which may be an empty sequence).</li> <li data-source="spec/Section%202%20--%20Language.md#L935">Return the result of <span class="spec-call"><a href="#BlockStringValue()" data-name="BlockStringValue">BlockStringValue</a>(<var data-name="rawValue">rawValue</var>)</span>.</li> </ol> </div> <div class="spec-semantic d2" data-source="spec/Section%202%20--%20Language.md#L937-L939"> <span class="spec-nt"><a href="#BlockStringCharacter" data-name="BlockStringCharacter">BlockStringCharacter</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span><span class="spec-butnot"><span class="spec-t">"""</span><span class="spec-t">\"""</span></span></span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L939">Return the character value of <span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span>.</li> </ol> </div> <div class="spec-semantic d2" data-source="spec/Section%202%20--%20Language.md#L941-L943"> <span class="spec-nt"><a href="#BlockStringCharacter" data-name="BlockStringCharacter">BlockStringCharacter</a></span><div class="spec-rhs"><span class="spec-t">\"""</span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L943">Return the character sequence <code>"""</code>.</li> </ol> </div> <div class="spec-algo" id="BlockStringValue()" data-source="spec/Section%202%20--%20Language.md#L945-L972"> <span class="spec-call"><a href="#BlockStringValue()" data-name="BlockStringValue">BlockStringValue</a>(<var data-name="rawValue">rawValue</var>)</span><ol> <li data-source="spec/Section%202%20--%20Language.md#L947">Let <var data-name="lines">lines</var> be the result of splitting <var data-name="rawValue">rawValue</var> by <span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span>.</li> <li data-source="spec/Section%202%20--%20Language.md#L948">Let <var data-name="commonIndent">commonIndent</var> be <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%202%20--%20Language.md#L949-L956">For each <var data-name="line">line</var> in <var data-name="lines">lines</var>:<ol> <li data-source="spec/Section%202%20--%20Language.md#L950">If <var data-name="line">line</var> is the first item in <var data-name="lines">lines</var>, continue to the next line.</li> <li data-source="spec/Section%202%20--%20Language.md#L951">Let <var data-name="length">length</var> be the number of characters in <var data-name="line">line</var>.</li> <li data-source="spec/Section%202%20--%20Language.md#L952-L953">Let <var data-name="indent">indent</var> be the number of leading consecutive <span class="spec-nt"><a href="#WhiteSpace" data-name="WhiteSpace">WhiteSpace</a></span> characters in <var data-name="line">line</var>.</li> <li data-source="spec/Section%202%20--%20Language.md#L954-L956">If <var data-name="indent">indent</var> is less than <var data-name="length">length</var>:<ol> <li data-source="spec/Section%202%20--%20Language.md#L955-L956">If <var data-name="commonIndent">commonIndent</var> is <span class="spec-keyword">null</span> or <var data-name="indent">indent</var> is less than <var data-name="commonIndent">commonIndent</var>:<ol> <li data-source="spec/Section%202%20--%20Language.md#L956">Let <var data-name="commonIndent">commonIndent</var> be <var data-name="indent">indent</var>.</li> </ol> </li> </ol> </li> </ol> </li> <li data-source="spec/Section%202%20--%20Language.md#L957-L960">If <var data-name="commonIndent">commonIndent</var> is not <span class="spec-keyword">null</span>:<ol> <li data-source="spec/Section%202%20--%20Language.md#L958-L960">For each <var data-name="line">line</var> in <var data-name="lines">lines</var>:<ol> <li data-source="spec/Section%202%20--%20Language.md#L959">If <var data-name="line">line</var> is the first item in <var data-name="lines">lines</var>, continue to the next line.</li> <li data-source="spec/Section%202%20--%20Language.md#L960">Remove <var data-name="commonIndent">commonIndent</var> characters from the beginning of <var data-name="line">line</var>.</li> </ol> </li> </ol> </li> <li data-source="spec/Section%202%20--%20Language.md#L961-L962">While the first item <var data-name="line">line</var> in <var data-name="lines">lines</var> contains only <span class="spec-nt"><a href="#WhiteSpace" data-name="WhiteSpace">WhiteSpace</a></span>:<ol> <li data-source="spec/Section%202%20--%20Language.md#L962">Remove the first item from <var data-name="lines">lines</var>.</li> </ol> </li> <li data-source="spec/Section%202%20--%20Language.md#L963-L964">While the last item <var data-name="line">line</var> in <var data-name="lines">lines</var> contains only <span class="spec-nt"><a href="#WhiteSpace" data-name="WhiteSpace">WhiteSpace</a></span>:<ol> <li data-source="spec/Section%202%20--%20Language.md#L964">Remove the last item from <var data-name="lines">lines</var>.</li> </ol> </li> <li data-source="spec/Section%202%20--%20Language.md#L965">Let <var data-name="formatted">formatted</var> be the empty character sequence.</li> <li data-source="spec/Section%202%20--%20Language.md#L966-L971">For each <var data-name="line">line</var> in <var data-name="lines">lines</var>:<ol> <li data-source="spec/Section%202%20--%20Language.md#L967-L968">If <var data-name="line">line</var> is the first item in <var data-name="lines">lines</var>:<ol> <li data-source="spec/Section%202%20--%20Language.md#L968">Append <var data-name="formatted">formatted</var> with <var data-name="line">line</var>.</li> </ol> </li> <li data-source="spec/Section%202%20--%20Language.md#L969-L971">Otherwise:<ol> <li data-source="spec/Section%202%20--%20Language.md#L970">Append <var data-name="formatted">formatted</var> with a line feed character (U+000A).</li> <li data-source="spec/Section%202%20--%20Language.md#L971">Append <var data-name="formatted">formatted</var> with <var data-name="line">line</var>.</li> </ol> </li> </ol> </li> <li data-source="spec/Section%202%20--%20Language.md#L972">Return <var data-name="formatted">formatted</var>.</li> </ol> </div> </section> </section> <section id="sec-Null-Value" secid="2.9.5"> <h3 data-source="spec/Section%202%20--%20Language.md#L975"><span class="spec-secid" title="link to this section"><a href="#sec-Null-Value">2.9.5</a></span>Null Value</h3> <div class="spec-production" id="NullValue" data-source="spec/Section%202%20--%20Language.md#L977"> <span class="spec-nt"><a href="#NullValue" data-name="NullValue">NullValue</a></span><div class="spec-rhs"><span class="spec-t">null</span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L979">Null values are represented as the keyword <span class="spec-keyword">null</span>.</p> <p data-source="spec/Section%202%20--%20Language.md#L981">GraphQL has two semantically different ways to represent the lack of a value:</p> <ul> <li data-source="spec/Section%202%20--%20Language.md#L983">Explicitly providing the literal value: <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%202%20--%20Language.md#L984">Implicitly not providing a value at all.</li> </ul> <p data-source="spec/Section%202%20--%20Language.md#L986">For example, these two field calls are similar, but are not identical:</p> <pre id="example-1c7eb" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L988-L993"><a href="#example-1c7eb">Example № 29</a><code><span class="token punctuation">{</span> <span class="token property-query">field</span><span class="token punctuation">(</span><span class="token attr-name">arg</span><span class="token punctuation">:</span> <span class="token property">null</span><span class="token punctuation">)</span> <span class="token property">field</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L995-L999">The first has explicitly provided <span class="spec-keyword">null</span> to the argument “arg”, while the second has implicitly not provided a value to the argument “arg”. These two forms may be interpreted differently. For example, a mutation representing deleting a field vs not altering a field, respectively. Neither form may be used for an input expecting a Non-Null type.</p> <div id="note-eab9b" class="spec-note" data-source="spec/Section%202%20--%20Language.md#L1001-L1003"> <a href="#note-eab9b">Note</a> The same two methods of representing the lack of a value are possible via variables by either providing the variable value as <span class="spec-keyword">null</span> or not providing a variable value at all.</div> </section> <section id="sec-Enum-Value" secid="2.9.6"> <h3 data-source="spec/Section%202%20--%20Language.md#L1006"><span class="spec-secid" title="link to this section"><a href="#sec-Enum-Value">2.9.6</a></span>Enum Value</h3> <div class="spec-production" id="EnumValue" data-source="spec/Section%202%20--%20Language.md#L1008"> <span class="spec-nt"><a href="#EnumValue" data-name="EnumValue">EnumValue</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-butnot"><span class="spec-t">true</span><span class="spec-t">false</span><span class="spec-t">null</span></span></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L1010-L1013">Enum values are represented as unquoted names (ex. <code>MOBILE_WEB</code>). It is recommended that Enum values be “all caps”. Enum values are only used in contexts where the precise enumeration type is known. Therefore it’s not necessary to supply an enumeration type name in the literal.</p> </section> <section id="sec-List-Value" secid="2.9.7"> <h3 data-source="spec/Section%202%20--%20Language.md#L1016"><span class="spec-secid" title="link to this section"><a href="#sec-List-Value">2.9.7</a></span>List Value</h3> <div class="spec-production" id="ListValue" data-source="spec/Section%202%20--%20Language.md#L1018-L1020"> <span class="spec-nt"><a href="#ListValue" data-name="ListValue">ListValue</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-t">[</span><span class="spec-t">]</span></div> <div class="spec-rhs"><span class="spec-t">[</span><span class="spec-quantified"><span class="spec-nt"><a href="#Value" data-name="Value">Value</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">]</span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L1022-L1023">Lists are ordered sequences of values wrapped in square-brackets <code>[ ]</code>. The values of a List literal may be any value literal or variable (ex. <code>[1, 2, 3]</code>).</p> <p data-source="spec/Section%202%20--%20Language.md#L1025-L1026">Commas are optional throughout GraphQL so trailing commas are allowed and repeated commas do not represent missing values.</p> <section id="sec-List-Value.Semantics" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L1028"><a href="#sec-List-Value.Semantics" title="link to this subsection">Semantics</a></h6> <div class="spec-semantic" data-source="spec/Section%202%20--%20Language.md#L1030-L1032"> <span class="spec-nt"><a href="#ListValue" data-name="ListValue">ListValue</a></span><div class="spec-rhs"><span class="spec-t">[</span><span class="spec-t">]</span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L1032">Return a new empty list value.</li> </ol> </div> <div class="spec-semantic" data-source="spec/Section%202%20--%20Language.md#L1034-L1040"> <span class="spec-nt"><a href="#ListValue" data-name="ListValue">ListValue</a></span><div class="spec-rhs"><span class="spec-t">[</span><span class="spec-quantified"><span class="spec-nt"><a href="#Value" data-name="Value">Value</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">]</span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L1036">Let <var data-name="inputList">inputList</var> be a new empty list value.</li> <li data-source="spec/Section%202%20--%20Language.md#L1037-L1039">For each <span class="spec-quantified"><span class="spec-nt"><a href="#Value" data-name="Value">Value</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><ol> <li data-source="spec/Section%202%20--%20Language.md#L1038">Let <var data-name="value">value</var> be the result of evaluating <span class="spec-nt"><a href="#Value" data-name="Value">Value</a></span>.</li> <li data-source="spec/Section%202%20--%20Language.md#L1039">Append <var data-name="value">value</var> to <var data-name="inputList">inputList</var>.</li> </ol> </li> <li data-source="spec/Section%202%20--%20Language.md#L1040">Return <var data-name="inputList">inputList</var></li> </ol> </div> </section> </section> <section id="sec-Input-Object-Values" secid="2.9.8"> <h3 data-source="spec/Section%202%20--%20Language.md#L1043"><span class="spec-secid" title="link to this section"><a href="#sec-Input-Object-Values">2.9.8</a></span>Input Object Values</h3> <div class="spec-production" id="ObjectValue" data-source="spec/Section%202%20--%20Language.md#L1045-L1047"> <span class="spec-nt"><a href="#ObjectValue" data-name="ObjectValue">ObjectValue</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-t">}</span></div> <div class="spec-rhs"><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#ObjectField" data-name="ObjectField">ObjectField</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <div class="spec-production" id="ObjectField" data-source="spec/Section%202%20--%20Language.md#L1049"> <span class="spec-nt"><a href="#ObjectField" data-name="ObjectField">ObjectField</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Value" data-name="Value">Value</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L1051-L1054">Input object literal values are unordered lists of keyed input values wrapped in curly-braces <code>{ }</code>. The values of an object literal may be any input value literal or variable (ex. <code>{ name: "Hello world", score: 1.0 }</code>). We refer to literal representation of input objects as “object literals.”</p> <section id="sec-Input-Object-Values.Input-object-fields-are-unordered" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L1056"><a href="#sec-Input-Object-Values.Input-object-fields-are-unordered" title="link to this subsection">Input object fields are unordered</a></h6> <p data-source="spec/Section%202%20--%20Language.md#L1058-L1059">Input object fields may be provided in any syntactic order and maintain identical semantic meaning.</p> <p data-source="spec/Section%202%20--%20Language.md#L1061">These two operations are semantically identical:</p> <pre id="example-09646" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L1063-L1067"><a href="#example-09646">Example № 30</a><code><span class="token punctuation">{</span> <span class="token property-query">nearestThing</span><span class="token punctuation">(</span><span class="token attr-name">location</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token attr-name">lon</span><span class="token punctuation">:</span> <span class="token number">12.43</span><span class="token punctuation">,</span> <span class="token attr-name">lat</span><span class="token punctuation">:</span> <span class="token number">-53.211</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <pre id="example-6ebee" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L1069-L1073"><a href="#example-6ebee">Example № 31</a><code><span class="token punctuation">{</span> <span class="token property-query">nearestThing</span><span class="token punctuation">(</span><span class="token attr-name">location</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token attr-name">lat</span><span class="token punctuation">:</span> <span class="token number">-53.211</span><span class="token punctuation">,</span> <span class="token attr-name">lon</span><span class="token punctuation">:</span> <span class="token number">12.43</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-Input-Object-Values.Semantics" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L1075"><a href="#sec-Input-Object-Values.Semantics" title="link to this subsection">Semantics</a></h6> <div class="spec-semantic" data-source="spec/Section%202%20--%20Language.md#L1077-L1079"> <span class="spec-nt"><a href="#ObjectValue" data-name="ObjectValue">ObjectValue</a></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-t">}</span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L1079">Return a new input object value with no fields.</li> </ol> </div> <div class="spec-semantic" data-source="spec/Section%202%20--%20Language.md#L1081-L1088"> <span class="spec-nt"><a href="#ObjectValue" data-name="ObjectValue">ObjectValue</a></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#ObjectField" data-name="ObjectField">ObjectField</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L1083">Let <var data-name="inputObject">inputObject</var> be a new input object value with no fields.</li> <li data-source="spec/Section%202%20--%20Language.md#L1084-L1087">For each <var data-name="field">field</var> in <span class="spec-quantified"><span class="spec-nt"><a href="#ObjectField" data-name="ObjectField">ObjectField</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><ol> <li data-source="spec/Section%202%20--%20Language.md#L1085">Let <var data-name="name">name</var> be <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span> in <var data-name="field">field</var>.</li> <li data-source="spec/Section%202%20--%20Language.md#L1086">Let <var data-name="value">value</var> be the result of evaluating <span class="spec-nt"><a href="#Value" data-name="Value">Value</a></span> in <var data-name="field">field</var>.</li> <li data-source="spec/Section%202%20--%20Language.md#L1087">Add a field to <var data-name="inputObject">inputObject</var> of name <var data-name="name">name</var> containing value <var data-name="value">value</var>.</li> </ol> </li> <li data-source="spec/Section%202%20--%20Language.md#L1088">Return <var data-name="inputObject">inputObject</var></li> </ol> </div> </section> </section> </section> <section id="sec-Language.Variables" secid="2.10"> <h2 data-source="spec/Section%202%20--%20Language.md#L1091"><span class="spec-secid" title="link to this section"><a href="#sec-Language.Variables">2.10</a></span>Variables</h2> <div class="spec-production" id="Variable" data-source="spec/Section%202%20--%20Language.md#L1093"> <span class="spec-nt"><a href="#Variable" data-name="Variable">Variable</a></span><div class="spec-rhs"><span class="spec-t">$</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span></div> </div> <div class="spec-production" id="VariableDefinitions" data-source="spec/Section%202%20--%20Language.md#L1095"> <span class="spec-nt"><a href="#VariableDefinitions" data-name="VariableDefinitions">VariableDefinitions</a></span><div class="spec-rhs"><span class="spec-t">(</span><span class="spec-quantified"><span class="spec-nt"><a href="#VariableDefinition" data-name="VariableDefinition">VariableDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">)</span></div> </div> <div class="spec-production" id="VariableDefinition" data-source="spec/Section%202%20--%20Language.md#L1097"> <span class="spec-nt"><a href="#VariableDefinition" data-name="VariableDefinition">VariableDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Variable" data-name="Variable">Variable</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#DefaultValue" data-name="DefaultValue">DefaultValue</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="DefaultValue" data-source="spec/Section%202%20--%20Language.md#L1099"> <span class="spec-nt"><a href="#DefaultValue" data-name="DefaultValue">DefaultValue</a></span><div class="spec-rhs"><span class="spec-t">=</span><span class="spec-nt"><a href="#Value" data-name="Value">Value</a><span class="spec-params"><span class="spec-param">Const</span></span></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L1101-L1102">A GraphQL operation can be parameterized with variables, maximizing reuse, and avoiding costly string building in clients at runtime.</p> <p data-source="spec/Section%202%20--%20Language.md#L1104-L1105">If not defined as constant (for example, in <span class="spec-nt"><a href="#DefaultValue" data-name="DefaultValue">DefaultValue</a></span>), a <span class="spec-nt"><a href="#Variable" data-name="Variable">Variable</a></span> can be supplied for an input value.</p> <p data-source="spec/Section%202%20--%20Language.md#L1107-L1110">Variables must be defined at the top of an operation and are in scope throughout the execution of that operation. Values for those variables are provided to a GraphQL service as part of a request so they may be substituted in during execution.</p> <p data-source="spec/Section%202%20--%20Language.md#L1112-L1113">In this example, we want to fetch a profile picture size based on the size of a particular device:</p> <pre id="example-7f690" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L1115-L1123"><a href="#example-7f690">Example № 32</a><code><span class="token keyword">query</span> <span class="token definition-query function">getZuckProfile</span><span class="token punctuation">(</span><span class="token variable">$devicePicSize</span><span class="token punctuation">:</span> <span class="token scalar">Int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property-query">user</span><span class="token punctuation">(</span><span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">name</span> <span class="token property-query">profilePic</span><span class="token punctuation">(</span><span class="token attr-name">size</span><span class="token punctuation">:</span> <span class="token variable">$devicePicSize</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%202%20--%20Language.md#L1125-L1126">If providing JSON for the variables’ values, we could request a <code>profilePic</code> of size <code>60</code>:</p> <pre id="example-98958" class="spec-example" data-language="json" data-source="spec/Section%202%20--%20Language.md#L1128-L1132"><a href="#example-98958">Example № 33</a><code><span class="token punctuation">{</span> <span class="token property">"devicePicSize"</span><span class="token operator">:</span> <span class="token number">60</span> <span class="token punctuation">}</span> </code></pre> <section id="sec-Language.Variables.Variable-use-within-Fragments" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L1134"><a href="#sec-Language.Variables.Variable-use-within-Fragments" title="link to this subsection">Variable use within Fragments</a></h6> <p data-source="spec/Section%202%20--%20Language.md#L1136-L1139">Variables can be used within fragments. Variables have global scope with a given operation, so a variable used within a fragment must be declared in any top-level operation that transitively consumes that fragment. If a variable is referenced in a fragment and is included by an operation that does not define that variable, that operation is invalid (see <a href="#sec-All-Variable-Uses-Defined">All Variable Uses Defined</a>).</p> </section> </section> <section id="sec-Type-References" secid="2.11"> <h2 data-source="spec/Section%202%20--%20Language.md#L1142"><span class="spec-secid" title="link to this section"><a href="#sec-Type-References">2.11</a></span>Type References</h2> <div class="spec-production" id="Type" data-source="spec/Section%202%20--%20Language.md#L1144-L1147"> <span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ListType" data-name="ListType">ListType</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#NonNullType" data-name="NonNullType">NonNullType</a></span></div> </div> <div class="spec-production" id="NamedType" data-source="spec/Section%202%20--%20Language.md#L1149"> <span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span></div> </div> <div class="spec-production" id="ListType" data-source="spec/Section%202%20--%20Language.md#L1151"> <span class="spec-nt"><a href="#ListType" data-name="ListType">ListType</a></span><div class="spec-rhs"><span class="spec-t">[</span><span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><span class="spec-t">]</span></div> </div> <div class="spec-production" id="NonNullType" data-source="spec/Section%202%20--%20Language.md#L1153-L1155"> <span class="spec-nt"><a href="#NonNullType" data-name="NonNullType">NonNullType</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span><span class="spec-t">!</span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ListType" data-name="ListType">ListType</a></span><span class="spec-t">!</span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L1157-L1159">GraphQL describes the types of data expected by arguments and variables. Input types may be lists of another input type, or a non-null variant of any other input type.</p> <section id="sec-Type-References.Semantics" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L1161"><a href="#sec-Type-References.Semantics" title="link to this subsection">Semantics</a></h6> <div class="spec-semantic" data-source="spec/Section%202%20--%20Language.md#L1163-L1168"> <span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L1165">Let <var data-name="name">name</var> be the string value of <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span></li> <li data-source="spec/Section%202%20--%20Language.md#L1166">Let <var data-name="type">type</var> be the type defined in the Schema named <var data-name="name">name</var></li> <li data-source="spec/Section%202%20--%20Language.md#L1167"><var data-name="type">type</var> must not be <span class="spec-keyword">null</span></li> <li data-source="spec/Section%202%20--%20Language.md#L1168">Return <var data-name="type">type</var></li> </ol> </div> <div class="spec-semantic" data-source="spec/Section%202%20--%20Language.md#L1170-L1174"> <span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><div class="spec-rhs"><span class="spec-t">[</span><span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><span class="spec-t">]</span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L1172">Let <var data-name="itemType">itemType</var> be the result of evaluating <span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span></li> <li data-source="spec/Section%202%20--%20Language.md#L1173">Let <var data-name="type">type</var> be a List type where <var data-name="itemType">itemType</var> is the contained type.</li> <li data-source="spec/Section%202%20--%20Language.md#L1174">Return <var data-name="type">type</var></li> </ol> </div> <div class="spec-semantic" data-source="spec/Section%202%20--%20Language.md#L1176-L1180"> <span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><span class="spec-t">!</span></div> <ol> <li data-source="spec/Section%202%20--%20Language.md#L1178">Let <var data-name="nullableType">nullableType</var> be the result of evaluating <span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span></li> <li data-source="spec/Section%202%20--%20Language.md#L1179">Let <var data-name="type">type</var> be a Non-Null type where <var data-name="nullableType">nullableType</var> is the contained type.</li> <li data-source="spec/Section%202%20--%20Language.md#L1180">Return <var data-name="type">type</var></li> </ol> </div> </section> </section> <section id="sec-Language.Directives" secid="2.12"> <h2 data-source="spec/Section%202%20--%20Language.md#L1183"><span class="spec-secid" title="link to this section"><a href="#sec-Language.Directives">2.12</a></span>Directives</h2> <div class="spec-production" id="Directives" data-source="spec/Section%202%20--%20Language.md#L1185"> <span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Directive" data-name="Directive">Directive</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production" id="Directive" data-source="spec/Section%202%20--%20Language.md#L1187"> <span class="spec-nt"><a href="#Directive" data-name="Directive">Directive</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-t">@</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Arguments" data-name="Arguments">Arguments</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <p data-source="spec/Section%202%20--%20Language.md#L1189-L1190">Directives provide a way to describe alternate runtime execution and type validation behavior in a GraphQL document.</p> <p data-source="spec/Section%202%20--%20Language.md#L1192-L1194">In some cases, you need to provide options to alter GraphQL’s execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.</p> <p data-source="spec/Section%202%20--%20Language.md#L1196-L1197">Directives have a name along with a list of arguments which may accept values of any input type.</p> <p data-source="spec/Section%202%20--%20Language.md#L1199-L1200">Directives can be used to describe additional information for types, fields, fragments and operations.</p> <p data-source="spec/Section%202%20--%20Language.md#L1202-L1204">As future versions of GraphQL adopt new configurable execution capabilities, they may be exposed via directives. GraphQL services and tools may also provide any additional <span class="spec-ref"><a href="#custom-directive" data-name="custom-directive">custom directive</a></span> beyond those described here.</p> <section id="sec-Language.Directives.Directive-order-is-significant" class="subsec"> <h6 data-source="spec/Section%202%20--%20Language.md#L1206"><a href="#sec-Language.Directives.Directive-order-is-significant" title="link to this subsection">Directive order is significant</a></h6> <p data-source="spec/Section%202%20--%20Language.md#L1208">Directives may be provided in a specific syntactic order which may have semantic interpretation.</p> <p data-source="spec/Section%202%20--%20Language.md#L1210">These two type definitions may have different semantic meaning:</p> <pre id="example-2a4f9" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L1212-L1218"><a href="#example-2a4f9">Example № 34</a><code><span class="token keyword">type</span> <span class="token class-name">Person</span> <span class="token directive function">@addExternalFields</span><span class="token punctuation">(</span><span class="token attr-name">source</span><span class="token punctuation">:</span> <span class="token string">"profiles"</span><span class="token punctuation">)</span> <span class="token directive function">@excludeField</span><span class="token punctuation">(</span><span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token string">"photo"</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> <pre id="example-c1f24" class="spec-example" data-language="graphql" data-source="spec/Section%202%20--%20Language.md#L1220-L1226"><a href="#example-c1f24">Example № 35</a><code><span class="token keyword">type</span> <span class="token class-name">Person</span> <span class="token directive function">@excludeField</span><span class="token punctuation">(</span><span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token string">"photo"</span><span class="token punctuation">)</span> <span class="token directive function">@addExternalFields</span><span class="token punctuation">(</span><span class="token attr-name">source</span><span class="token punctuation">:</span> <span class="token string">"profiles"</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> </section> </section> </section> <section id="sec-Type-System" secid="3"> <h1 data-source="spec/Section%203%20--%20Type%20System.md#L1"><span class="spec-secid" title="link to this section"><a href="#sec-Type-System">3</a></span>Type System</h1> <p data-source="spec/Section%203%20--%20Type%20System.md#L3-L6">The GraphQL Type system describes the capabilities of a GraphQL service and is used to determine if a requested operation is valid, to guarantee the type of response results, and describes the input types of variables to determine if values provided at request time are valid.</p> <div class="spec-production" id="TypeSystemDocument" data-source="spec/Section%203%20--%20Type%20System.md#L8"> <span class="spec-nt"><a href="#TypeSystemDocument" data-name="TypeSystemDocument">TypeSystemDocument</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#TypeSystemDefinition" data-name="TypeSystemDefinition">TypeSystemDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production" id="TypeSystemDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L10-L13"> <span class="spec-nt"><a href="#TypeSystemDefinition" data-name="TypeSystemDefinition">TypeSystemDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#SchemaDefinition" data-name="SchemaDefinition">SchemaDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#TypeDefinition" data-name="TypeDefinition">TypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#DirectiveDefinition" data-name="DirectiveDefinition">DirectiveDefinition</a></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L15-L18">The GraphQL language includes an <a href="https://en.wikipedia.org/wiki/Interface_description_language">IDL</a> used to describe a GraphQL service’s type system. Tools may use this definition language to provide utilities such as client code generation or service boot-strapping.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L20-L24">GraphQL tools or services which only seek to execute GraphQL requests and not construct a new GraphQL schema may choose not to allow <span class="spec-nt"><a href="#TypeSystemDefinition" data-name="TypeSystemDefinition">TypeSystemDefinition</a></span>. Tools which only seek to produce schema and not execute requests may choose to only allow <span class="spec-nt"><a href="#TypeSystemDocument" data-name="TypeSystemDocument">TypeSystemDocument</a></span> and not allow <span class="spec-nt"><a href="#ExecutableDefinition" data-name="ExecutableDefinition">ExecutableDefinition</a></span> or <span class="spec-nt"><a href="#TypeSystemExtension" data-name="TypeSystemExtension">TypeSystemExtension</a></span> but should provide a descriptive error if present.</p> <div id="note-d5e8e" class="spec-note" data-source="spec/Section%203%20--%20Type%20System.md#L26-L27"> <a href="#note-d5e8e">Note</a> The type system definition language is used throughout the remainder of this specification document when illustrating example type systems.</div> <section id="sec-Type-System-Extensions" secid="3.1"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L30"><span class="spec-secid" title="link to this section"><a href="#sec-Type-System-Extensions">3.1</a></span>Type System Extensions</h2> <div class="spec-production" id="TypeSystemExtensionDocument" data-source="spec/Section%203%20--%20Type%20System.md#L32"> <span class="spec-nt"><a href="#TypeSystemExtensionDocument" data-name="TypeSystemExtensionDocument">TypeSystemExtensionDocument</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#TypeSystemDefinitionOrExtension" data-name="TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production" id="TypeSystemDefinitionOrExtension" data-source="spec/Section%203%20--%20Type%20System.md#L34-L36"> <span class="spec-nt"><a href="#TypeSystemDefinitionOrExtension" data-name="TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#TypeSystemDefinition" data-name="TypeSystemDefinition">TypeSystemDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#TypeSystemExtension" data-name="TypeSystemExtension">TypeSystemExtension</a></span></div> </div> <div class="spec-production" id="TypeSystemExtension" data-source="spec/Section%203%20--%20Type%20System.md#L38-L40"> <span class="spec-nt"><a href="#TypeSystemExtension" data-name="TypeSystemExtension">TypeSystemExtension</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#SchemaExtension" data-name="SchemaExtension">SchemaExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#TypeExtension" data-name="TypeExtension">TypeExtension</a></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L42-L45">Type system extensions are used to represent a GraphQL type system which has been extended from some original type system. For example, this might be used by a local service to represent data a GraphQL client only accesses locally, or by a GraphQL service which is itself an extension of another GraphQL service.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L47-L49">Tools which only seek to produce and extend schema and not execute requests may choose to only allow <span class="spec-nt"><a href="#TypeSystemExtensionDocument" data-name="TypeSystemExtensionDocument">TypeSystemExtensionDocument</a></span> and not allow <span class="spec-nt"><a href="#ExecutableDefinition" data-name="ExecutableDefinition">ExecutableDefinition</a></span> but should provide a descriptive error if present.</p> </section> <section id="sec-Descriptions" secid="3.2"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L52"><span class="spec-secid" title="link to this section"><a href="#sec-Descriptions">3.2</a></span>Descriptions</h2> <div class="spec-production" id="Description" data-source="spec/Section%203%20--%20Type%20System.md#L54"> <span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L56-L59">Documentation is a first-class feature of GraphQL type systems. To ensure the documentation of a GraphQL service remains consistent with its capabilities, descriptions of GraphQL definitions are provided alongside their definitions and made available via introspection.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L61-L65">To allow GraphQL service designers to easily publish documentation alongside the capabilities of a GraphQL service, GraphQL descriptions are defined using the Markdown syntax (as specified by <a href="https://commonmark.org/">CommonMark</a>). In the type system definition language, these description strings (often <span class="spec-nt"><span data-name="BlockString">BlockString</span></span>) occur immediately before the definition they describe.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L67-L69">GraphQL schema and all other definitions (e.g. types, fields, arguments, etc.) which can be described should provide a <span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span> unless they are considered self descriptive.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L71">As an example, this simple GraphQL schema is well described:</p> <pre id="example-916f4" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L73-L113"><a href="#example-916f4">Example № 36</a><code><span class="token description string">"""<span class="token language-markdown"> A simple GraphQL schema which is well described. </span>"""</span> <span class="token keyword">schema</span> <span class="token punctuation">{</span> <span class="token attr-name">query</span><span class="token punctuation">:</span> <span class="token class-name">Query</span> <span class="token punctuation">}</span> <span class="token description string">"""<span class="token language-markdown"> Root type for all your query operations </span>"""</span> <span class="token keyword">type</span> <span class="token class-name">Query</span> <span class="token punctuation">{</span> <span class="token description string">"""<span class="token language-markdown"> Translates a string from a given language into a different language. </span>"""</span> <span class="token attr-name">translate</span><span class="token punctuation">(</span> <span class="token description string">"<span class="token language-markdown">The original language that `text` is provided in.</span>"</span> <span class="token attr-name">fromLanguage</span><span class="token punctuation">:</span> <span class="token class-name">Language</span> <span class="token description string">"<span class="token language-markdown">The translated language to be returned.</span>"</span> <span class="token attr-name">toLanguage</span><span class="token punctuation">:</span> <span class="token class-name">Language</span> <span class="token description string">"<span class="token language-markdown">The text to be translated.</span>"</span> <span class="token attr-name">text</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token description string">"""<span class="token language-markdown"> The set of languages supported by `translate`. </span>"""</span> <span class="token keyword">enum</span> <span class="token class-name">Language</span> <span class="token punctuation">{</span> <span class="token description string">"<span class="token language-markdown">English</span>"</span> <span class="token constant">EN</span> <span class="token description string">"<span class="token language-markdown">French</span>"</span> <span class="token constant">FR</span> <span class="token description string">"<span class="token language-markdown">Chinese</span>"</span> <span class="token constant">CH</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-Schema" secid="3.3"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L116"><span class="spec-secid" title="link to this section"><a href="#sec-Schema">3.3</a></span>Schema</h2> <div class="spec-production" id="SchemaDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L118"> <span class="spec-nt"><a href="#SchemaDefinition" data-name="SchemaDefinition">SchemaDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">schema</span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#RootOperationTypeDefinition" data-name="RootOperationTypeDefinition">RootOperationTypeDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <div class="spec-production" id="RootOperationTypeDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L120"> <span class="spec-nt"><a href="#RootOperationTypeDefinition" data-name="RootOperationTypeDefinition">RootOperationTypeDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#OperationType" data-name="OperationType">OperationType</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L122-L126">A GraphQL service’s collective type system capabilities are referred to as that service’s “schema”. A schema is defined in terms of the types and directives it supports as well as the root operation types for each kind of operation: query, mutation, and subscription; this determines the place in the type system where those operations begin.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L128-L129">A GraphQL schema must itself be internally valid. This section describes the rules for this validation process where relevant.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L131-L133">All types within a GraphQL schema must have unique names. No two provided types may have the same name. No provided type may have a name which conflicts with any built in types (including Scalar and Introspection types).</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L135">All directives within a GraphQL schema must have unique names.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L137-L139">All types and directives defined within a schema must not have a name which begins with <span class="spec-string">"__"</span> (two underscores), as this is used exclusively by GraphQL’s introspection system.</p> <section id="sec-Root-Operation-Types" secid="3.3.1"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L141"><span class="spec-secid" title="link to this section"><a href="#sec-Root-Operation-Types">3.3.1</a></span>Root Operation Types</h3> <p data-source="spec/Section%203%20--%20Type%20System.md#L143-L145">A schema defines the initial root operation type for each kind of operation it supports: query, mutation, and subscription; this determines the place in the type system where those operations begin.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L147">The <span class="spec-t">query</span> root operation type must be provided and must be an Object type.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L149-L151">The <span class="spec-t">mutation</span> root operation type is optional; if it is not provided, the service does not support mutations. If it is provided, it must be an Object type.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L153-L155">Similarly, the <span class="spec-t">subscription</span> root operation type is also optional; if it is not provided, the service does not support subscriptions. If it is provided, it must be an Object type.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L157-L158">The <span class="spec-t">query</span>, <span class="spec-t">mutation</span>, and <span class="spec-t">subscription</span> root types must all be different types if provided.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L160-L161">The fields on the <span class="spec-t">query</span> root operation type indicate what fields are available at the top level of a GraphQL query operation.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L163">For example, this example operation:</p> <pre id="example-081b4" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L165-L169"><a href="#example-081b4">Example № 37</a><code><span class="token keyword">query</span> <span class="token punctuation">{</span> <span class="token property">myName</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L171">is only valid when the <span class="spec-t">query</span> root operation type has a field named “myName”:</p> <pre id="example-50137" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L173-L177"><a href="#example-50137">Example № 38</a><code><span class="token keyword">type</span> <span class="token class-name">Query</span> <span class="token punctuation">{</span> <span class="token attr-name">myName</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L179-L180">Similarly, the following mutation is only valid if the <span class="spec-t">mutation</span> root operation type has a field named “setName”.</p> <pre id="example-d1ed8" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L182-L188"><a href="#example-d1ed8">Example № 39</a><code><span class="token keyword">mutation</span> <span class="token punctuation">{</span> <span class="token property-query">setName</span><span class="token punctuation">(</span><span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token string">"Zuck"</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">newName</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L190-L191">When using the type system definition language, a document must include at most one <span class="spec-t">schema</span> definition.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L193-L194">In this example, a GraphQL schema is defined with both query and mutation root operation types:</p> <pre id="example-e2969" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L196-L209"><a href="#example-e2969">Example № 40</a><code><span class="token keyword">schema</span> <span class="token punctuation">{</span> <span class="token attr-name">query</span><span class="token punctuation">:</span> <span class="token class-name">MyQueryRootType</span> <span class="token attr-name">mutation</span><span class="token punctuation">:</span> <span class="token class-name">MyMutationRootType</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">MyQueryRootType</span> <span class="token punctuation">{</span> <span class="token attr-name">someField</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">MyMutationRootType</span> <span class="token punctuation">{</span> <span class="token attr-name">setSomeField</span><span class="token punctuation">(</span><span class="token attr-name">to</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> <section id="sec-Root-Operation-Types.Default-Root-Operation-Type-Names" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L211"><a href="#sec-Root-Operation-Types.Default-Root-Operation-Type-Names" title="link to this subsection">Default Root Operation Type Names</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L213-L216">While any type can be the root operation type for a GraphQL operation, the type system definition language can omit the schema definition when the <span class="spec-t">query</span>, <span class="spec-t">mutation</span>, and <span class="spec-t">subscription</span> root types are named <span class="spec-string">"Query"</span>, <span class="spec-string">"Mutation"</span>, and <span class="spec-string">"Subscription"</span> respectively.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L218-L220">Likewise, when representing a GraphQL schema using the type system definition language, a schema definition should be omitted if it only uses the default root operation type names.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L222-L224">This example describes a valid complete GraphQL schema, despite not explicitly including a <span class="spec-t">schema</span> definition. The <span class="spec-string">"Query"</span> type is presumed to be the <span class="spec-t">query</span> root operation type of the schema.</p> <pre id="example-9d70f" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L226-L230"><a href="#example-9d70f">Example № 41</a><code><span class="token keyword">type</span> <span class="token class-name">Query</span> <span class="token punctuation">{</span> <span class="token attr-name">someField</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Schema-Extension" secid="3.3.2"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L232"><span class="spec-secid" title="link to this section"><a href="#sec-Schema-Extension">3.3.2</a></span>Schema Extension</h3> <div class="spec-production" id="SchemaExtension" data-source="spec/Section%203%20--%20Type%20System.md#L234-L236"> <span class="spec-nt"><a href="#SchemaExtension" data-name="SchemaExtension">SchemaExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">schema</span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#RootOperationTypeDefinition" data-name="RootOperationTypeDefinition">RootOperationTypeDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">schema</span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L238-L240">Schema extensions are used to represent a schema which has been extended from an original schema. For example, this might be used by a GraphQL service which adds additional operation types, or additional directives to an existing schema.</p> <div id="note-c9cd2" class="spec-note" data-source="spec/Section%203%20--%20Type%20System.md#L242-L244"> <a href="#note-c9cd2">Note</a> Schema extensions without additional operation type definitions must not be followed by a <span class="spec-t">{</span> (such as a query shorthand) to avoid parsing ambiguity. The same limitation applies to the type definitions and extensions below.</div> <section id="sec-Schema-Extension.Schema-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L246"><a href="#sec-Schema-Extension.Schema-Validation" title="link to this subsection">Schema Validation</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L248">Schema extensions have the potential to be invalid if incorrectly defined.</p> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L250">The Schema must already be defined.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L251-L252">Any non-repeatable directives provided must not already apply to the original Schema.</li> </ol> </section> </section> </section> <section id="sec-Types" secid="3.4"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L255"><span class="spec-secid" title="link to this section"><a href="#sec-Types">3.4</a></span>Types</h2> <div class="spec-production" id="TypeDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L257-L263"> <span class="spec-nt"><a href="#TypeDefinition" data-name="TypeDefinition">TypeDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ScalarTypeDefinition" data-name="ScalarTypeDefinition">ScalarTypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ObjectTypeDefinition" data-name="ObjectTypeDefinition">ObjectTypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#InterfaceTypeDefinition" data-name="InterfaceTypeDefinition">InterfaceTypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#UnionTypeDefinition" data-name="UnionTypeDefinition">UnionTypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#EnumTypeDefinition" data-name="EnumTypeDefinition">EnumTypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#InputObjectTypeDefinition" data-name="InputObjectTypeDefinition">InputObjectTypeDefinition</a></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L265-L266">The fundamental unit of any GraphQL Schema is the type. There are six kinds of named type definitions in GraphQL, and two wrapping types.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L268-L271">The most basic type is a <code>Scalar</code>. A scalar represents a primitive value, like a string or an integer. Oftentimes, the possible responses for a scalar field are enumerable. GraphQL offers an <code>Enum</code> type in those cases, where the type specifies the space of valid responses.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L273-L275">Scalars and Enums form the leaves in response trees; the intermediate levels are <code>Object</code> types, which define a set of fields, where each field is another type in the system, allowing the definition of arbitrary type hierarchies.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L277">GraphQL supports two abstract types: interfaces and unions.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L279-L282">An <code>Interface</code> defines a list of fields; <code>Object</code> types and other Interface types which implement this Interface are guaranteed to implement those fields. Whenever a field claims it will return an Interface type, it will return a valid implementing Object type during execution.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L284-L286">A <code>Union</code> defines a list of possible types; similar to interfaces, whenever the type system claims a union will be returned, one of the possible types will be returned.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L288-L290">Finally, oftentimes it is useful to provide complex structs as inputs to GraphQL field arguments or variables; the <code>Input Object</code> type allows the schema to define exactly what data is expected.</p> <section id="sec-Wrapping-Types" secid="3.4.1"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L293"><span class="spec-secid" title="link to this section"><a href="#sec-Wrapping-Types">3.4.1</a></span>Wrapping Types</h3> <p data-source="spec/Section%203%20--%20Type%20System.md#L295-L296">All of the types so far are assumed to be both nullable and singular: e.g. a scalar string returns either null or a singular string.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L298-L299">A GraphQL schema may describe that a field represents a list of another type; the <code>List</code> type is provided for this reason, and wraps another type.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L301-L303">Similarly, the <code>Non-Null</code> type wraps another type, and denotes that the resulting value will never be <span class="spec-keyword">null</span> (and that a field error cannot result in a <span class="spec-keyword">null</span> value).</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L305-L307">These two types are referred to as “wrapping types”; non-wrapping types are referred to as “named types”. A wrapping type has an underlying named type, found by continually unwrapping the type until a named type is found.</p> </section> <section id="sec-Input-and-Output-Types" secid="3.4.2"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L310"><span class="spec-secid" title="link to this section"><a href="#sec-Input-and-Output-Types">3.4.2</a></span>Input and Output Types</h3> <p data-source="spec/Section%203%20--%20Type%20System.md#L312-L319">Types are used throughout GraphQL to describe both the values accepted as input to arguments and variables as well as the values output by fields. These two uses categorize types as <em>input types</em> and <em>output types</em>. Some kinds of types, like Scalar and Enum types, can be used as both input types and output types; other kinds of types can only be used in one or the other. Input Object types can only be used as input types. Object, Interface, and Union types can only be used as output types. Lists and Non-Null types may be used as input types or output types depending on how the wrapped type may be used.</p> <div class="spec-algo" id="IsInputType()" data-source="spec/Section%203%20--%20Type%20System.md#L321-L327"> <span class="spec-call"><a href="#IsInputType()" data-name="IsInputType">IsInputType</a>(<var data-name="type">type</var>)</span><ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L322-L324">If <var data-name="type">type</var> is a List type or Non-Null type:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L323">Let <var data-name="unwrappedType">unwrappedType</var> be the unwrapped type of <var data-name="type">type</var>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L324">Return IsInputType(<var data-name="unwrappedType">unwrappedType</var>)</li> </ol> </li> <li data-source="spec/Section%203%20--%20Type%20System.md#L325-L326">If <var data-name="type">type</var> is a Scalar, Enum, or Input Object type:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L326">Return <span class="spec-keyword">true</span></li> </ol> </li> <li data-source="spec/Section%203%20--%20Type%20System.md#L327">Return <span class="spec-keyword">false</span></li> </ol> </div> <div class="spec-algo" id="IsOutputType()" data-source="spec/Section%203%20--%20Type%20System.md#L329-L335"> <span class="spec-call"><a href="#IsOutputType()" data-name="IsOutputType">IsOutputType</a>(<var data-name="type">type</var>)</span><ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L330-L332">If <var data-name="type">type</var> is a List type or Non-Null type:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L331">Let <var data-name="unwrappedType">unwrappedType</var> be the unwrapped type of <var data-name="type">type</var>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L332">Return IsOutputType(<var data-name="unwrappedType">unwrappedType</var>)</li> </ol> </li> <li data-source="spec/Section%203%20--%20Type%20System.md#L333-L334">If <var data-name="type">type</var> is a Scalar, Object, Interface, Union, or Enum type:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L334">Return <span class="spec-keyword">true</span></li> </ol> </li> <li data-source="spec/Section%203%20--%20Type%20System.md#L335">Return <span class="spec-keyword">false</span></li> </ol> </div> </section> <section id="sec-Type-Extensions" secid="3.4.3"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L338"><span class="spec-secid" title="link to this section"><a href="#sec-Type-Extensions">3.4.3</a></span>Type Extensions</h3> <div class="spec-production" id="TypeExtension" data-source="spec/Section%203%20--%20Type%20System.md#L340-L346"> <span class="spec-nt"><a href="#TypeExtension" data-name="TypeExtension">TypeExtension</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ScalarTypeExtension" data-name="ScalarTypeExtension">ScalarTypeExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ObjectTypeExtension" data-name="ObjectTypeExtension">ObjectTypeExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#InterfaceTypeExtension" data-name="InterfaceTypeExtension">InterfaceTypeExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#UnionTypeExtension" data-name="UnionTypeExtension">UnionTypeExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#EnumTypeExtension" data-name="EnumTypeExtension">EnumTypeExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#InputObjectTypeExtension" data-name="InputObjectTypeExtension">InputObjectTypeExtension</a></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L348-L350">Type extensions are used to represent a GraphQL type which has been extended from some original type. For example, this might be used by a local service to represent additional fields a GraphQL client only accesses locally.</p> </section> </section> <section id="sec-Scalars" secid="3.5"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L353"><span class="spec-secid" title="link to this section"><a href="#sec-Scalars">3.5</a></span>Scalars</h2> <div class="spec-production" id="ScalarTypeDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L355"> <span class="spec-nt"><a href="#ScalarTypeDefinition" data-name="ScalarTypeDefinition">ScalarTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">scalar</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L357-L359">Scalar types represent primitive leaf values in a GraphQL type system. GraphQL responses take the form of a hierarchical tree; the leaves of this tree are typically GraphQL Scalar types (but may also be Enum types or <span class="spec-keyword">null</span> values).</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L361-L363">GraphQL provides a number of built-in scalars which are fully defined in the sections below, however type systems may also add additional custom scalars to introduce additional semantic meaning.</p> <section id="sec-Scalars.Built-in-Scalars" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L365"><a href="#sec-Scalars.Built-in-Scalars" title="link to this subsection">Built-in Scalars</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L367-L373">GraphQL specifies a basic set of well-defined Scalar types: <span class="spec-nt"><span data-name="Int">Int</span></span>, <span class="spec-nt"><span data-name="Float">Float</span></span>, <span class="spec-nt"><span data-name="String">String</span></span>, <span class="spec-nt"><span data-name="Boolean">Boolean</span></span>, and <span class="spec-nt"><span data-name="ID">ID</span></span>. A GraphQL framework should support all of these types, and a GraphQL service which provides a type by these names must adhere to the behavior described for them in this document. As an example, a service must not include a type called <span class="spec-nt"><span data-name="Int">Int</span></span> and use it to represent 64-bit numbers, internationalization information, or anything other than what is defined in this document.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L375-L378">When returning the set of types from the <code>__Schema</code> introspection type, all referenced built-in scalars must be included. If a built-in scalar type is not referenced anywhere in a schema (there is no field, argument, or input field of that type) then it must not be included.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L380-L381">When representing a GraphQL schema using the type system definition language, all built-in scalars must be omitted for brevity.</p> </section> <section id="sec-Scalars.Custom-Scalars" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L383"><a href="#sec-Scalars.Custom-Scalars" title="link to this subsection">Custom Scalars</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L385-L391">GraphQL services may use custom scalar types in addition to the built-in scalars. For example, a GraphQL service could define a scalar called <code>UUID</code> which, while serialized as a string, conforms to <a href="https://tools.ietf.org/html/rfc4122">RFC 4122</a>. When querying a field of type <code>UUID</code>, you can then rely on the ability to parse the result with a RFC 4122 compliant parser. Another example of a potentially useful custom scalar is <code>URL</code>, which serializes as a string, but is guaranteed by the server to be a valid URL.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L393-L396">When defining a custom scalar, GraphQL services should provide a <dfn id="scalar-specification-url"><a href="#scalar-specification-url" data-name="scalar-specification-url">scalar specification URL</a></dfn> via the <code>@specifiedBy</code> directive or the <code>specifiedByURL</code> introspection field. This URL must link to a human-readable specification of the data format, serialization, and coercion rules for the scalar.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L398-L401">For example, a GraphQL service providing a <code>UUID</code> scalar may link to RFC 4122, or some custom document defining a reasonable subset of that RFC. If a <span class="spec-ref"><a href="#scalar-specification-url" data-name="scalar-specification-url">scalar specification URL</a></span> is present, systems and tools that are aware of it should conform to its described rules.</p> <pre id="example-9e6a3" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L403-L406"><a href="#example-9e6a3">Example № 42</a><code><span class="token keyword">scalar</span> <span class="token constant">UUID</span> <span class="token directive function">@specifiedBy</span><span class="token punctuation">(</span><span class="token attr-name">url</span><span class="token punctuation">:</span> <span class="token string">"https://tools.ietf.org/html/rfc4122"</span><span class="token punctuation">)</span> <span class="token keyword">scalar</span> <span class="token constant">URL</span> <span class="token directive function">@specifiedBy</span><span class="token punctuation">(</span><span class="token attr-name">url</span><span class="token punctuation">:</span> <span class="token string">"https://tools.ietf.org/html/rfc3986"</span><span class="token punctuation">)</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L408-L410">Custom <span class="spec-ref"><a href="#scalar-specification-url" data-name="scalar-specification-url">scalar specification URL</a></span>s should provide a single, stable format to avoid ambiguity. If the linked specification is in flux, the service should link to a fixed version rather than to a resource which might change.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L412-L414">Custom <span class="spec-ref"><a href="#scalar-specification-url" data-name="scalar-specification-url">scalar specification URL</a></span>s should not be changed once defined. Doing so would likely disrupt tooling or could introduce breaking changes within the linked specification’s contents.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L416-L417">Built-in scalar types must not provide a <span class="spec-ref"><a href="#scalar-specification-url" data-name="scalar-specification-url">scalar specification URL</a></span> as they are specified by this document.</p> <div id="note-b68f7" class="spec-note" data-source="spec/Section%203%20--%20Type%20System.md#L419-L420"> <a href="#note-b68f7">Note</a> Custom scalars should also summarize the specified format and provide examples in their description.</div> </section> <section id="sec-Scalars.Result-Coercion-and-Serialization" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L422"><a href="#sec-Scalars.Result-Coercion-and-Serialization" title="link to this subsection">Result Coercion and Serialization</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L424-L427">A GraphQL service, when preparing a field of a given scalar type, must uphold the contract the scalar type describes, either by coercing the value or producing a <a href="#sec-Errors.Field-errors">field error</a> if a value cannot be coerced or if coercion may result in data loss.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L429-L433">A GraphQL service may decide to allow coercing different internal types to the expected return type. For example when coercing a field of type <span class="spec-nt"><span data-name="Int">Int</span></span> a boolean <span class="spec-keyword">true</span> value may produce <span class="spec-t">1</span> or a string value <span class="spec-string">"123"</span> may be parsed as base-10 <span class="spec-t">123</span>. However if internal type coercion cannot be reasonably performed without losing information, then it must raise a field error.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L435-L438">Since this coercion behavior is not observable to clients of the GraphQL service, the precise rules of coercion are left to the implementation. The only requirement is that the service must yield values which adhere to the expected Scalar type.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L440-L442">GraphQL scalars are serialized according to the serialization format being used. There may be a most appropriate serialized primitive for each given scalar type, and the service should produce each primitive where appropriate.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L444-L445">See <a href="#sec-Serialization-Format">Serialization Format</a> for more detailed information on the serialization of scalars in common JSON and other formats.</p> </section> <section id="sec-Scalars.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L447"><a href="#sec-Scalars.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L449-L452">If a GraphQL service expects a scalar type as input to an argument, coercion is observable and the rules must be well defined. If an input value does not match a coercion rule, a <a href="#sec-Errors.Request-errors">request error</a> must be raised (input values are validated before execution begins).</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L454-L461">GraphQL has different constant literals to represent integer and floating-point input values, and coercion rules may apply differently depending on which type of input value is encountered. GraphQL may be parameterized by variables, the values of which are often serialized when sent over a transport like HTTP. Since some common serializations (ex. JSON) do not discriminate between integer and floating-point values, they are interpreted as an integer input value if they have an empty fractional part (ex. <code>1.0</code>) and otherwise as floating-point input value.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L463-L464">For all types below, with the exception of Non-Null, if the explicit value <span class="spec-keyword">null</span> is provided, then the result of input coercion is <span class="spec-keyword">null</span>.</p> </section> <section id="sec-Int" secid="3.5.1"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L467"><span class="spec-secid" title="link to this section"><a href="#sec-Int">3.5.1</a></span>Int</h3> <p data-source="spec/Section%203%20--%20Type%20System.md#L469-L471">The Int scalar type represents a signed 32-bit numeric non-fractional value. Response formats that support a 32-bit integer or a number type should use that type to represent this scalar.</p> <section id="sec-Int.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L473"><a href="#sec-Int.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L475-L476">Fields returning the type <span class="spec-nt"><span data-name="Int">Int</span></span> expect to encounter 32-bit integer internal values.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L478-L483">GraphQL services may coerce non-integer internal values to integers when reasonable without losing information, otherwise they must raise a field error. Examples of this may include returning <code>1</code> for the floating-point number <code>1.0</code>, or returning <code>123</code> for the string <code>"123"</code>. In scenarios where coercion may lose data, raising a field error is more appropriate. For example, a floating-point number <code>1.2</code> should raise a field error instead of being truncated to <code>1</code>.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L485-L486">If the integer internal value represents a value less than -2<sup>31</sup> or greater than or equal to 2<sup>31</sup>, a field error should be raised.</p> </section> <section id="sec-Int.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L488"><a href="#sec-Int.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L490-L494">When expected as an input type, only integer input values are accepted. All other input values, including strings with numeric content, must raise a request error indicating an incorrect type. If the integer input value represents a value less than -2<sup>31</sup> or greater than or equal to 2<sup>31</sup>, a request error should be raised.</p> <div id="note-0770a" class="spec-note" data-source="spec/Section%203%20--%20Type%20System.md#L496-L498"> <a href="#note-0770a">Note</a> Numeric integer values larger than 32-bit should either use String or a custom-defined Scalar type, as not all platforms and transports support encoding integer numbers larger than 32-bit.</div> </section> </section> <section id="sec-Float" secid="3.5.2"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L501"><span class="spec-secid" title="link to this section"><a href="#sec-Float">3.5.2</a></span>Float</h3> <p data-source="spec/Section%203%20--%20Type%20System.md#L503-L506">The Float scalar type represents signed double-precision finite values as specified by <a href="https://en.wikipedia.org/wiki/IEEE_floating_point">IEEE 754</a>. Response formats that support an appropriate double-precision number type should use that type to represent this scalar.</p> <section id="sec-Float.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L508"><a href="#sec-Float.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L510-L511">Fields returning the type <span class="spec-nt"><span data-name="Float">Float</span></span> expect to encounter double-precision floating-point internal values.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L513-L516">GraphQL services may coerce non-floating-point internal values to <span class="spec-nt"><span data-name="Float">Float</span></span> when reasonable without losing information, otherwise they must raise a field error. Examples of this may include returning <code>1.0</code> for the integer number <code>1</code>, or <code>123.0</code> for the string <code>"123"</code>.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L518-L519">Non-finite floating-point internal values (<span class="spec-nt"><span data-name="NaN">NaN</span></span> and <span class="spec-nt"><span data-name="Infinity">Infinity</span></span>) cannot be coerced to <span class="spec-nt"><span data-name="Float">Float</span></span> and must raise a field error.</p> </section> <section id="sec-Float.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L521"><a href="#sec-Float.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L523-L529">When expected as an input type, both integer and float input values are accepted. Integer input values are coerced to Float by adding an empty fractional part, for example <code>1.0</code> for the integer input value <code>1</code>. All other input values, including strings with numeric content, must raise a request error indicating an incorrect type. If the input value otherwise represents a value not representable by finite IEEE 754 (e.g. <span class="spec-nt"><span data-name="NaN">NaN</span></span>, <span class="spec-nt"><span data-name="Infinity">Infinity</span></span>, or a value outside the available precision), a request error must be raised.</p> </section> </section> <section id="sec-String" secid="3.5.3"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L532"><span class="spec-secid" title="link to this section"><a href="#sec-String">3.5.3</a></span>String</h3> <p data-source="spec/Section%203%20--%20Type%20System.md#L534-L539">The String scalar type represents textual data, represented as a sequence of Unicode code points. The String type is most often used by GraphQL to represent free-form human-readable text. How the String is encoded internally (for example UTF-8) is left to the service implementation. All response serialization formats must support a string representation (for example, JSON Unicode strings), and that representation must be used to serialize this type.</p> <section id="sec-String.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L541"><a href="#sec-String.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L543">Fields returning the type <span class="spec-nt"><span data-name="String">String</span></span> expect to encounter Unicode string values.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L545-L548">GraphQL services may coerce non-string raw values to <span class="spec-nt"><span data-name="String">String</span></span> when reasonable without losing information, otherwise they must raise a field error. Examples of this may include returning the string <code>"true"</code> for a boolean true value, or the string <code>"1"</code> for the integer <code>1</code>.</p> </section> <section id="sec-String.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L550"><a href="#sec-String.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L552-L554">When expected as an input type, only valid Unicode string input values are accepted. All other input values must raise a request error indicating an incorrect type.</p> </section> </section> <section id="sec-Boolean" secid="3.5.4"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L557"><span class="spec-secid" title="link to this section"><a href="#sec-Boolean">3.5.4</a></span>Boolean</h3> <p data-source="spec/Section%203%20--%20Type%20System.md#L559-L561">The Boolean scalar type represents <code>true</code> or <code>false</code>. Response formats should use a built-in boolean type if supported; otherwise, they should use their representation of the integers <code>1</code> and <code>0</code>.</p> <section id="sec-Boolean.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L563"><a href="#sec-Boolean.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L565">Fields returning the type <span class="spec-nt"><span data-name="Boolean">Boolean</span></span> expect to encounter boolean internal values.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L567-L569">GraphQL services may coerce non-boolean raw values to <span class="spec-nt"><span data-name="Boolean">Boolean</span></span> when reasonable without losing information, otherwise they must raise a field error. Examples of this may include returning <code>true</code> for non-zero numbers.</p> </section> <section id="sec-Boolean.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L571"><a href="#sec-Boolean.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L573-L574">When expected as an input type, only boolean input values are accepted. All other input values must raise a request error indicating an incorrect type.</p> </section> </section> <section id="sec-ID" secid="3.5.5"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L577"><span class="spec-secid" title="link to this section"><a href="#sec-ID">3.5.5</a></span>ID</h3> <p data-source="spec/Section%203%20--%20Type%20System.md#L579-L582">The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a <span class="spec-nt"><span data-name="String">String</span></span>; however, it is not intended to be human-readable. While it is often numeric, it should always serialize as a <span class="spec-nt"><span data-name="String">String</span></span>.</p> <section id="sec-ID.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L584"><a href="#sec-ID.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L586-L589">GraphQL is agnostic to ID format, and serializes to string to ensure consistency across many formats ID could represent, from small auto-increment numbers, to large 128-bit random numbers, to base64 encoded values, or string values of a format like <a href="https://en.wikipedia.org/wiki/Globally_unique_identifier">GUID</a>.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L591-L592">GraphQL services should coerce as appropriate given the ID formats they expect. When coercion is not possible they must raise a field error.</p> </section> <section id="sec-ID.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L594"><a href="#sec-ID.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L596-L600">When expected as an input type, any string (such as <code>"4"</code>) or integer (such as <code>4</code> or <code>-4</code>) input value should be coerced to ID as appropriate for the ID formats a given GraphQL service expects. Any other input value, including float input values (such as <code>4.0</code>), must raise a request error indicating an incorrect type.</p> </section> </section> <section id="sec-Scalar-Extensions" secid="3.5.6"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L603"><span class="spec-secid" title="link to this section"><a href="#sec-Scalar-Extensions">3.5.6</a></span>Scalar Extensions</h3> <div class="spec-production" id="ScalarTypeExtension" data-source="spec/Section%203%20--%20Type%20System.md#L605-L606"> <span class="spec-nt"><a href="#ScalarTypeExtension" data-name="ScalarTypeExtension">ScalarTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">scalar</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L608-L610">Scalar type extensions are used to represent a scalar type which has been extended from some original scalar type. For example, this might be used by a GraphQL tool or service which adds directives to an existing scalar.</p> <section id="sec-Scalar-Extensions.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L612"><a href="#sec-Scalar-Extensions.Type-Validation" title="link to this subsection">Type Validation</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L614">Scalar type extensions have the potential to be invalid if incorrectly defined.</p> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L616">The named type must already be defined and must be a Scalar type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L617-L618">Any non-repeatable directives provided must not already apply to the original Scalar type.</li> </ol> </section> </section> </section> <section id="sec-Objects" secid="3.6"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L621"><span class="spec-secid" title="link to this section"><a href="#sec-Objects">3.6</a></span>Objects</h2> <div class="spec-production" id="ObjectTypeDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L623-L625"> <span class="spec-nt"><a href="#ObjectTypeDefinition" data-name="ObjectTypeDefinition">ObjectTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">type</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#FieldsDefinition" data-name="FieldsDefinition">FieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">type</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="ImplementsInterfaces" data-source="spec/Section%203%20--%20Type%20System.md#L627-L629"> <span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-t">&</span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> <div class="spec-rhs"><span class="spec-t">implements</span><span class="spec-quantified"><span class="spec-t">&</span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> </div> <div class="spec-production" id="FieldsDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L631"> <span class="spec-nt"><a href="#FieldsDefinition" data-name="FieldsDefinition">FieldsDefinition</a></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#FieldDefinition" data-name="FieldDefinition">FieldDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <div class="spec-production" id="FieldDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L633"> <span class="spec-nt"><a href="#FieldDefinition" data-name="FieldDefinition">FieldDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ArgumentsDefinition" data-name="ArgumentsDefinition">ArgumentsDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L635-L637">GraphQL operations are hierarchical and composed, describing a tree of information. While Scalar types describe the leaf values of these hierarchical operations, Objects describe the intermediate levels.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L639-L643">GraphQL Objects represent a list of named fields, each of which yield a value of a specific type. Object values should be serialized as ordered maps, where the selected field names (or aliases) are the keys and the result of evaluating the field is the value, ordered by the order in which they appear in the selection set.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L645-L647">All fields defined within an Object type must not have a name which begins with <span class="spec-string">"__"</span> (two underscores), as this is used exclusively by GraphQL’s introspection system.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L649">For example, a type <code>Person</code> could be described as:</p> <pre id="example-ccb01" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L651-L657"><a href="#example-ccb01">Example № 43</a><code><span class="token keyword">type</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">age</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token attr-name">picture</span><span class="token punctuation">:</span> <span class="token class-name">Url</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L659-L661">Where <code>name</code> is a field that will yield a <span class="spec-nt"><span data-name="String">String</span></span> value, and <code>age</code> is a field that will yield an <span class="spec-nt"><span data-name="Int">Int</span></span> value, and <code>picture</code> is a field that will yield a <code>Url</code> value.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L663-L667">A query of an object value must select at least one field. This selection of fields will yield an ordered map containing exactly the subset of the object queried, which should be represented in the order in which they were queried. Only fields that are declared on the object type may validly be queried on that object.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L669">For example, selecting all the fields of <code>Person</code>:</p> <pre id="example-1743a" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L671-L677"><a href="#example-1743a">Example № 44</a><code><span class="token punctuation">{</span> <span class="token property">name</span> <span class="token property">age</span> <span class="token property">picture</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L679">Would yield the object:</p> <pre id="example-71184" class="spec-example" data-language="json" data-source="spec/Section%203%20--%20Type%20System.md#L681-L687"><a href="#example-71184">Example № 45</a><code><span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Mark Zuckerberg"</span><span class="token punctuation">,</span> <span class="token property">"age"</span><span class="token operator">:</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token property">"picture"</span><span class="token operator">:</span> <span class="token string">"http://some.cdn/picture.jpg"</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L689">While selecting a subset of fields:</p> <pre id="example-3964f" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L691-L696"><a href="#example-3964f">Example № 46</a><code><span class="token punctuation">{</span> <span class="token property">age</span> <span class="token property">name</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L698">Must only yield exactly that subset:</p> <pre id="example-600a0" class="spec-example" data-language="json" data-source="spec/Section%203%20--%20Type%20System.md#L700-L705"><a href="#example-600a0">Example № 47</a><code><span class="token punctuation">{</span> <span class="token property">"age"</span><span class="token operator">:</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Mark Zuckerberg"</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L707-L709">A field of an Object type may be a Scalar, Enum, another Object type, an Interface, or a Union. Additionally, it may be any wrapping type whose underlying base type is one of those five.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L711">For example, the <code>Person</code> type might include a <code>relationship</code>:</p> <pre id="example-49198" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L713-L720"><a href="#example-49198">Example № 48</a><code><span class="token keyword">type</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">age</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token attr-name">picture</span><span class="token punctuation">:</span> <span class="token class-name">Url</span> <span class="token attr-name">relationship</span><span class="token punctuation">:</span> <span class="token class-name">Person</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L722-L723">Valid operations must supply a nested field set for any field that returns an object, so this operation is not valid:</p> <pre id="example-729a1" class="spec-counter-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L725-L730"><a href="#example-729a1">Counter Example № 49</a><code><span class="token punctuation">{</span> <span class="token property">name</span> <span class="token property">relationship</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L732">However, this example is valid:</p> <pre id="example-bb999" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L734-L741"><a href="#example-bb999">Example № 50</a><code><span class="token punctuation">{</span> <span class="token property">name</span> <span class="token object">relationship</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L743">And will yield the subset of each object type queried:</p> <pre id="example-352cc" class="spec-example" data-language="json" data-source="spec/Section%203%20--%20Type%20System.md#L745-L752"><a href="#example-352cc">Example № 51</a><code><span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Mark Zuckerberg"</span><span class="token punctuation">,</span> <span class="token property">"relationship"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Priscilla Chan"</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <section id="sec-Objects.Field-Ordering" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L754"><a href="#sec-Objects.Field-Ordering" title="link to this subsection">Field Ordering</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L756-L760">When querying an Object, the resulting mapping of fields are conceptually ordered in the same order in which they were encountered during execution, excluding fragments for which the type does not apply and fields or fragments that are skipped via <code>@skip</code> or <code>@include</code> directives. This ordering is correctly produced when using the <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>()</span> algorithm.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L762-L766">Response serialization formats capable of representing ordered maps should maintain this ordering. Serialization formats which can only represent unordered maps (such as JSON) should retain this order textually. That is, if two fields <code>{foo, bar}</code> were queried in that order, the resulting JSON serialization should contain <code>{"foo": "...", "bar": "..."}</code> in the same order.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L768-L771">Producing a response where fields are represented in the same order in which they appear in the request improves human readability during debugging and enables more efficient parsing of responses if the order of properties can be anticipated.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L773-L774">If a fragment is spread before other fields, the fields that fragment specifies occur in the response before the following fields.</p> <pre id="example-7924b" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L776-L787"><a href="#example-7924b">Example № 52</a><code><span class="token punctuation">{</span> <span class="token property">foo</span> <span class="token operator">...</span><span class="token fragment function">Frag</span> <span class="token property">qux</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">Frag</span> <span class="token keyword">on</span> <span class="token class-name">Query</span> <span class="token punctuation">{</span> <span class="token property">bar</span> <span class="token property">baz</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L789">Produces the ordered result:</p> <pre id="example-1455b" class="spec-example" data-language="json" data-source="spec/Section%203%20--%20Type%20System.md#L791-L798"><a href="#example-1455b">Example № 53</a><code><span class="token punctuation">{</span> <span class="token property">"foo"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token property">"bar"</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token property">"baz"</span><span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token property">"qux"</span><span class="token operator">:</span> <span class="token number">4</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L800-L802">If a field is queried multiple times in a selection, it is ordered by the first time it is encountered. However fragments for which the type does not apply does not affect ordering.</p> <pre id="example-70ded" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L804-L822"><a href="#example-70ded">Example № 54</a><code><span class="token punctuation">{</span> <span class="token property">foo</span> <span class="token operator">...</span><span class="token fragment function">Ignored</span> <span class="token operator">...</span><span class="token fragment function">Matching</span> <span class="token property">bar</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">Ignored</span> <span class="token keyword">on</span> <span class="token class-name">UnknownType</span> <span class="token punctuation">{</span> <span class="token property">qux</span> <span class="token property">baz</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">Matching</span> <span class="token keyword">on</span> <span class="token class-name">Query</span> <span class="token punctuation">{</span> <span class="token property">bar</span> <span class="token property">qux</span> <span class="token property">foo</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L824">Produces the ordered result:</p> <pre id="example-2e0e9" class="spec-example" data-language="json" data-source="spec/Section%203%20--%20Type%20System.md#L826-L832"><a href="#example-2e0e9">Example № 55</a><code><span class="token punctuation">{</span> <span class="token property">"foo"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token property">"bar"</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token property">"qux"</span><span class="token operator">:</span> <span class="token number">3</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L834-L835">Also, if directives result in fields being excluded, they are not considered in the ordering of fields.</p> <pre id="example-50762" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L837-L843"><a href="#example-50762">Example № 56</a><code><span class="token punctuation">{</span> <span class="token property">foo</span> <span class="token directive function">@skip</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token property">bar</span> <span class="token property">foo</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L845">Produces the ordered result:</p> <pre id="example-dd904" class="spec-example" data-language="json" data-source="spec/Section%203%20--%20Type%20System.md#L847-L852"><a href="#example-dd904">Example № 57</a><code><span class="token punctuation">{</span> <span class="token property">"bar"</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token property">"foo"</span><span class="token operator">:</span> <span class="token number">2</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-Objects.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L854"><a href="#sec-Objects.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L856-L857">Determining the result of coercing an object is the heart of the GraphQL executor, so this is covered in that section of the spec.</p> </section> <section id="sec-Objects.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L859"><a href="#sec-Objects.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L861">Objects are never valid inputs.</p> </section> <section id="sec-Objects.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L863"><a href="#sec-Objects.Type-Validation" title="link to this subsection">Type Validation</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L865-L866">Object types have the potential to be invalid if incorrectly defined. This set of rules must be adhered to by every Object type in a GraphQL schema.</p> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L868">An Object type must define one or more fields.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L869-L879">For each field of an Object type:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L870-L871">The field must have a unique name within that Object type; no two fields may share the same name.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L872-L873">The field must not have a name which begins with the characters <span class="spec-string">"__"</span> (two underscores).</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L874">The field must return a type where <span class="spec-call"><a href="#IsOutputType()" data-name="IsOutputType">IsOutputType</a>(<var data-name="fieldType">fieldType</var>)</span> returns <span class="spec-keyword">true</span>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L875-L879">For each argument of the field:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L876-L877">The argument must not have a name which begins with the characters <span class="spec-string">"__"</span> (two underscores).</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L878-L879">The argument must accept a type where <span class="spec-call"><a href="#IsInputType()" data-name="IsInputType">IsInputType</a>(<var data-name="argumentType">argumentType</var>)</span> returns <span class="spec-keyword">true</span>.</li> </ol> </li> </ol> </li> <li data-source="spec/Section%203%20--%20Type%20System.md#L880">An object type may declare that it implements one or more unique interfaces.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L881-L884">An object type must be a super-set of all interfaces it implements:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L882">Let this object type be <var data-name="objectType">objectType</var>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L883-L884">For each interface declared implemented as <var data-name="interfaceType">interfaceType</var>, <span class="spec-call"><a href="#IsValidImplementation()" data-name="IsValidImplementation">IsValidImplementation</a>(<var data-name="objectType">objectType</var>, <var data-name="interfaceType">interfaceType</var>)</span> must be <span class="spec-keyword">true</span>.</li> </ol> </li> </ol> <div class="spec-algo" id="IsValidImplementation()" data-source="spec/Section%203%20--%20Type%20System.md#L886-L906"> <span class="spec-call"><a href="#IsValidImplementation()" data-name="IsValidImplementation">IsValidImplementation</a>(<var data-name="type">type</var>, <var data-name="implementedType">implementedType</var>)</span><ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L888-L889">If <var data-name="implementedType">implementedType</var> declares it implements any interfaces, <var data-name="type">type</var> must also declare it implements those interfaces.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L890-L906"><var data-name="type">type</var> must include a field of the same name for every field defined in <var data-name="implementedType">implementedType</var>.<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L892">Let <var data-name="field">field</var> be that named field on <var data-name="type">type</var>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L893">Let <var data-name="implementedField">implementedField</var> be that named field on <var data-name="implementedType">implementedType</var>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L894-L897"><var data-name="field">field</var> must include an argument of the same name for every argument defined in <var data-name="implementedField">implementedField</var>.<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L896-L897">That named argument on <var data-name="field">field</var> must accept the same type (invariant) as that named argument on <var data-name="implementedField">implementedField</var>.</li> </ol> </li> <li data-source="spec/Section%203%20--%20Type%20System.md#L898-L900"><var data-name="field">field</var> may include additional arguments not defined in <var data-name="implementedField">implementedField</var>, but any additional argument must not be required, e.g. must not be of a non-nullable type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L901-L906"><var data-name="field">field</var> must return a type which is equal to or a sub-type of (covariant) the return type of <var data-name="implementedField">implementedField</var> field’s return type:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L903">Let <var data-name="fieldType">fieldType</var> be the return type of <var data-name="field">field</var>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L904">Let <var data-name="implementedFieldType">implementedFieldType</var> be the return type of <var data-name="implementedField">implementedField</var>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L905-L906"><span class="spec-call"><a href="#IsValidImplementationFieldType()" data-name="IsValidImplementationFieldType">IsValidImplementationFieldType</a>(<var data-name="fieldType">fieldType</var>, <var data-name="implementedFieldType">implementedFieldType</var>)</span> must be <span class="spec-keyword">true</span>.</li> </ol> </li> </ol> </li> </ol> </div> <div class="spec-algo" id="IsValidImplementationFieldType()" data-source="spec/Section%203%20--%20Type%20System.md#L908-L927"> <span class="spec-call"><a href="#IsValidImplementationFieldType()" data-name="IsValidImplementationFieldType">IsValidImplementationFieldType</a>(<var data-name="fieldType">fieldType</var>, <var data-name="implementedFieldType">implementedFieldType</var>)</span><ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L909-L914">If <var data-name="fieldType">fieldType</var> is a Non-Null type:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L910">Let <var data-name="nullableType">nullableType</var> be the unwrapped nullable type of <var data-name="fieldType">fieldType</var>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L911-L913">Let <var data-name="implementedNullableType">implementedNullableType</var> be the unwrapped nullable type of <var data-name="implementedFieldType">implementedFieldType</var> if it is a Non-Null type, otherwise let it be <var data-name="implementedFieldType">implementedFieldType</var> directly.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L914">Return <span class="spec-call"><a href="#IsValidImplementationFieldType()" data-name="IsValidImplementationFieldType">IsValidImplementationFieldType</a>(<var data-name="nullableType">nullableType</var>, <var data-name="implementedNullableType">implementedNullableType</var>)</span>.</li> </ol> </li> <li data-source="spec/Section%203%20--%20Type%20System.md#L915-L919">If <var data-name="fieldType">fieldType</var> is a List type and <var data-name="implementedFieldType">implementedFieldType</var> is also a List type:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L916">Let <var data-name="itemType">itemType</var> be the unwrapped item type of <var data-name="fieldType">fieldType</var>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L917-L918">Let <var data-name="implementedItemType">implementedItemType</var> be the unwrapped item type of <var data-name="implementedFieldType">implementedFieldType</var>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L919">Return <span class="spec-call"><a href="#IsValidImplementationFieldType()" data-name="IsValidImplementationFieldType">IsValidImplementationFieldType</a>(<var data-name="itemType">itemType</var>, <var data-name="implementedItemType">implementedItemType</var>)</span>.</li> </ol> </li> <li data-source="spec/Section%203%20--%20Type%20System.md#L920">If <var data-name="fieldType">fieldType</var> is the same type as <var data-name="implementedFieldType">implementedFieldType</var> then return <span class="spec-keyword">true</span>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L921-L923">If <var data-name="fieldType">fieldType</var> is an Object type and <var data-name="implementedFieldType">implementedFieldType</var> is a Union type and <var data-name="fieldType">fieldType</var> is a possible type of <var data-name="implementedFieldType">implementedFieldType</var> then return <span class="spec-keyword">true</span>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L924-L926">If <var data-name="fieldType">fieldType</var> is an Object or Interface type and <var data-name="implementedFieldType">implementedFieldType</var> is an Interface type and <var data-name="fieldType">fieldType</var> declares it implements <var data-name="implementedFieldType">implementedFieldType</var> then return <span class="spec-keyword">true</span>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L927">Otherwise return <span class="spec-keyword">false</span>.</li> </ol> </div> </section> <section id="sec-Field-Arguments" secid="3.6.1"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L930"><span class="spec-secid" title="link to this section"><a href="#sec-Field-Arguments">3.6.1</a></span>Field Arguments</h3> <div class="spec-production" id="ArgumentsDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L932"> <span class="spec-nt"><a href="#ArgumentsDefinition" data-name="ArgumentsDefinition">ArgumentsDefinition</a></span><div class="spec-rhs"><span class="spec-t">(</span><span class="spec-quantified"><span class="spec-nt"><a href="#InputValueDefinition" data-name="InputValueDefinition">InputValueDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">)</span></div> </div> <div class="spec-production" id="InputValueDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L934"> <span class="spec-nt"><a href="#InputValueDefinition" data-name="InputValueDefinition">InputValueDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#DefaultValue" data-name="DefaultValue">DefaultValue</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L936-L939">Object fields are conceptually functions which yield values. Occasionally object fields can accept arguments to further specify the return value. Object field arguments are defined as a list of all possible argument names and their expected input types.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L941-L943">All arguments defined within a field must not have a name which begins with <span class="spec-string">"__"</span> (two underscores), as this is used exclusively by GraphQL’s introspection system.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L945-L946">For example, a <code>Person</code> type with a <code>picture</code> field could accept an argument to determine what size of an image to return.</p> <pre id="example-fb0d5" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L948-L953"><a href="#example-fb0d5">Example № 58</a><code><span class="token keyword">type</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">picture</span><span class="token punctuation">(</span><span class="token attr-name">size</span><span class="token punctuation">:</span> <span class="token scalar">Int</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name">Url</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L955-L956">Operations can optionally specify arguments to their fields to provide these arguments.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L958">This example operation:</p> <pre id="example-81f19" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L960-L965"><a href="#example-81f19">Example № 59</a><code><span class="token punctuation">{</span> <span class="token property">name</span> <span class="token property-query">picture</span><span class="token punctuation">(</span><span class="token attr-name">size</span><span class="token punctuation">:</span> <span class="token number">600</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L967">May return the result:</p> <pre id="example-31f7a" class="spec-example" data-language="json" data-source="spec/Section%203%20--%20Type%20System.md#L969-L974"><a href="#example-31f7a">Example № 60</a><code><span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Mark Zuckerberg"</span><span class="token punctuation">,</span> <span class="token property">"picture"</span><span class="token operator">:</span> <span class="token string">"http://some.cdn/picture_600.jpg"</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L976-L977">The type of an object field argument must be an input type (any type except an Object, Interface, or Union type).</p> </section> <section id="sec-Field-Deprecation" secid="3.6.2"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L980"><span class="spec-secid" title="link to this section"><a href="#sec-Field-Deprecation">3.6.2</a></span>Field Deprecation</h3> <p data-source="spec/Section%203%20--%20Type%20System.md#L982-L985">Fields in an object may be marked as deprecated as deemed necessary by the application. It is still legal to include these fields in a selection set (to ensure existing clients are not broken by the change), but the fields should be appropriately treated in documentation and tooling.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L987-L988">When using the type system definition language, <code>@deprecated</code> directives are used to indicate that a field is deprecated:</p> <pre id="example-013ef" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L990-L994"><a href="#example-013ef">Example № 61</a><code><span class="token keyword">type</span> <span class="token class-name">ExampleType</span> <span class="token punctuation">{</span> <span class="token attr-name">oldField</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token directive function">@deprecated</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-Object-Extensions" secid="3.6.3"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L997"><span class="spec-secid" title="link to this section"><a href="#sec-Object-Extensions">3.6.3</a></span>Object Extensions</h3> <div class="spec-production" id="ObjectTypeExtension" data-source="spec/Section%203%20--%20Type%20System.md#L999-L1002"> <span class="spec-nt"><a href="#ObjectTypeExtension" data-name="ObjectTypeExtension">ObjectTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">type</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#FieldsDefinition" data-name="FieldsDefinition">FieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">type</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">type</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L1004-L1006">Object type extensions are used to represent a type which has been extended from some original type. For example, this might be used to represent local data, or by a GraphQL service which is itself an extension of another GraphQL service.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1008">In this example, a local data field is added to a <code>Story</code> type:</p> <pre id="example-8bda7" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1010-L1014"><a href="#example-8bda7">Example № 62</a><code><span class="token keyword">extend</span> <span class="token keyword">type</span> <span class="token class-name">Story</span> <span class="token punctuation">{</span> <span class="token attr-name">isHiddenLocally</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1016-L1017">Object type extensions may choose not to add additional fields, instead only adding interfaces or directives.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1019">In this example, a directive is added to a <code>User</code> type without adding fields:</p> <pre id="example-605bd" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1021-L1023"><a href="#example-605bd">Example № 63</a><code><span class="token keyword">extend</span> <span class="token keyword">type</span> <span class="token class-name">User</span> <span class="token directive function">@addedDirective</span> </code></pre> <section id="sec-Object-Extensions.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1025"><a href="#sec-Object-Extensions.Type-Validation" title="link to this subsection">Type Validation</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1027">Object type extensions have the potential to be invalid if incorrectly defined.</p> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1029">The named type must already be defined and must be an Object type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1030-L1031">The fields of an Object type extension must have unique names; no two fields may share the same name.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1032-L1033">Any fields of an Object type extension must not be already defined on the original Object type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1034-L1035">Any non-repeatable directives provided must not already apply to the original Object type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1036-L1037">Any interfaces provided must not be already implemented by the original Object type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1038-L1039">The resulting extended object type must be a super-set of all interfaces it implements.</li> </ol> </section> </section> </section> <section id="sec-Interfaces" secid="3.7"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L1042"><span class="spec-secid" title="link to this section"><a href="#sec-Interfaces">3.7</a></span>Interfaces</h2> <div class="spec-production" id="InterfaceTypeDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L1044-L1046"> <span class="spec-nt"><a href="#InterfaceTypeDefinition" data-name="InterfaceTypeDefinition">InterfaceTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">interface</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#FieldsDefinition" data-name="FieldsDefinition">FieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">interface</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L1048-L1050">GraphQL interfaces represent a list of named fields and their arguments. GraphQL objects and interfaces can then implement these interfaces which requires that the implementing type will define all fields defined by those interfaces.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1052-L1054">Fields on a GraphQL interface have the same rules as fields on a GraphQL object; their type can be Scalar, Object, Enum, Interface, or Union, or any wrapping type whose base type is one of those five.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1056-L1058">For example, an interface <code>NamedEntity</code> may describe a required field and types such as <code>Person</code> or <code>Business</code> may then implement this interface to guarantee this field will always exist.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1060-L1061">Types may also implement multiple interfaces. For example, <code>Business</code> implements both the <code>NamedEntity</code> and <code>ValuedEntity</code> interfaces in the example below.</p> <pre id="example-ab5e5" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1063-L1082"><a href="#example-ab5e5">Example № 64</a><code><span class="token keyword">interface</span> <span class="token class-name">NamedEntity</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">interface</span> <span class="token class-name">ValuedEntity</span> <span class="token punctuation">{</span> <span class="token attr-name">value</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">Person</span> <span class="token keyword">implements</span> <span class="token class-name">NamedEntity</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">age</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">Business</span> <span class="token keyword">implements</span> <span class="token class-name">NamedEntity</span> <span class="token operator">&</span> <span class="token class-name">ValuedEntity</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">value</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token attr-name">employeeCount</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1084-L1085">Fields which yield an interface are useful when one of many Object types are expected, but some fields should be guaranteed.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1087">To continue the example, a <code>Contact</code> might refer to <code>NamedEntity</code>.</p> <pre id="example-00227" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1089-L1095"><a href="#example-00227">Example № 65</a><code><span class="token keyword">type</span> <span class="token class-name">Contact</span> <span class="token punctuation">{</span> <span class="token attr-name">entity</span><span class="token punctuation">:</span> <span class="token class-name">NamedEntity</span> <span class="token attr-name">phoneNumber</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">address</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1097-L1098">This allows us to write a selection set for a <code>Contact</code> that can select the common fields.</p> <pre id="example-bc3fd" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1100-L1107"><a href="#example-bc3fd">Example № 66</a><code><span class="token punctuation">{</span> <span class="token object">entity</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token property">phoneNumber</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1109-L1112">When selecting fields on an interface type, only those fields declared on the interface may be queried. In the above example, <code>entity</code> returns a <code>NamedEntity</code>, and <code>name</code> is defined on <code>NamedEntity</code>, so it is valid. However, the following would not be a valid selection set against <code>Contact</code>:</p> <pre id="example-0c812" class="spec-counter-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1114-L1122"><a href="#example-0c812">Counter Example № 67</a><code><span class="token punctuation">{</span> <span class="token object">entity</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token property">age</span> <span class="token punctuation">}</span> <span class="token property">phoneNumber</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1124-L1126">because <code>entity</code> refers to a <code>NamedEntity</code>, and <code>age</code> is not defined on that interface. Querying for <code>age</code> is only valid when the result of <code>entity</code> is a <code>Person</code>; this can be expressed using a fragment or an inline fragment:</p> <pre id="example-47576" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1128-L1138"><a href="#example-47576">Example № 68</a><code><span class="token punctuation">{</span> <span class="token object">entity</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span> <span class="token property">age</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token property">phoneNumber</span> <span class="token punctuation">}</span> </code></pre> <section id="sec-Interfaces.Interfaces-Implementing-Interfaces" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1140"><a href="#sec-Interfaces.Interfaces-Implementing-Interfaces" title="link to this subsection">Interfaces Implementing Interfaces</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1142-L1145">When defining an interface that implements another interface, the implementing interface must define each field that is specified by the implemented interface. For example, the interface Resource must define the field id to implement the Node interface:</p> <pre id="example-ba6cb" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1147-L1156"><a href="#example-ba6cb">Example № 69</a><code><span class="token keyword">interface</span> <span class="token class-name">Node</span> <span class="token punctuation">{</span> <span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token scalar">ID</span><span class="token operator">!</span> <span class="token punctuation">}</span> <span class="token keyword">interface</span> <span class="token class-name">Resource</span> <span class="token keyword">implements</span> <span class="token class-name">Node</span> <span class="token punctuation">{</span> <span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token scalar">ID</span><span class="token operator">!</span> <span class="token attr-name">url</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1158-L1161">Transitively implemented interfaces (interfaces implemented by the interface that is being implemented) must also be defined on an implementing type or interface. For example, <code>Image</code> cannot implement <code>Resource</code> without also implementing <code>Node</code>:</p> <pre id="example-4c7ed" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1163-L1178"><a href="#example-4c7ed">Example № 70</a><code><span class="token keyword">interface</span> <span class="token class-name">Node</span> <span class="token punctuation">{</span> <span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token scalar">ID</span><span class="token operator">!</span> <span class="token punctuation">}</span> <span class="token keyword">interface</span> <span class="token class-name">Resource</span> <span class="token keyword">implements</span> <span class="token class-name">Node</span> <span class="token punctuation">{</span> <span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token scalar">ID</span><span class="token operator">!</span> <span class="token attr-name">url</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">interface</span> <span class="token class-name">Image</span> <span class="token keyword">implements</span> <span class="token class-name">Resource</span> <span class="token operator">&</span> <span class="token class-name">Node</span> <span class="token punctuation">{</span> <span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token scalar">ID</span><span class="token operator">!</span> <span class="token attr-name">url</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">thumbnail</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1180-L1182">Interface definitions must not contain cyclic references nor implement themselves. This example is invalid because <code>Node</code> and <code>Named</code> implement themselves and each other:</p> <pre id="example-9b199" class="spec-counter-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1184-L1194"><a href="#example-9b199">Counter Example № 71</a><code><span class="token keyword">interface</span> <span class="token class-name">Node</span> <span class="token keyword">implements</span> <span class="token class-name">Named</span> <span class="token operator">&</span> <span class="token class-name">Node</span> <span class="token punctuation">{</span> <span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token scalar">ID</span><span class="token operator">!</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">interface</span> <span class="token class-name">Named</span> <span class="token keyword">implements</span> <span class="token class-name">Node</span> <span class="token operator">&</span> <span class="token class-name">Named</span> <span class="token punctuation">{</span> <span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token scalar">ID</span><span class="token operator">!</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-Interfaces.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1197"><a href="#sec-Interfaces.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1199-L1201">The interface type should have some way of determining which object a given result corresponds to. Once it has done so, the result coercion of the interface is the same as the result coercion of the object.</p> </section> <section id="sec-Interfaces.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1203"><a href="#sec-Interfaces.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1205">Interfaces are never valid inputs.</p> </section> <section id="sec-Interfaces.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1207"><a href="#sec-Interfaces.Type-Validation" title="link to this subsection">Type Validation</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1209">Interface types have the potential to be invalid if incorrectly defined.</p> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1211">An Interface type must define one or more fields.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1212-L1223">For each field of an Interface type:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1213-L1214">The field must have a unique name within that Interface type; no two fields may share the same name.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1215-L1216">The field must not have a name which begins with the characters <span class="spec-string">"__"</span> (two underscores).</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1217-L1218">The field must return a type where <span class="spec-call"><a href="#IsOutputType()" data-name="IsOutputType">IsOutputType</a>(<var data-name="fieldType">fieldType</var>)</span> returns <span class="spec-keyword">true</span>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1219-L1223">For each argument of the field:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1220-L1221">The argument must not have a name which begins with the characters <span class="spec-string">"__"</span> (two underscores).</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1222-L1223">The argument must accept a type where <span class="spec-call"><a href="#IsInputType()" data-name="IsInputType">IsInputType</a>(<var data-name="argumentType">argumentType</var>)</span> returns <span class="spec-keyword">true</span>.</li> </ol> </li> </ol> </li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1224-L1225">An interface type may declare that it implements one or more unique interfaces, but may not implement itself.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1226-L1229">An interface type must be a super-set of all interfaces it implements:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1227">Let this interface type be <var data-name="implementingType">implementingType</var>.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1228-L1229">For each interface declared implemented as <var data-name="implementedType">implementedType</var>, <span class="spec-call"><a href="#IsValidImplementation()" data-name="IsValidImplementation">IsValidImplementation</a>(<var data-name="implementingType">implementingType</var>, <var data-name="implementedType">implementedType</var>)</span> must be <span class="spec-keyword">true</span>.</li> </ol> </li> </ol> </section> <section id="sec-Interface-Extensions" secid="3.7.1"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L1232"><span class="spec-secid" title="link to this section"><a href="#sec-Interface-Extensions">3.7.1</a></span>Interface Extensions</h3> <div class="spec-production" id="InterfaceTypeExtension" data-source="spec/Section%203%20--%20Type%20System.md#L1234-L1237"> <span class="spec-nt"><a href="#InterfaceTypeExtension" data-name="InterfaceTypeExtension">InterfaceTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">interface</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#FieldsDefinition" data-name="FieldsDefinition">FieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">interface</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">interface</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L1239-L1242">Interface type extensions are used to represent an interface which has been extended from some original interface. For example, this might be used to represent common local data on many types, or by a GraphQL service which is itself an extension of another GraphQL service.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1244-L1245">In this example, an extended data field is added to a <code>NamedEntity</code> type along with the types which implement it:</p> <pre id="example-9d45f" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1247-L1259"><a href="#example-9d45f">Example № 72</a><code><span class="token keyword">extend</span> <span class="token keyword">interface</span> <span class="token class-name">NamedEntity</span> <span class="token punctuation">{</span> <span class="token attr-name">nickname</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">extend</span> <span class="token keyword">type</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span> <span class="token attr-name">nickname</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">extend</span> <span class="token keyword">type</span> <span class="token class-name">Business</span> <span class="token punctuation">{</span> <span class="token attr-name">nickname</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1261-L1262">Interface type extensions may choose not to add additional fields, instead only adding directives.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1264-L1265">In this example, a directive is added to a <code>NamedEntity</code> type without adding fields:</p> <pre id="example-02d28" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1267-L1269"><a href="#example-02d28">Example № 73</a><code><span class="token keyword">extend</span> <span class="token keyword">interface</span> <span class="token class-name">NamedEntity</span> <span class="token directive function">@addedDirective</span> </code></pre> <section id="sec-Interface-Extensions.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1271"><a href="#sec-Interface-Extensions.Type-Validation" title="link to this subsection">Type Validation</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1273">Interface type extensions have the potential to be invalid if incorrectly defined.</p> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1275">The named type must already be defined and must be an Interface type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1276-L1277">The fields of an Interface type extension must have unique names; no two fields may share the same name.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1278-L1279">Any fields of an Interface type extension must not be already defined on the original Interface type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1280-L1282">Any Object or Interface type which implemented the original Interface type must also be a super-set of the fields of the Interface type extension (which may be due to Object type extension).</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1283-L1284">Any non-repeatable directives provided must not already apply to the original Interface type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1285-L1286">The resulting extended Interface type must be a super-set of all Interfaces it implements.</li> </ol> </section> </section> </section> <section id="sec-Unions" secid="3.8"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L1289"><span class="spec-secid" title="link to this section"><a href="#sec-Unions">3.8</a></span>Unions</h2> <div class="spec-production" id="UnionTypeDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L1291"> <span class="spec-nt"><a href="#UnionTypeDefinition" data-name="UnionTypeDefinition">UnionTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">union</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#UnionMemberTypes" data-name="UnionMemberTypes">UnionMemberTypes</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="UnionMemberTypes" data-source="spec/Section%203%20--%20Type%20System.md#L1293-L1295"> <span class="spec-nt"><a href="#UnionMemberTypes" data-name="UnionMemberTypes">UnionMemberTypes</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#UnionMemberTypes" data-name="UnionMemberTypes">UnionMemberTypes</a></span><span class="spec-t">|</span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> <div class="spec-rhs"><span class="spec-t">=</span><span class="spec-quantified"><span class="spec-t">|</span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L1297-L1300">GraphQL Unions represent an object that could be one of a list of GraphQL Object types, but provides for no guaranteed fields between those types. They also differ from interfaces in that Object types declare what interfaces they implement, but are not aware of what unions contain them.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1302-L1307">With interfaces and objects, only those fields defined on the type can be queried directly; to query other fields on an interface, typed fragments must be used. This is the same as for unions, but unions do not define any fields, so <strong>no</strong> fields may be queried on this type without the use of type refining fragments or inline fragments (with the exception of the meta-field <var data-name="__typename">__typename</var>).</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1309">For example, we might define the following types:</p> <pre id="example-255de" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1311-L1327"><a href="#example-255de">Example № 74</a><code><span class="token keyword">union</span> <span class="token class-name">SearchResult</span> <span class="token operator">=</span> <span class="token property">Photo</span> <span class="token operator">|</span> <span class="token property">Person</span> <span class="token keyword">type</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">age</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">Photo</span> <span class="token punctuation">{</span> <span class="token attr-name">height</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token attr-name">width</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">SearchQuery</span> <span class="token punctuation">{</span> <span class="token attr-name">firstSearchResult</span><span class="token punctuation">:</span> <span class="token class-name">SearchResult</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1329-L1331">In this example, a query operation wants the name if the result was a Person, and the height if it was a photo. However because a union itself defines no fields, this could be ambiguous and is invalid.</p> <pre id="example-38dc1" class="spec-counter-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1333-L1340"><a href="#example-38dc1">Counter Example № 75</a><code><span class="token punctuation">{</span> <span class="token object">firstSearchResult</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token property">height</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1342">A valid operation includes typed fragments (in this example, inline fragments):</p> <pre id="example-f8163" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1344-L1355"><a href="#example-f8163">Example № 76</a><code><span class="token punctuation">{</span> <span class="token object">firstSearchResult</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Photo</span> <span class="token punctuation">{</span> <span class="token property">height</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1357-L1358">Union members may be defined with an optional leading <code>|</code> character to aid formatting when representing a longer list of possible types:</p> <pre id="example-0fbc6" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1360-L1364"><a href="#example-0fbc6">Example № 77</a><code><span class="token keyword">union</span> <span class="token class-name">SearchResult</span> <span class="token operator">=</span> <span class="token operator">|</span> <span class="token property">Photo</span> <span class="token operator">|</span> <span class="token property">Person</span> </code></pre> <section id="sec-Unions.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1366"><a href="#sec-Unions.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1368-L1370">The union type should have some way of determining which object a given result corresponds to. Once it has done so, the result coercion of the union is the same as the result coercion of the object.</p> </section> <section id="sec-Unions.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1372"><a href="#sec-Unions.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1374">Unions are never valid inputs.</p> </section> <section id="sec-Unions.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1376"><a href="#sec-Unions.Type-Validation" title="link to this subsection">Type Validation</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1378">Union types have the potential to be invalid if incorrectly defined.</p> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1380">A Union type must include one or more unique member types.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1381-L1383">The member types of a Union type must all be Object base types; Scalar, Interface and Union types must not be member types of a Union. Similarly, wrapping types must not be member types of a Union.</li> </ol> </section> <section id="sec-Union-Extensions" secid="3.8.1"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L1386"><span class="spec-secid" title="link to this section"><a href="#sec-Union-Extensions">3.8.1</a></span>Union Extensions</h3> <div class="spec-production" id="UnionTypeExtension" data-source="spec/Section%203%20--%20Type%20System.md#L1388-L1390"> <span class="spec-nt"><a href="#UnionTypeExtension" data-name="UnionTypeExtension">UnionTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">union</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#UnionMemberTypes" data-name="UnionMemberTypes">UnionMemberTypes</a></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">union</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L1392-L1395">Union type extensions are used to represent a union type which has been extended from some original union type. For example, this might be used to represent additional local data, or by a GraphQL service which is itself an extension of another GraphQL service.</p> <section id="sec-Union-Extensions.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1397"><a href="#sec-Union-Extensions.Type-Validation" title="link to this subsection">Type Validation</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1399">Union type extensions have the potential to be invalid if incorrectly defined.</p> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1401">The named type must already be defined and must be a Union type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1402-L1404">The member types of a Union type extension must all be Object base types; Scalar, Interface and Union types must not be member types of a Union. Similarly, wrapping types must not be member types of a Union.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1405">All member types of a Union type extension must be unique.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1406-L1407">All member types of a Union type extension must not already be a member of the original Union type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1408-L1409">Any non-repeatable directives provided must not already apply to the original Union type.</li> </ol> </section> </section> </section> <section id="sec-Enums" secid="3.9"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L1411"><span class="spec-secid" title="link to this section"><a href="#sec-Enums">3.9</a></span>Enums</h2> <div class="spec-production" id="EnumTypeDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L1413-L1415"> <span class="spec-nt"><a href="#EnumTypeDefinition" data-name="EnumTypeDefinition">EnumTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">enum</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#EnumValuesDefinition" data-name="EnumValuesDefinition">EnumValuesDefinition</a></span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">enum</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="EnumValuesDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L1417"> <span class="spec-nt"><a href="#EnumValuesDefinition" data-name="EnumValuesDefinition">EnumValuesDefinition</a></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#EnumValueDefinition" data-name="EnumValueDefinition">EnumValueDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <div class="spec-production" id="EnumValueDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L1419"> <span class="spec-nt"><a href="#EnumValueDefinition" data-name="EnumValueDefinition">EnumValueDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#EnumValue" data-name="EnumValue">EnumValue</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L1421-L1422">GraphQL Enum types, like Scalar types, also represent leaf values in a GraphQL type system. However Enum types describe the set of possible values.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1424-L1425">Enums are not references for a numeric value, but are unique values in their own right. They may serialize as a string: the name of the represented value.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1427">In this example, an Enum type called <code>Direction</code> is defined:</p> <pre id="example-36555" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1429-L1436"><a href="#example-36555">Example № 78</a><code><span class="token keyword">enum</span> <span class="token class-name">Direction</span> <span class="token punctuation">{</span> <span class="token constant">NORTH</span> <span class="token constant">EAST</span> <span class="token constant">SOUTH</span> <span class="token constant">WEST</span> <span class="token punctuation">}</span> </code></pre> <section id="sec-Enums.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1438"><a href="#sec-Enums.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1440-L1441">GraphQL services must return one of the defined set of possible values. If a reasonable coercion is not possible they must raise a field error.</p> </section> <section id="sec-Enums.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1443"><a href="#sec-Enums.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1445-L1446">GraphQL has a constant literal to represent enum input values. GraphQL string literals must not be accepted as an enum input and instead raise a request error.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1448-L1452">Variable transport serializations which have a different representation for non-string symbolic values (for example, <a href="https://github.com/edn-format/edn">EDN</a>) should only allow such values as enum input values. Otherwise, for most transport serializations that do not, strings may be interpreted as the enum input value with the same name.</p> </section> <section id="sec-Enums.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1454"><a href="#sec-Enums.Type-Validation" title="link to this subsection">Type Validation</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1456">Enum types have the potential to be invalid if incorrectly defined.</p> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1458">An Enum type must define one or more unique enum values.</li> </ol> </section> <section id="sec-Enum-Extensions" secid="3.9.1"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L1461"><span class="spec-secid" title="link to this section"><a href="#sec-Enum-Extensions">3.9.1</a></span>Enum Extensions</h3> <div class="spec-production" id="EnumTypeExtension" data-source="spec/Section%203%20--%20Type%20System.md#L1463-L1465"> <span class="spec-nt"><a href="#EnumTypeExtension" data-name="EnumTypeExtension">EnumTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">enum</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#EnumValuesDefinition" data-name="EnumValuesDefinition">EnumValuesDefinition</a></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">enum</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L1467-L1470">Enum type extensions are used to represent an enum type which has been extended from some original enum type. For example, this might be used to represent additional local data, or by a GraphQL service which is itself an extension of another GraphQL service.</p> <section id="sec-Enum-Extensions.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1472"><a href="#sec-Enum-Extensions.Type-Validation" title="link to this subsection">Type Validation</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1474">Enum type extensions have the potential to be invalid if incorrectly defined.</p> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1476">The named type must already be defined and must be an Enum type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1477">All values of an Enum type extension must be unique.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1478-L1479">All values of an Enum type extension must not already be a value of the original Enum.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1480-L1481">Any non-repeatable directives provided must not already apply to the original Enum type.</li> </ol> </section> </section> </section> <section id="sec-Input-Objects" secid="3.10"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L1484"><span class="spec-secid" title="link to this section"><a href="#sec-Input-Objects">3.10</a></span>Input Objects</h2> <div class="spec-production" id="InputObjectTypeDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L1486-L1488"> <span class="spec-nt"><a href="#InputObjectTypeDefinition" data-name="InputObjectTypeDefinition">InputObjectTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">input</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#InputFieldsDefinition" data-name="InputFieldsDefinition">InputFieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">input</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="InputFieldsDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L1490"> <span class="spec-nt"><a href="#InputFieldsDefinition" data-name="InputFieldsDefinition">InputFieldsDefinition</a></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#InputValueDefinition" data-name="InputValueDefinition">InputValueDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L1492-L1493">Fields may accept arguments to configure their behavior. These inputs are often scalars or enums, but they sometimes need to represent more complex values.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1495-L1497">A GraphQL Input Object defines a set of input fields; the input fields are either scalars, enums, or other input objects. This allows arguments to accept arbitrarily complex structs.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1499">In this example, an Input Object called <code>Point2D</code> describes <code>x</code> and <code>y</code> inputs:</p> <pre id="example-45e4e" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1501-L1506"><a href="#example-45e4e">Example № 79</a><code><span class="token keyword">input</span> <span class="token object">Point2D</span> <span class="token punctuation">{</span> <span class="token attr-name">x</span><span class="token punctuation">:</span> <span class="token scalar">Float</span> <span class="token attr-name">y</span><span class="token punctuation">:</span> <span class="token scalar">Float</span> <span class="token punctuation">}</span> </code></pre> <div id="note-7a6d2" class="spec-note" data-source="spec/Section%203%20--%20Type%20System.md#L1508-L1512"> <a href="#note-7a6d2">Note</a> The GraphQL Object type (<span class="spec-nt"><a href="#ObjectTypeDefinition" data-name="ObjectTypeDefinition">ObjectTypeDefinition</a></span>) defined above is inappropriate for re-use here, because Object types can contain fields that define arguments or contain references to interfaces and unions, neither of which is appropriate for use as an input argument. For this reason, input objects have a separate type in the system.</div> <section id="sec-Input-Objects.Circular-References" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1514"><a href="#sec-Input-Objects.Circular-References" title="link to this subsection">Circular References</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1516-L1518">Input Objects are allowed to reference other Input Objects as field types. A circular reference occurs when an Input Object references itself either directly or through referenced Input Objects.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1520-L1522">Circular references are generally allowed, however they may not be defined as an unbroken chain of Non-Null singular fields. Such Input Objects are invalid because there is no way to provide a legal value for them.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1524-L1525">This example of a circularly-referenced input type is valid as the field <code>self</code> may be omitted or the value <span class="spec-keyword">null</span>.</p> <pre id="example-e9cda" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1527-L1532"><a href="#example-e9cda">Example № 80</a><code><span class="token keyword">input</span> <span class="token object">Example</span> <span class="token punctuation">{</span> <span class="token attr-name">self</span><span class="token punctuation">:</span> <span class="token class-name">Example</span> <span class="token attr-name">value</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1534">This example is also valid as the field <code>self</code> may be an empty List.</p> <pre id="example-2f832" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1536-L1541"><a href="#example-2f832">Example № 81</a><code><span class="token keyword">input</span> <span class="token object">Example</span> <span class="token punctuation">{</span> <span class="token attr-name">self</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">Example</span><span class="token operator">!</span><span class="token punctuation">]</span><span class="token operator">!</span> <span class="token attr-name">value</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1543-L1544">This example of a circularly-referenced input type is invalid as the field <code>self</code> cannot be provided a finite value.</p> <pre id="example-e70c9" class="spec-counter-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1546-L1551"><a href="#example-e70c9">Counter Example № 82</a><code><span class="token keyword">input</span> <span class="token object">Example</span> <span class="token punctuation">{</span> <span class="token attr-name">value</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">self</span><span class="token punctuation">:</span> <span class="token class-name">Example</span><span class="token operator">!</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1553-L1554">This example is also invalid, as there is a non-null singular circular reference via the <code>First.second</code> and <code>Second.first</code> fields.</p> <pre id="example-31c9f" class="spec-counter-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1556-L1566"><a href="#example-31c9f">Counter Example № 83</a><code><span class="token keyword">input</span> <span class="token object">First</span> <span class="token punctuation">{</span> <span class="token attr-name">second</span><span class="token punctuation">:</span> <span class="token class-name">Second</span><span class="token operator">!</span> <span class="token attr-name">value</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">input</span> <span class="token object">Second</span> <span class="token punctuation">{</span> <span class="token attr-name">first</span><span class="token punctuation">:</span> <span class="token class-name">First</span><span class="token operator">!</span> <span class="token attr-name">value</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-Input-Objects.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1568"><a href="#sec-Input-Objects.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1570-L1571">An input object is never a valid result. Input Object types cannot be the return type of an Object or Interface field.</p> </section> <section id="sec-Input-Objects.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1573"><a href="#sec-Input-Objects.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1575-L1579">The value for an input object should be an input object literal or an unordered map supplied by a variable, otherwise a request error must be raised. In either case, the input object literal or unordered map must not contain any entries with names not defined by a field of this input object type, otherwise a response error must be raised.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1581-L1583">The result of coercion is an unordered map with an entry for each field both defined by the input object type and for which a value exists. The resulting map is constructed with the following rules:</p> <ul> <li data-source="spec/Section%203%20--%20Type%20System.md#L1585-L1589">If no value is provided for a defined input object field and that field definition provides a default value, the default value should be used. If no default value is provided and the input object field’s type is non-null, an error should be raised. Otherwise, if the field is not required, then no entry is added to the coerced unordered map.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1591-L1594">If the value <span class="spec-keyword">null</span> was provided for an input object field, and the field’s type is not a non-null type, an entry in the coerced unordered map is given the value <span class="spec-keyword">null</span>. In other words, there is a semantic difference between the explicitly provided value <span class="spec-keyword">null</span> versus having not provided a value.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1596-L1598">If a literal value is provided for an input object field, an entry in the coerced unordered map is given the result of coercing that value according to the input coercion rules for the type of that field.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1600-L1605">If a variable is provided for an input object field, the runtime value of that variable must be used. If the runtime value is <span class="spec-keyword">null</span> and the field type is non-null, a field error must be raised. If no runtime value is provided, the variable definition’s default value should be used. If the variable definition does not provide a default value, the input object field definition’s default value should be used.</li> </ul> <p data-source="spec/Section%203%20--%20Type%20System.md#L1607-L1608">Following are examples of input coercion for an input object type with a <code>String</code> field <code>a</code> and a required (non-null) <code>Int!</code> field <code>b</code>:</p> <pre id="example-704b8" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1610-L1615"><a href="#example-704b8">Example № 84</a><code><span class="token keyword">input</span> <span class="token atom-input class-name">ExampleInput</span><span class="token object">Object</span> <span class="token punctuation">{</span> <span class="token attr-name">a</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">b</span><span class="token punctuation">:</span> <span class="token scalar">Int</span><span class="token operator">!</span> <span class="token punctuation">}</span> </code></pre> <table> <thead> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1617"> <th>Literal Value</th> <th>Variables</th> <th>Coerced Value</th> </tr> </thead> <tbody> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1619"> <td><code>{ a: "abc", b: 123 }</code></td> <td><code>{}</code></td> <td><code>{ a: "abc", b: 123 }</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1620"> <td><code>{ a: null, b: 123 }</code></td> <td><code>{}</code></td> <td><code>{ a: null, b: 123 }</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1621"> <td><code>{ b: 123 }</code></td> <td><code>{}</code></td> <td><code>{ b: 123 }</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1622"> <td><code>{ a: $var, b: 123 }</code></td> <td><code>{ var: null }</code></td> <td><code>{ a: null, b: 123 }</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1623"> <td><code>{ a: $var, b: 123 }</code></td> <td><code>{}</code></td> <td><code>{ b: 123 }</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1624"> <td><code>{ b: $var }</code></td> <td><code>{ var: 123 }</code></td> <td><code>{ b: 123 }</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1625"> <td><code>$var</code></td> <td><code>{ var: { b: 123 } }</code></td> <td><code>{ b: 123 }</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1626"> <td><code>"abc123"</code></td> <td><code>{}</code></td> <td>Error: Incorrect value</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1627"> <td><code>$var</code></td> <td><code>{ var: "abc123" }</code></td> <td>Error: Incorrect value</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1628"> <td><code>{ a: "abc", b: "123" }</code></td> <td><code>{}</code></td> <td>Error: Incorrect value for field <var data-name="b">b</var></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1629"> <td><code>{ a: "abc" }</code></td> <td><code>{}</code></td> <td>Error: Missing required field <var data-name="b">b</var></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1630"> <td><code>{ b: $var }</code></td> <td><code>{}</code></td> <td>Error: Missing required field <var data-name="b">b</var>.</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1631"> <td><code>$var</code></td> <td><code>{ var: { a: "abc" } }</code></td> <td>Error: Missing required field <var data-name="b">b</var></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1632"> <td><code>{ a: "abc", b: null }</code></td> <td><code>{}</code></td> <td>Error: <var data-name="b">b</var> must be non-null.</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1633"> <td><code>{ b: $var }</code></td> <td><code>{ var: null }</code></td> <td>Error: <var data-name="b">b</var> must be non-null.</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1634"> <td><code>{ b: 123, c: "xyz" }</code></td> <td><code>{}</code></td> <td>Error: Unexpected field <var data-name="c">c</var></td> </tr> </tbody> </table> </section> <section id="sec-Input-Objects.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1636"><a href="#sec-Input-Objects.Type-Validation" title="link to this subsection">Type Validation</a></h6> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1638">An Input Object type must define one or more input fields.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1639-L1645">For each input field of an Input Object type:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1640-L1641">The input field must have a unique name within that Input Object type; no two input fields may share the same name.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1642-L1643">The input field must not have a name which begins with the characters <span class="spec-string">"__"</span> (two underscores).</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1644-L1645">The input field must accept a type where <span class="spec-call"><a href="#IsInputType()" data-name="IsInputType">IsInputType</a>(<var data-name="inputFieldType">inputFieldType</var>)</span> returns <span class="spec-keyword">true</span>.</li> </ol> </li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1646-L1648">If an Input Object references itself either directly or through referenced Input Objects, at least one of the fields in the chain of references must be either a nullable or a List type.</li> </ol> </section> <section id="sec-Input-Object-Extensions" secid="3.10.1"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L1651"><span class="spec-secid" title="link to this section"><a href="#sec-Input-Object-Extensions">3.10.1</a></span>Input Object Extensions</h3> <div class="spec-production" id="InputObjectTypeExtension" data-source="spec/Section%203%20--%20Type%20System.md#L1653-L1655"> <span class="spec-nt"><a href="#InputObjectTypeExtension" data-name="InputObjectTypeExtension">InputObjectTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">input</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#InputFieldsDefinition" data-name="InputFieldsDefinition">InputFieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">input</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L1657-L1659">Input object type extensions are used to represent an input object type which has been extended from some original input object type. For example, this might be used by a GraphQL service which is itself an extension of another GraphQL service.</p> <section id="sec-Input-Object-Extensions.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1661"><a href="#sec-Input-Object-Extensions.Type-Validation" title="link to this subsection">Type Validation</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1663">Input object type extensions have the potential to be invalid if incorrectly defined.</p> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1665">The named type must already be defined and must be a Input Object type.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1666">All fields of an Input Object type extension must have unique names.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1667-L1668">All fields of an Input Object type extension must not already be a field of the original Input Object.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1669-L1670">Any non-repeatable directives provided must not already apply to the original Input Object type.</li> </ol> </section> </section> </section> <section id="sec-List" secid="3.11"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L1673"><span class="spec-secid" title="link to this section"><a href="#sec-List">3.11</a></span>List</h2> <p data-source="spec/Section%203%20--%20Type%20System.md#L1675-L1678">A GraphQL list is a special collection type which declares the type of each item in the List (referred to as the <em>item type</em> of the list). List values are serialized as ordered lists, where each item in the list is serialized as per the item type.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1680-L1681">To denote that a field uses a List type the item type is wrapped in square brackets like this: <code>pets: [Pet]</code>. Nesting lists is allowed: <code>matrix: [[Int]]</code>.</p> <section id="sec-List.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1683"><a href="#sec-List.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1685-L1690">GraphQL services must return an ordered list as the result of a list type. Each item in the list must be the result of a result coercion of the item type. If a reasonable coercion is not possible it must raise a field error. In particular, if a non-list is returned, the coercion should fail, as this indicates a mismatch in expectations between the type system and the implementation.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1692-L1696">If a list’s item type is nullable, then errors occurring during preparation or coercion of an individual item in the list must result in a the value <span class="spec-keyword">null</span> at that position in the list along with a field error added to the response. If a list’s item type is non-null, a field error occurring at an individual item in the list must result in a field error for the entire list.</p> <div id="note-6f554" class="spec-note" data-source="spec/Section%203%20--%20Type%20System.md#L1698-L1699"> <a href="#note-6f554">Note</a> See <a href="#sec-Handling-Field-Errors">Handling Field Errors</a> for more about this behavior.</div> </section> <section id="sec-List.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1701"><a href="#sec-List.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1703-L1704">When expected as an input, list values are accepted only when each item in the list can be accepted by the list’s item type.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1706-L1709">If the value passed as an input to a list type is <em>not</em> a list and not the <span class="spec-keyword">null</span> value, then the result of input coercion is a list of size one, where the single item value is the result of input coercion for the list’s item type on the provided value (note this may apply recursively for nested lists).</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1711-L1714">This allows inputs which accept one or many arguments (sometimes referred to as “var args”) to declare their input type as a list while for the common case of a single value, a client can just pass that value directly rather than constructing the list.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1716">Following are examples of input coercion with various list types and values:</p> <table> <thead> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1718"> <th>Expected Type</th> <th>Provided Value</th> <th>Coerced Value</th> </tr> </thead> <tbody> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1720"> <td><code>[Int]</code></td> <td><code>[1, 2, 3]</code></td> <td><code>[1, 2, 3]</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1721"> <td><code>[Int]</code></td> <td><code>[1, "b", true]</code></td> <td>Error: Incorrect item value</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1722"> <td><code>[Int]</code></td> <td><code>1</code></td> <td><code>[1]</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1723"> <td><code>[Int]</code></td> <td><code>null</code></td> <td><code>null</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1724"> <td><code>[[Int]]</code></td> <td><code>[[1], [2, 3]]</code></td> <td><code>[[1], [2, 3]]</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1725"> <td><code>[[Int]]</code></td> <td><code>[1, 2, 3]</code></td> <td>Error: Incorrect item value</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1726"> <td><code>[[Int]]</code></td> <td><code>1</code></td> <td><code>[[1]]</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1727"> <td><code>[[Int]]</code></td> <td><code>null</code></td> <td><code>null</code></td> </tr> </tbody> </table> </section> </section> <section id="sec-Non-Null" secid="3.12"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L1730"><span class="spec-secid" title="link to this section"><a href="#sec-Non-Null">3.12</a></span>Non-Null</h2> <p data-source="spec/Section%203%20--%20Type%20System.md#L1732-L1738">By default, all types in GraphQL are nullable; the <span class="spec-keyword">null</span> value is a valid response for all of the above types. To declare a type that disallows null, the GraphQL Non-Null type can be used. This type wraps an underlying type, and this type acts identically to that wrapped type, with the exception that <span class="spec-keyword">null</span> is not a valid response for the wrapping type. A trailing exclamation mark is used to denote a field that uses a Non-Null type like this: <code>name: String!</code>.</p> <section id="sec-Non-Null.Nullable-vs-Optional" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1740"><a href="#sec-Non-Null.Nullable-vs-Optional" title="link to this subsection">Nullable vs. Optional</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1742-L1744">Fields are <em>always</em> optional within the context of a selection set, a field may be omitted and the selection set is still valid. However fields that return Non-Null types will never return the value <span class="spec-keyword">null</span> if queried.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1746-L1749">Inputs (such as field arguments), are always optional by default. However a non-null input type is required. In addition to not accepting the value <span class="spec-keyword">null</span>, it also does not accept omission. For the sake of simplicity nullable types are always optional and non-null types are always required.</p> </section> <section id="sec-Non-Null.Result-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1751"><a href="#sec-Non-Null.Result-Coercion" title="link to this subsection">Result Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1753-L1757">In all of the above result coercions, <span class="spec-keyword">null</span> was considered a valid value. To coerce the result of a Non-Null type, the coercion of the wrapped type should be performed. If that result was not <span class="spec-keyword">null</span>, then the result of coercing the Non-Null type is that result. If that result was <span class="spec-keyword">null</span>, then a field error must be raised.</p> <div id="note-ad65b" class="spec-note" data-source="spec/Section%203%20--%20Type%20System.md#L1759-L1761"> <a href="#note-ad65b">Note</a> When a field error is raised on a non-null value, the error propagates to the parent field. For more information on this process, see “Errors and Non-Nullability” within the Execution section.</div> </section> <section id="sec-Non-Null.Input-Coercion" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1763"><a href="#sec-Non-Null.Input-Coercion" title="link to this subsection">Input Coercion</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1765-L1768">If an argument or input-object field of a Non-Null type is not provided, is provided with the literal value <span class="spec-keyword">null</span>, or is provided with a variable that was either not provided a value at runtime, or was provided the value <span class="spec-keyword">null</span>, then a request error must be raised.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1770-L1772">If the value provided to the Non-Null type is provided with a literal value other than <span class="spec-keyword">null</span>, or a Non-Null variable value, it is coerced using the input coercion for the wrapped type.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1774">A non-null argument cannot be omitted:</p> <pre id="example-32bbf" class="spec-counter-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1776-L1780"><a href="#example-32bbf">Counter Example № 85</a><code><span class="token punctuation">{</span> <span class="token property">fieldWithNonNullArg</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1782">The value <span class="spec-keyword">null</span> cannot be provided to a non-null argument:</p> <pre id="example-da489" class="spec-counter-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1784-L1788"><a href="#example-da489">Counter Example № 86</a><code><span class="token punctuation">{</span> <span class="token property-query">fieldWithNonNullArg</span><span class="token punctuation">(</span><span class="token attr-name">nonNullArg</span><span class="token punctuation">:</span> <span class="token property">null</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1790">A variable of a nullable type cannot be provided to a non-null argument:</p> <pre id="example-6d129" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1792-L1796"><a href="#example-6d129">Example № 87</a><code><span class="token keyword">query</span> <span class="token definition-query function">withNullableVariable</span><span class="token punctuation">(</span><span class="token variable">$var</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property-query">fieldWithNonNullArg</span><span class="token punctuation">(</span><span class="token attr-name">nonNullArg</span><span class="token punctuation">:</span> <span class="token variable">$var</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <div id="note-97a45" class="spec-note" data-source="spec/Section%203%20--%20Type%20System.md#L1798-L1799"> <a href="#note-97a45">Note</a> The Validation section defines providing a nullable variable type to a non-null input type as invalid.</div> </section> <section id="sec-Non-Null.Type-Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1801"><a href="#sec-Non-Null.Type-Validation" title="link to this subsection">Type Validation</a></h6> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1803">A Non-Null type must not wrap another Non-Null type.</li> </ol> </section> <section id="sec-Combining-List-and-Non-Null" secid="3.12.1"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L1806"><span class="spec-secid" title="link to this section"><a href="#sec-Combining-List-and-Non-Null">3.12.1</a></span>Combining List and Non-Null</h3> <p data-source="spec/Section%203%20--%20Type%20System.md#L1808-L1810">The List and Non-Null wrapping types can compose, representing more complex types. The rules for result coercion and input coercion of Lists and Non-Null types apply in a recursive fashion.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1812-L1815">For example if the inner item type of a List is Non-Null (e.g. <code>[T!]</code>), then that List may not contain any <span class="spec-keyword">null</span> items. However if the inner type of a Non-Null is a List (e.g. <code>[T]!</code>), then <span class="spec-keyword">null</span> is not accepted however an empty list is accepted.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1817">Following are examples of result coercion with various types and values:</p> <table> <thead> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1819"> <th>Expected Type</th> <th>Internal Value</th> <th>Coerced Result</th> </tr> </thead> <tbody> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1821"> <td><code>[Int]</code></td> <td><code>[1, 2, 3]</code></td> <td><code>[1, 2, 3]</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1822"> <td><code>[Int]</code></td> <td><code>null</code></td> <td><code>null</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1823"> <td><code>[Int]</code></td> <td><code>[1, 2, null]</code></td> <td><code>[1, 2, null]</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1824"> <td><code>[Int]</code></td> <td><code>[1, 2, Error]</code></td> <td><code>[1, 2, null]</code> (With logged error)</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1825"> <td><code>[Int]!</code></td> <td><code>[1, 2, 3]</code></td> <td><code>[1, 2, 3]</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1826"> <td><code>[Int]!</code></td> <td><code>null</code></td> <td>Error: Value cannot be null</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1827"> <td><code>[Int]!</code></td> <td><code>[1, 2, null]</code></td> <td><code>[1, 2, null]</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1828"> <td><code>[Int]!</code></td> <td><code>[1, 2, Error]</code></td> <td><code>[1, 2, null]</code> (With logged error)</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1829"> <td><code>[Int!]</code></td> <td><code>[1, 2, 3]</code></td> <td><code>[1, 2, 3]</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1830"> <td><code>[Int!]</code></td> <td><code>null</code></td> <td><code>null</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1831"> <td><code>[Int!]</code></td> <td><code>[1, 2, null]</code></td> <td><code>null</code> (With logged coercion error)</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1832"> <td><code>[Int!]</code></td> <td><code>[1, 2, Error]</code></td> <td><code>null</code> (With logged error)</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1833"> <td><code>[Int!]!</code></td> <td><code>[1, 2, 3]</code></td> <td><code>[1, 2, 3]</code></td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1834"> <td><code>[Int!]!</code></td> <td><code>null</code></td> <td>Error: Value cannot be null</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1835"> <td><code>[Int!]!</code></td> <td><code>[1, 2, null]</code></td> <td>Error: Item cannot be null</td> </tr> <tr data-source="spec/Section%203%20--%20Type%20System.md#L1836"> <td><code>[Int!]!</code></td> <td><code>[1, 2, Error]</code></td> <td>Error: Error occurred in item</td> </tr> </tbody> </table> </section> </section> <section id="sec-Type-System.Directives" secid="3.13"> <h2 data-source="spec/Section%203%20--%20Type%20System.md#L1839"><span class="spec-secid" title="link to this section"><a href="#sec-Type-System.Directives">3.13</a></span>Directives</h2> <div class="spec-production" id="DirectiveDefinition" data-source="spec/Section%203%20--%20Type%20System.md#L1841"> <span class="spec-nt"><a href="#DirectiveDefinition" data-name="DirectiveDefinition">DirectiveDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">directive</span><span class="spec-t">@</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ArgumentsDefinition" data-name="ArgumentsDefinition">ArgumentsDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-t">repeatable</span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">on</span><span class="spec-nt"><a href="#DirectiveLocations" data-name="DirectiveLocations">DirectiveLocations</a></span></div> </div> <div class="spec-production" id="DirectiveLocations" data-source="spec/Section%203%20--%20Type%20System.md#L1843-L1845"> <span class="spec-nt"><a href="#DirectiveLocations" data-name="DirectiveLocations">DirectiveLocations</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#DirectiveLocations" data-name="DirectiveLocations">DirectiveLocations</a></span><span class="spec-t">|</span><span class="spec-nt"><a href="#DirectiveLocation" data-name="DirectiveLocation">DirectiveLocation</a></span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-t">|</span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#DirectiveLocation" data-name="DirectiveLocation">DirectiveLocation</a></span></div> </div> <div class="spec-production" id="DirectiveLocation" data-source="spec/Section%203%20--%20Type%20System.md#L1847-L1849"> <span class="spec-nt"><a href="#DirectiveLocation" data-name="DirectiveLocation">DirectiveLocation</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ExecutableDirectiveLocation" data-name="ExecutableDirectiveLocation">ExecutableDirectiveLocation</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#TypeSystemDirectiveLocation" data-name="TypeSystemDirectiveLocation">TypeSystemDirectiveLocation</a></span></div> </div> <div class="spec-production" id="ExecutableDirectiveLocation" data-source="spec/Section%203%20--%20Type%20System.md#L1851-L1859"> <span class="spec-nt"><a href="#ExecutableDirectiveLocation" data-name="ExecutableDirectiveLocation">ExecutableDirectiveLocation</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">QUERY</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">MUTATION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">SUBSCRIPTION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">FIELD</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">FRAGMENT_DEFINITION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">FRAGMENT_SPREAD</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">INLINE_FRAGMENT</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">VARIABLE_DEFINITION</span></td></tr> </table></div></div> </div> <div class="spec-production" id="TypeSystemDirectiveLocation" data-source="spec/Section%203%20--%20Type%20System.md#L1861-L1872"> <span class="spec-nt"><a href="#TypeSystemDirectiveLocation" data-name="TypeSystemDirectiveLocation">TypeSystemDirectiveLocation</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">SCHEMA</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">SCALAR</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">OBJECT</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">FIELD_DEFINITION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">ARGUMENT_DEFINITION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">INTERFACE</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">UNION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">ENUM</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">ENUM_VALUE</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">INPUT_OBJECT</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">INPUT_FIELD_DEFINITION</span></td></tr> </table></div></div> </div> <p data-source="spec/Section%203%20--%20Type%20System.md#L1874-L1876">A GraphQL schema describes directives which are used to annotate various parts of a GraphQL document as an indicator that they should be evaluated differently by a validator, executor, or client tool such as a code generator.</p> <section id="sec-Type-System.Directives.Built-in-Directives" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1878"><a href="#sec-Type-System.Directives.Built-in-Directives" title="link to this subsection">Built-in Directives</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1880">A <dfn id="built-in-directive"><a href="#built-in-directive" data-name="built-in-directive">built-in directive</a></dfn> is any directive defined within this specification.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1882">GraphQL implementations should provide the <code>@skip</code> and <code>@include</code> directives.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1884-L1886">GraphQL implementations that support the type system definition language must provide the <code>@deprecated</code> directive if representing deprecated portions of the schema.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1888-L1890">GraphQL implementations that support the type system definition language should provide the <code>@specifiedBy</code> directive if representing custom scalar definitions.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1892-L1893">When representing a GraphQL schema using the type system definition language any <span class="spec-ref"><a href="#built-in-directive" data-name="built-in-directive">built-in directive</a></span> may be omitted for brevity.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1895-L1896">When introspecting a GraphQL service all provided directives, including any <span class="spec-ref"><a href="#built-in-directive" data-name="built-in-directive">built-in directive</a></span>, must be included in the set of returned directives.</p> </section> <section id="sec-Type-System.Directives.Custom-Directives" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1898"><a href="#sec-Type-System.Directives.Custom-Directives" title="link to this subsection">Custom Directives</a></h6> <p data-source="spec/Section%203%20--%20Type%20System.md#L1900-L1902">GraphQL services and client tooling may provide any additional <dfn id="custom-directive"><a href="#custom-directive" data-name="custom-directive">custom directive</a></dfn> beyond those defined in this document. Directives are the preferred way to extend GraphQL with custom or experimental behavior.</p> <div id="note-39239" class="spec-note" data-source="spec/Section%203%20--%20Type%20System.md#L1904-L1911"> <a href="#note-39239">Note</a> When defining a <span class="spec-ref"><a href="#custom-directive" data-name="custom-directive">custom directive</a></span>, it is recommended to prefix the directive’s name to make its scope of usage clear and to prevent a collision with <span class="spec-ref"><a href="#built-in-directive" data-name="built-in-directive">built-in directive</a></span> which may be specified by future versions of this document (which will not include <code>_</code> in their name). For example, a <span class="spec-ref"><a href="#custom-directive" data-name="custom-directive">custom directive</a></span> used by Facebook’s GraphQL service should be named <code>@fb_auth</code> instead of <code>@auth</code>. This is especially recommended for proposed additions to this specification which can change during the <a href="https://github.com/graphql/graphql-spec/blob/main/CONTRIBUTING.md">RFC process</a>. For example a work in progress version of <code>@live</code> should be named <code>@rfc_live</code>.</div> <p data-source="spec/Section%203%20--%20Type%20System.md#L1913-L1914">Directives must only be used in the locations they are declared to belong in. In this example, a directive is defined which can be used to annotate a field:</p> <pre id="example-060af" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1916-L1922"><a href="#example-060af">Example № 88</a><code><span class="token keyword">directive</span> <span class="token directive function">@example</span> <span class="token keyword">on</span> <span class="token constant">FIELD</span> <span class="token keyword">fragment</span> <span class="token fragment function">SomeFragment</span> <span class="token keyword">on</span> <span class="token class-name">SomeType</span> <span class="token punctuation">{</span> <span class="token property">field</span> <span class="token directive function">@example</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1924-L1925">Directive locations may be defined with an optional leading <code>|</code> character to aid formatting when representing a longer list of possible locations:</p> <pre id="example-79697" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1927-L1932"><a href="#example-79697">Example № 89</a><code><span class="token keyword">directive</span> <span class="token directive function">@example</span> <span class="token keyword">on</span> <span class="token operator">|</span> <span class="token constant">FIELD</span> <span class="token operator">|</span> <span class="token constant">FRAGMENT_SPREAD</span> <span class="token operator">|</span> <span class="token constant">INLINE_FRAGMENT</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1934-L1937">Directives can also be used to annotate the type system definition language as well, which can be a useful tool for supplying additional metadata in order to generate GraphQL execution services, produce client generated runtime code, or many other useful extensions of the GraphQL semantics.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1939">In this example, the directive <code>@example</code> annotates field and argument definitions:</p> <pre id="example-c3a06" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1941-L1947"><a href="#example-c3a06">Example № 90</a><code><span class="token keyword">directive</span> <span class="token directive function">@example</span> <span class="token keyword">on</span> <span class="token constant">FIELD_DEFINITION</span> <span class="token operator">|</span> <span class="token constant">ARGUMENT_DEFINITION</span> <span class="token keyword">type</span> <span class="token class-name">SomeType</span> <span class="token punctuation">{</span> <span class="token attr-name">field</span><span class="token punctuation">(</span><span class="token attr-name">arg</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token directive function">@example</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token directive function">@example</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1949-L1953">A directive may be defined as repeatable by including the “repeatable” keyword. Repeatable directives are often useful when the same directive should be used with different arguments at a single location, especially in cases where additional information needs to be provided to a type or schema extension via a directive:</p> <pre id="example-67869" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1955-L1963"><a href="#example-67869">Example № 91</a><code><span class="token keyword">directive</span> <span class="token directive function">@delegateField</span><span class="token punctuation">(</span><span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span><span class="token punctuation">)</span> <span class="token keyword">repeatable</span> <span class="token keyword">on</span> <span class="token constant">OBJECT</span> <span class="token operator">|</span> <span class="token constant">INTERFACE</span> <span class="token keyword">type</span> <span class="token class-name">Book</span> <span class="token directive function">@delegateField</span><span class="token punctuation">(</span><span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token string">"pageCount"</span><span class="token punctuation">)</span> <span class="token directive function">@delegateField</span><span class="token punctuation">(</span><span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token string">"author"</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token scalar">ID</span><span class="token operator">!</span> <span class="token punctuation">}</span> <span class="token keyword">extend</span> <span class="token keyword">type</span> <span class="token class-name">Book</span> <span class="token directive function">@delegateField</span><span class="token punctuation">(</span><span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token string">"index"</span><span class="token punctuation">)</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1965">While defining a directive, it must not reference itself directly or indirectly:</p> <pre id="example-79945" class="spec-counter-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1967-L1969"><a href="#example-79945">Counter Example № 92</a><code><span class="token keyword">directive</span> <span class="token directive function">@invalidExample</span><span class="token punctuation">(</span><span class="token attr-name">arg</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token directive function">@invalidExample</span><span class="token punctuation">)</span> <span class="token keyword">on</span> <span class="token constant">ARGUMENT_DEFINITION</span> </code></pre> <div id="note-921fb" class="spec-note" data-source="spec/Section%203%20--%20Type%20System.md#L1971-L1972"> <a href="#note-921fb">Note</a> The order in which directives appear may be significant, including repeatable directives.</div> </section> <section id="sec-Type-System.Directives.Validation" class="subsec"> <h6 data-source="spec/Section%203%20--%20Type%20System.md#L1974"><a href="#sec-Type-System.Directives.Validation" title="link to this subsection">Validation</a></h6> <ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1976-L1977">A directive definition must not contain the use of a directive which references itself directly.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1978-L1980">A directive definition must not contain the use of a directive which references itself indirectly by referencing a Type or Directive which transitively includes a reference to this directive.</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1981-L1982">The directive must not have a name which begins with the characters <span class="spec-string">"__"</span> (two underscores).</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1983-L1987">For each argument of the directive:<ol> <li data-source="spec/Section%203%20--%20Type%20System.md#L1984-L1985">The argument must not have a name which begins with the characters <span class="spec-string">"__"</span> (two underscores).</li> <li data-source="spec/Section%203%20--%20Type%20System.md#L1986-L1987">The argument must accept a type where <span class="spec-call"><a href="#IsInputType()" data-name="IsInputType">IsInputType</a>(<var data-name="argumentType">argumentType</var>)</span> returns <span class="spec-keyword">true</span>.</li> </ol> </li> </ol> </section> <section id="sec--skip" secid="3.13.1"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L1989"><span class="spec-secid" title="link to this section"><a href="#sec--skip">3.13.1</a></span>@skip</h3> <pre data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L1991-L1993"><code><span class="token keyword">directive</span> <span class="token directive function">@skip</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span><span class="token punctuation">)</span> <span class="token keyword">on</span> <span class="token constant">FIELD</span> <span class="token operator">|</span> <span class="token constant">FRAGMENT_SPREAD</span> <span class="token operator">|</span> <span class="token constant">INLINE_FRAGMENT</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L1995-L1997">The <code>@skip</code> <span class="spec-ref"><a href="#built-in-directive" data-name="built-in-directive">built-in directive</a></span> may be provided for fields, fragment spreads, and inline fragments, and allows for conditional exclusion during execution as described by the <code>if</code> argument.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L1999-L2000">In this example <code>experimentalField</code> will only be queried if the variable <code>$someTest</code> has the value <code>false</code>.</p> <pre id="example-cb6b7" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L2002-L2006"><a href="#example-cb6b7">Example № 93</a><code><span class="token keyword">query</span> <span class="token definition-query function">myQuery</span><span class="token punctuation">(</span><span class="token variable">$someTest</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">experimentalField</span> <span class="token directive function">@skip</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token variable">$someTest</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec--include" secid="3.13.2"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L2009"><span class="spec-secid" title="link to this section"><a href="#sec--include">3.13.2</a></span>@include</h3> <pre data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L2011-L2013"><code><span class="token keyword">directive</span> <span class="token directive function">@include</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span><span class="token punctuation">)</span> <span class="token keyword">on</span> <span class="token constant">FIELD</span> <span class="token operator">|</span> <span class="token constant">FRAGMENT_SPREAD</span> <span class="token operator">|</span> <span class="token constant">INLINE_FRAGMENT</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L2015-L2017">The <code>@include</code> <span class="spec-ref"><a href="#built-in-directive" data-name="built-in-directive">built-in directive</a></span> may be provided for fields, fragment spreads, and inline fragments, and allows for conditional inclusion during execution as described by the <code>if</code> argument.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L2019-L2020">In this example <code>experimentalField</code> will only be queried if the variable <code>$someTest</code> has the value <code>true</code></p> <pre id="example-aa3a0" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L2022-L2026"><a href="#example-aa3a0">Example № 94</a><code><span class="token keyword">query</span> <span class="token definition-query function">myQuery</span><span class="token punctuation">(</span><span class="token variable">$someTest</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">experimentalField</span> <span class="token directive function">@include</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token variable">$someTest</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <div id="note-f3059" class="spec-note" data-source="spec/Section%203%20--%20Type%20System.md#L2028-L2033"> <a href="#note-f3059">Note</a> Neither <code>@skip</code> nor <code>@include</code> has precedence over the other. In the case that both the <code>@skip</code> and <code>@include</code> directives are provided on the same field or fragment, it <em>must</em> be queried only if the <code>@skip</code> condition is false <em>and</em> the <code>@include</code> condition is true. Stated conversely, the field or fragment must <em>not</em> be queried if either the <code>@skip</code> condition is true <em>or</em> the <code>@include</code> condition is false.</div> </section> <section id="sec--deprecated" secid="3.13.3"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L2036"><span class="spec-secid" title="link to this section"><a href="#sec--deprecated">3.13.3</a></span>@deprecated</h3> <pre data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L2038-L2042"><code><span class="token keyword">directive</span> <span class="token directive function">@deprecated</span><span class="token punctuation">(</span> <span class="token attr-name">reason</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token operator">=</span> <span class="token string">"No longer supported"</span> <span class="token punctuation">)</span> <span class="token keyword">on</span> <span class="token constant">FIELD_DEFINITION</span> <span class="token operator">|</span> <span class="token constant">ENUM_VALUE</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L2044-L2046">The <code>@deprecated</code> <span class="spec-ref"><a href="#built-in-directive" data-name="built-in-directive">built-in directive</a></span> is used within the type system definition language to indicate deprecated portions of a GraphQL service’s schema, such as deprecated fields on a type or deprecated enum values.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L2048-L2049">Deprecations include a reason for why it is deprecated, which is formatted using Markdown syntax (as specified by <a href="https://commonmark.org/">CommonMark</a>).</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L2051-L2052">In this example type definition, <code>oldField</code> is deprecated in favor of using <code>newField</code>.</p> <pre id="example-d0cdc" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L2054-L2059"><a href="#example-d0cdc">Example № 95</a><code><span class="token keyword">type</span> <span class="token class-name">ExampleType</span> <span class="token punctuation">{</span> <span class="token attr-name">newField</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">oldField</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token directive function">@deprecated</span><span class="token punctuation">(</span><span class="token attr-name">reason</span><span class="token punctuation">:</span> <span class="token string">"Use `newField`."</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec--specifiedBy" secid="3.13.4"> <h3 data-source="spec/Section%203%20--%20Type%20System.md#L2062"><span class="spec-secid" title="link to this section"><a href="#sec--specifiedBy">3.13.4</a></span>@specifiedBy</h3> <pre data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L2064-L2066"><code><span class="token keyword">directive</span> <span class="token directive function">@specifiedBy</span><span class="token punctuation">(</span><span class="token attr-name">url</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span><span class="token punctuation">)</span> <span class="token keyword">on</span> <span class="token constant">SCALAR</span> </code></pre> <p data-source="spec/Section%203%20--%20Type%20System.md#L2068-L2072">The <code>@specifiedBy</code> <span class="spec-ref"><a href="#built-in-directive" data-name="built-in-directive">built-in directive</a></span> is used within the type system definition language to provide a <span class="spec-ref"><a href="#scalar-specification-url" data-name="scalar-specification-url">scalar specification URL</a></span> for specifying the behavior of <a href="#sec-Scalars.Custom-Scalars">custom scalar types</a>. The URL should point to a human-readable specification of the data format, serialization, and coercion rules. It must not appear on built-in scalar types.</p> <p data-source="spec/Section%203%20--%20Type%20System.md#L2074-L2075">In this example, a custom scalar type for <code>UUID</code> is defined with a URL pointing to the relevant IETF specification.</p> <pre id="example-e5b0d" class="spec-example" data-language="graphql" data-source="spec/Section%203%20--%20Type%20System.md#L2077-L2079"><a href="#example-e5b0d">Example № 96</a><code><span class="token keyword">scalar</span> <span class="token constant">UUID</span> <span class="token directive function">@specifiedBy</span><span class="token punctuation">(</span><span class="token attr-name">url</span><span class="token punctuation">:</span> <span class="token string">"https://tools.ietf.org/html/rfc4122"</span><span class="token punctuation">)</span> </code></pre> </section> </section> </section> <section id="sec-Introspection" secid="4"> <h1 data-source="spec/Section%204%20--%20Introspection.md#L1"><span class="spec-secid" title="link to this section"><a href="#sec-Introspection">4</a></span>Introspection</h1> <p data-source="spec/Section%204%20--%20Introspection.md#L3-L4">A GraphQL service supports introspection over its schema. This schema is queried using GraphQL itself, creating a powerful platform for tool-building.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L6-L7">Take an example request for a trivial app. In this case there is a User type with three fields: id, name, and birthday.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L9">For example, given a service with the following type definition:</p> <pre id="example-3005e" class="spec-example" data-language="graphql" data-source="spec/Section%204%20--%20Introspection.md#L11-L17"><a href="#example-3005e">Example № 97</a><code><span class="token keyword">type</span> <span class="token class-name">User</span> <span class="token punctuation">{</span> <span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">birthday</span><span class="token punctuation">:</span> <span class="token class-name">Date</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%204%20--%20Introspection.md#L19">A request containing the operation:</p> <pre id="example-2efd3" class="spec-example" data-language="graphql" data-source="spec/Section%204%20--%20Introspection.md#L21-L33"><a href="#example-2efd3">Example № 98</a><code><span class="token punctuation">{</span> <span class="token property-query">__type</span><span class="token punctuation">(</span><span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token string">"User"</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token object">fields</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token keyword">type</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%204%20--%20Introspection.md#L35">would produce the result:</p> <pre id="example-47d72" class="spec-example" data-language="json" data-source="spec/Section%204%20--%20Introspection.md#L37-L57"><a href="#example-47d72">Example № 99</a><code><span class="token punctuation">{</span> <span class="token property">"__type"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"User"</span><span class="token punctuation">,</span> <span class="token property">"fields"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"id"</span><span class="token punctuation">,</span> <span class="token property">"type"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"String"</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"name"</span><span class="token punctuation">,</span> <span class="token property">"type"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"String"</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"birthday"</span><span class="token punctuation">,</span> <span class="token property">"type"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Date"</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <section id="sec-Introspection.Reserved-Names" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L59"><a href="#sec-Introspection.Reserved-Names" title="link to this subsection">Reserved Names</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L61-L64">Types and fields required by the GraphQL introspection system that are used in the same context as user-defined types and fields are prefixed with <span class="spec-string">"__"</span> two underscores. This in order to avoid naming collisions with user-defined GraphQL types.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L66-L67">Otherwise, any <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span> within a GraphQL type system must not start with two underscores <span class="spec-string">"__"</span>.</p> </section> <section id="sec-Type-Name-Introspection" secid="4.1"> <h2 data-source="spec/Section%204%20--%20Introspection.md#L69"><span class="spec-secid" title="link to this section"><a href="#sec-Type-Name-Introspection">4.1</a></span>Type Name Introspection</h2> <p data-source="spec/Section%204%20--%20Introspection.md#L71-L75">GraphQL supports type name introspection within any selection set in an operation, with the single exception of selections at the root of a subscription operation. Type name introspection is accomplished via the meta-field <code>__typename: String!</code> on any Object, Interface, or Union. It returns the name of the concrete Object type at that point during execution.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L77-L78">This is most often used when querying against Interface or Union types to identify which actual Object type of the possible types has been returned.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L80-L81">As a meta-field, <code>__typename</code> is implicit and does not appear in the fields list in any defined type.</p> <div id="note-bc213" class="spec-note" data-source="spec/Section%204%20--%20Introspection.md#L83-L84"> <a href="#note-bc213">Note</a> <code>__typename</code> may not be included as a root field in a subscription operation.</div> </section> <section id="sec-Schema-Introspection" secid="4.2"> <h2 data-source="spec/Section%204%20--%20Introspection.md#L86"><span class="spec-secid" title="link to this section"><a href="#sec-Schema-Introspection">4.2</a></span>Schema Introspection</h2> <p data-source="spec/Section%204%20--%20Introspection.md#L88-L90">The schema introspection system is accessible from the meta-fields <code>__schema</code> and <code>__type</code> which are accessible from the type of the root of a query operation.</p> <pre data-language="graphql" data-source="spec/Section%204%20--%20Introspection.md#L92-L95"><code><span class="token attr-name">__schema</span><span class="token punctuation">:</span> <span class="token class-name">__Schema</span><span class="token operator">!</span> <span class="token attr-name">__type</span><span class="token punctuation">(</span><span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name">__Type</span> </code></pre> <p data-source="spec/Section%204%20--%20Introspection.md#L97-L98">Like all meta-fields, these are implicit and do not appear in the fields list in the root type of the query operation.</p> <section id="sec-Schema-Introspection.First-Class-Documentation" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L100"><a href="#sec-Schema-Introspection.First-Class-Documentation" title="link to this subsection">First Class Documentation</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L102-L107">All types in the introspection system provide a <code>description</code> field of type <code>String</code> to allow type designers to publish documentation in addition to capabilities. A GraphQL service may return the <code>description</code> field using Markdown syntax (as specified by <a href="https://commonmark.org/">CommonMark</a>). Therefore it is recommended that any tool that displays <code>description</code> use a CommonMark-compliant Markdown renderer.</p> </section> <section id="sec-Schema-Introspection.Deprecation" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L109"><a href="#sec-Schema-Introspection.Deprecation" title="link to this subsection">Deprecation</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L111-L113">To support the management of backwards compatibility, GraphQL fields and enum values can indicate whether or not they are deprecated (<code>isDeprecated: Boolean</code>) and a description of why it is deprecated (<code>deprecationReason: String</code>).</p> <p data-source="spec/Section%204%20--%20Introspection.md#L115-L117">Tools built using GraphQL introspection should respect deprecation by discouraging deprecated use through information hiding or developer-facing warnings.</p> </section> <section id="sec-Schema-Introspection.Schema-Introspection-Schema" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L119"><a href="#sec-Schema-Introspection.Schema-Introspection-Schema" title="link to this subsection">Schema Introspection Schema</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L121-L123">The schema introspection system is itself represented as a GraphQL schema. Below are the full set of type system definitions providing schema introspection, which are fully defined in the sections below.</p> <pre data-language="graphql" data-source="spec/Section%204%20--%20Introspection.md#L125-L218"><code><span class="token keyword">type</span> <span class="token class-name">__Schema</span> <span class="token punctuation">{</span> <span class="token attr-name">description</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">types</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">__Type</span><span class="token operator">!</span><span class="token punctuation">]</span><span class="token operator">!</span> <span class="token attr-name">queryType</span><span class="token punctuation">:</span> <span class="token class-name">__Type</span><span class="token operator">!</span> <span class="token attr-name">mutationType</span><span class="token punctuation">:</span> <span class="token class-name">__Type</span> <span class="token attr-name">subscriptionType</span><span class="token punctuation">:</span> <span class="token class-name">__Type</span> <span class="token attr-name">directives</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">__Directive</span><span class="token operator">!</span><span class="token punctuation">]</span><span class="token operator">!</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">__Type</span> <span class="token punctuation">{</span> <span class="token attr-name">kind</span><span class="token punctuation">:</span> <span class="token class-name">__TypeKind</span><span class="token operator">!</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">description</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token comment"># must be non-null for OBJECT and INTERFACE, otherwise null.</span> <span class="token attr-name">fields</span><span class="token punctuation">(</span><span class="token attr-name">includeDeprecated</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">__Field</span><span class="token operator">!</span><span class="token punctuation">]</span> <span class="token comment"># must be non-null for OBJECT and INTERFACE, otherwise null.</span> <span class="token attr-name">interfaces</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">__Type</span><span class="token operator">!</span><span class="token punctuation">]</span> <span class="token comment"># must be non-null for INTERFACE and UNION, otherwise null.</span> <span class="token attr-name">possibleTypes</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">__Type</span><span class="token operator">!</span><span class="token punctuation">]</span> <span class="token comment"># must be non-null for ENUM, otherwise null.</span> <span class="token attr-name">enumValues</span><span class="token punctuation">(</span><span class="token attr-name">includeDeprecated</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">__EnumValue</span><span class="token operator">!</span><span class="token punctuation">]</span> <span class="token comment"># must be non-null for INPUT_OBJECT, otherwise null.</span> <span class="token attr-name">inputFields</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">__InputValue</span><span class="token operator">!</span><span class="token punctuation">]</span> <span class="token comment"># must be non-null for NON_NULL and LIST, otherwise null.</span> <span class="token attr-name">ofType</span><span class="token punctuation">:</span> <span class="token class-name">__Type</span> <span class="token comment"># may be non-null for custom SCALAR, otherwise null.</span> <span class="token attr-name">specifiedByURL</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">enum</span> <span class="token class-name">__TypeKind</span> <span class="token punctuation">{</span> <span class="token constant">SCALAR</span> <span class="token constant">OBJECT</span> <span class="token constant">INTERFACE</span> <span class="token constant">UNION</span> <span class="token constant">ENUM</span> <span class="token constant">INPUT_OBJECT</span> <span class="token constant">LIST</span> <span class="token constant">NON_NULL</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">__Field</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span> <span class="token attr-name">description</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">args</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">__InputValue</span><span class="token operator">!</span><span class="token punctuation">]</span><span class="token operator">!</span> <span class="token attr-name">type</span><span class="token punctuation">:</span> <span class="token class-name">__Type</span><span class="token operator">!</span> <span class="token attr-name">isDeprecated</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span> <span class="token attr-name">deprecationReason</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">__InputValue</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span> <span class="token attr-name">description</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">type</span><span class="token punctuation">:</span> <span class="token class-name">__Type</span><span class="token operator">!</span> <span class="token attr-name">defaultValue</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">__EnumValue</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span> <span class="token attr-name">description</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">isDeprecated</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span> <span class="token attr-name">deprecationReason</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">__Directive</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span> <span class="token attr-name">description</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">locations</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">__DirectiveLocation</span><span class="token operator">!</span><span class="token punctuation">]</span><span class="token operator">!</span> <span class="token attr-name">args</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">__InputValue</span><span class="token operator">!</span><span class="token punctuation">]</span><span class="token operator">!</span> <span class="token attr-name">isRepeatable</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span> <span class="token punctuation">}</span> <span class="token keyword">enum</span> <span class="token class-name">__DirectiveLocation</span> <span class="token punctuation">{</span> <span class="token constant">QUERY</span> <span class="token constant">MUTATION</span> <span class="token constant">SUBSCRIPTION</span> <span class="token constant">FIELD</span> <span class="token constant">FRAGMENT_DEFINITION</span> <span class="token constant">FRAGMENT_SPREAD</span> <span class="token constant">INLINE_FRAGMENT</span> <span class="token constant">VARIABLE_DEFINITION</span> <span class="token constant">SCHEMA</span> <span class="token constant">SCALAR</span> <span class="token constant">OBJECT</span> <span class="token constant">FIELD_DEFINITION</span> <span class="token constant">ARGUMENT_DEFINITION</span> <span class="token constant">INTERFACE</span> <span class="token constant">UNION</span> <span class="token constant">ENUM</span> <span class="token constant">ENUM_VALUE</span> <span class="token constant">INPUT_OBJECT</span> <span class="token constant">INPUT_FIELD_DEFINITION</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-The-__Schema-Type" secid="4.2.1"> <h3 data-source="spec/Section%204%20--%20Introspection.md#L220"><span class="spec-secid" title="link to this section"><a href="#sec-The-__Schema-Type">4.2.1</a></span>The __Schema Type</h3> <p data-source="spec/Section%204%20--%20Introspection.md#L222-L223">The <code>__Schema</code> type is returned from the <code>__schema</code> meta-field and provides all information about the schema of a GraphQL service.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L225">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L227"><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L228"><code>queryType</code> is the root type of a query operation.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L229-L230"><code>mutationType</code> is the root type of a mutation operation, if supported. Otherwise <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L231-L232"><code>subscriptionType</code> is the root type of a subscription operation, if supported. Otherwise <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L233-L235"><code>types</code> must return the set of all named types contained within this schema. Any named type which can be found through a field of any introspection type must be included in this set.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L236-L237"><code>directives</code> must return the set of all directives available within this schema including all built-in directives.</li> </ul> </section> <section id="sec-The-__Type-Type" secid="4.2.2"> <h3 data-source="spec/Section%204%20--%20Introspection.md#L240"><span class="spec-secid" title="link to this section"><a href="#sec-The-__Type-Type">4.2.2</a></span>The __Type Type</h3> <p data-source="spec/Section%204%20--%20Introspection.md#L242-L244"><code>__Type</code> is at the core of the type introspection system, it represents all types in the system: both named types (e.g. Scalars and Object types) and type modifiers (e.g. List and Non-Null types).</p> <p data-source="spec/Section%204%20--%20Introspection.md#L246-L248">Type modifiers are used to modify the type presented in the field <code>ofType</code>. This modified type may recursively be a modified type, representing lists, non-nullables, and combinations thereof, ultimately modifying a named type.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L250-L251">There are several different kinds of type. In each kind, different fields are actually valid. All possible kinds are listed in the <code>__TypeKind</code> enum.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L253-L254">Each sub-section below defines the expected fields of <code>__Type</code> given each possible value of the <code>__TypeKind</code> enum:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L256"><span class="spec-string">"SCALAR"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L257"><span class="spec-string">"OBJECT"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L258"><span class="spec-string">"INTERFACE"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L259"><span class="spec-string">"UNION"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L260"><span class="spec-string">"ENUM"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L261"><span class="spec-string">"INPUT_OBJECT"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L262"><span class="spec-string">"LIST"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L263"><span class="spec-string">"NON_NULL"</span></li> </ul> <section id="sec-The-__Type-Type.Scalar" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L265"><a href="#sec-The-__Type-Type.Scalar" title="link to this subsection">Scalar</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L267">Represents scalar types such as Int, String, and Boolean. Scalars cannot have fields.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L269-L270">Also represents <a href="#sec-Scalars.Custom-Scalars">Custom scalars</a> which may provide <code>specifiedByURL</code> as a <span class="spec-ref"><a href="#scalar-specification-url" data-name="scalar-specification-url">scalar specification URL</a></span>.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L272">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L274"><code>kind</code> must return <code>__TypeKind.SCALAR</code>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L275"><code>name</code> must return a String.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L276"><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L277-L278"><code>specifiedByURL</code> may return a String (in the form of a URL) for custom scalars, otherwise must be <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L279">All other fields must return <span class="spec-keyword">null</span>.</li> </ul> </section> <section id="sec-The-__Type-Type.Object" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L282"><a href="#sec-The-__Type-Type.Object" title="link to this subsection">Object</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L284-L285">Object types represent concrete instantiations of sets of fields. The introspection types (e.g. <code>__Type</code>, <code>__Field</code>, etc) are examples of objects.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L287">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L289"><code>kind</code> must return <code>__TypeKind.OBJECT</code>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L290"><code>name</code> must return a String.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L291"><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L292-L294"><code>fields</code> must return the set of fields that can be selected for this type.<ul> <li data-source="spec/Section%204%20--%20Introspection.md#L293-L294">Accepts the argument <code>includeDeprecated</code> which defaults to <span class="spec-keyword">false</span>. If <span class="spec-keyword">true</span>, deprecated fields are also returned.</li> </ul> </li> <li data-source="spec/Section%204%20--%20Introspection.md#L295-L296"><code>interfaces</code> must return the set of interfaces that an object implements (if none, <code>interfaces</code> must return the empty set).</li> <li data-source="spec/Section%204%20--%20Introspection.md#L297">All other fields must return <span class="spec-keyword">null</span>.</li> </ul> </section> <section id="sec-The-__Type-Type.Union" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L300"><a href="#sec-The-__Type-Type.Union" title="link to this subsection">Union</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L302-L304">Unions are an abstract type where no common fields are declared. The possible types of a union are explicitly listed out in <code>possibleTypes</code>. Types can be made parts of unions without modification of that type.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L306">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L308"><code>kind</code> must return <code>__TypeKind.UNION</code>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L309"><code>name</code> must return a String.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L310"><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L311-L312"><code>possibleTypes</code> returns the list of types that can be represented within this union. They must be object types.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L313">All other fields must return <span class="spec-keyword">null</span>.</li> </ul> </section> <section id="sec-The-__Type-Type.Interface" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L316"><a href="#sec-The-__Type-Type.Interface" title="link to this subsection">Interface</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L318-L321">Interfaces are an abstract type where there are common fields declared. Any type that implements an interface must define all the fields with names and types exactly matching. The implementations of this interface are explicitly listed out in <code>possibleTypes</code>.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L323">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L325"><code>kind</code> must return <code>__TypeKind.INTERFACE</code>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L326"><code>name</code> must return a String.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L327"><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L328-L330"><code>fields</code> must return the set of fields required by this interface.<ul> <li data-source="spec/Section%204%20--%20Introspection.md#L329-L330">Accepts the argument <code>includeDeprecated</code> which defaults to <span class="spec-keyword">false</span>. If <span class="spec-keyword">true</span>, deprecated fields are also returned.</li> </ul> </li> <li data-source="spec/Section%204%20--%20Introspection.md#L331-L332"><code>interfaces</code> must return the set of interfaces that an object implements (if none, <code>interfaces</code> must return the empty set).</li> <li data-source="spec/Section%204%20--%20Introspection.md#L333-L334"><code>possibleTypes</code> returns the list of types that implement this interface. They must be object types.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L335">All other fields must return <span class="spec-keyword">null</span>.</li> </ul> </section> <section id="sec-The-__Type-Type.Enum" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L338"><a href="#sec-The-__Type-Type.Enum" title="link to this subsection">Enum</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L340">Enums are special scalars that can only have a defined set of values.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L342">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L344"><code>kind</code> must return <code>__TypeKind.ENUM</code>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L345"><code>name</code> must return a String.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L346"><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L347-L350"><code>enumValues</code> must return the set of enum values as a list of <code>__EnumValue</code>. There must be at least one and they must have unique names.<ul> <li data-source="spec/Section%204%20--%20Introspection.md#L349-L350">Accepts the argument <code>includeDeprecated</code> which defaults to <span class="spec-keyword">false</span>. If <span class="spec-keyword">true</span>, deprecated enum values are also returned.</li> </ul> </li> <li data-source="spec/Section%204%20--%20Introspection.md#L351">All other fields must return <span class="spec-keyword">null</span>.</li> </ul> </section> <section id="sec-The-__Type-Type.Input-Object" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L354"><a href="#sec-The-__Type-Type.Input-Object" title="link to this subsection">Input Object</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L356-L358">Input objects are composite types defined as a list of named input values. They are only used as inputs to arguments and variables and cannot be a field return type.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L360">For example the input object <code>Point</code> could be defined as:</p> <pre id="example-a0e6d" class="spec-example" data-language="graphql" data-source="spec/Section%204%20--%20Introspection.md#L362-L367"><a href="#example-a0e6d">Example № 100</a><code><span class="token keyword">input</span> <span class="token object">Point</span> <span class="token punctuation">{</span> <span class="token attr-name">x</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token attr-name">y</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%204%20--%20Introspection.md#L369">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L371"><code>kind</code> must return <code>__TypeKind.INPUT_OBJECT</code>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L372"><code>name</code> must return a String.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L373"><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L374"><code>inputFields</code> must return the set of input fields as a list of <code>__InputValue</code>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L375">All other fields must return <span class="spec-keyword">null</span>.</li> </ul> </section> <section id="sec-The-__Type-Type.List" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L378"><a href="#sec-The-__Type-Type.List" title="link to this subsection">List</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L380-L382">Lists represent sequences of values in GraphQL. A List type is a type modifier: it wraps another type instance in the <code>ofType</code> field, which defines the type of each item in the list.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L384-L385">The modified type in the <code>ofType</code> field may itself be a modified type, allowing the representation of Lists of Lists, or Lists of Non-Nulls.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L387">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L389"><code>kind</code> must return <code>__TypeKind.LIST</code>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L390"><code>ofType</code> must return a type of any kind.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L391">All other fields must return <span class="spec-keyword">null</span>.</li> </ul> </section> <section id="sec-The-__Type-Type.Non-Null" class="subsec"> <h6 data-source="spec/Section%204%20--%20Introspection.md#L394"><a href="#sec-The-__Type-Type.Non-Null" title="link to this subsection">Non-Null</a></h6> <p data-source="spec/Section%204%20--%20Introspection.md#L396">GraphQL types are nullable. The value <span class="spec-keyword">null</span> is a valid response for field type.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L398-L400">A Non-Null type is a type modifier: it wraps another type instance in the <code>ofType</code> field. Non-null types do not allow <span class="spec-keyword">null</span> as a response, and indicate required inputs for arguments and input object fields.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L402-L404">The modified type in the <code>ofType</code> field may itself be a modified List type, allowing the representation of Non-Null of Lists. However it must not be a modified Non-Null type to avoid a redundant Non-Null of Non-Null.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L406">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L408"><code>kind</code> must return <code>__TypeKind.NON_NULL</code>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L409"><code>ofType</code> must return a type of any kind except Non-Null.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L410">All other fields must return <span class="spec-keyword">null</span>.</li> </ul> </section> </section> <section id="sec-The-__Field-Type" secid="4.2.3"> <h3 data-source="spec/Section%204%20--%20Introspection.md#L413"><span class="spec-secid" title="link to this section"><a href="#sec-The-__Field-Type">4.2.3</a></span>The __Field Type</h3> <p data-source="spec/Section%204%20--%20Introspection.md#L415">The <code>__Field</code> type represents each field in an Object or Interface type.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L417">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L419"><code>name</code> must return a String</li> <li data-source="spec/Section%204%20--%20Introspection.md#L420"><code>description</code> may return a String or <span class="spec-keyword">null</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L421-L422"><code>args</code> returns a List of <code>__InputValue</code> representing the arguments this field accepts.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L423-L424"><code>type</code> must return a <code>__Type</code> that represents the type of value returned by this field.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L425-L426"><code>isDeprecated</code> returns <span class="spec-keyword">true</span> if this field should no longer be used, otherwise <span class="spec-keyword">false</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L427"><code>deprecationReason</code> optionally provides a reason why this field is deprecated.</li> </ul> </section> <section id="sec-The-__InputValue-Type" secid="4.2.4"> <h3 data-source="spec/Section%204%20--%20Introspection.md#L430"><span class="spec-secid" title="link to this section"><a href="#sec-The-__InputValue-Type">4.2.4</a></span>The __InputValue Type</h3> <p data-source="spec/Section%204%20--%20Introspection.md#L432-L433">The <code>__InputValue</code> type represents field and directive arguments as well as the <code>inputFields</code> of an input object.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L435">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L437"><code>name</code> must return a String</li> <li data-source="spec/Section%204%20--%20Introspection.md#L438"><code>description</code> may return a String or <span class="spec-keyword">null</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L439-L440"><code>type</code> must return a <code>__Type</code> that represents the type this input value expects.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L441-L443"><code>defaultValue</code> may return a String encoding (using the GraphQL language) of the default value used by this input value in the condition a value is not provided at runtime. If this input value has no default value, returns <span class="spec-keyword">null</span>.</li> </ul> </section> <section id="sec-The-__EnumValue-Type" secid="4.2.5"> <h3 data-source="spec/Section%204%20--%20Introspection.md#L445"><span class="spec-secid" title="link to this section"><a href="#sec-The-__EnumValue-Type">4.2.5</a></span>The __EnumValue Type</h3> <p data-source="spec/Section%204%20--%20Introspection.md#L447">The <code>__EnumValue</code> type represents one of possible values of an enum.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L449">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L451"><code>name</code> must return a String</li> <li data-source="spec/Section%204%20--%20Introspection.md#L452"><code>description</code> may return a String or <span class="spec-keyword">null</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L453-L454"><code>isDeprecated</code> returns <span class="spec-keyword">true</span> if this enum value should no longer be used, otherwise <span class="spec-keyword">false</span>.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L455"><code>deprecationReason</code> optionally provides a reason why this enum value is deprecated.</li> </ul> </section> <section id="sec-The-__Directive-Type" secid="4.2.6"> <h3 data-source="spec/Section%204%20--%20Introspection.md#L457"><span class="spec-secid" title="link to this section"><a href="#sec-The-__Directive-Type">4.2.6</a></span>The __Directive Type</h3> <p data-source="spec/Section%204%20--%20Introspection.md#L459">The <code>__Directive</code> type represents a directive that a service supports.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L461">This includes both any <span class="spec-ref"><a href="#built-in-directive" data-name="built-in-directive">built-in directive</a></span> and any <span class="spec-ref"><a href="#custom-directive" data-name="custom-directive">custom directive</a></span>.</p> <p data-source="spec/Section%204%20--%20Introspection.md#L463-L464">Individual directives may only be used in locations that are explicitly supported. All possible locations are listed in the <code>__DirectiveLocation</code> enum:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L466"><span class="spec-string">"QUERY"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L467"><span class="spec-string">"MUTATION"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L468"><span class="spec-string">"SUBSCRIPTION"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L469"><span class="spec-string">"FIELD"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L470"><span class="spec-string">"FRAGMENT_DEFINITION"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L471"><span class="spec-string">"FRAGMENT_SPREAD"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L472"><span class="spec-string">"INLINE_FRAGMENT"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L473"><span class="spec-string">"VARIABLE_DEFINITION"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L474"><span class="spec-string">"SCHEMA"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L475"><span class="spec-string">"SCALAR"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L476"><span class="spec-string">"OBJECT"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L477"><span class="spec-string">"FIELD_DEFINITION"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L478"><span class="spec-string">"ARGUMENT_DEFINITION"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L479"><span class="spec-string">"INTERFACE"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L480"><span class="spec-string">"UNION"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L481"><span class="spec-string">"ENUM"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L482"><span class="spec-string">"ENUM_VALUE"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L483"><span class="spec-string">"INPUT_OBJECT"</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L484"><span class="spec-string">"INPUT_FIELD_DEFINITION"</span></li> </ul> <p data-source="spec/Section%204%20--%20Introspection.md#L486">Fields:</p> <ul> <li data-source="spec/Section%204%20--%20Introspection.md#L488"><code>name</code> must return a String</li> <li data-source="spec/Section%204%20--%20Introspection.md#L489"><code>description</code> may return a String or <span class="spec-keyword">null</span></li> <li data-source="spec/Section%204%20--%20Introspection.md#L490-L491"><code>locations</code> returns a List of <code>__DirectiveLocation</code> representing the valid locations this directive may be placed.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L492-L493"><code>args</code> returns a List of <code>__InputValue</code> representing the arguments this directive accepts.</li> <li data-source="spec/Section%204%20--%20Introspection.md#L494-L496"><code>isRepeatable</code> must return a Boolean that indicates if the directive may be used repeatedly at a single location. </li> </ul> </section> </section> </section> <section id="sec-Validation" secid="5"> <h1 data-source="spec/Section%205%20--%20Validation.md#L1"><span class="spec-secid" title="link to this section"><a href="#sec-Validation">5</a></span>Validation</h1> <p data-source="spec/Section%205%20--%20Validation.md#L3-L5">GraphQL does not just verify if a request is syntactically correct, but also ensures that it is unambiguous and mistake-free in the context of a given GraphQL schema.</p> <p data-source="spec/Section%205%20--%20Validation.md#L7-L10">An invalid request is still technically executable, and will always produce a stable result as defined by the algorithms in the Execution section, however that result may be ambiguous, surprising, or unexpected relative to a request containing validation errors, so execution should only occur for valid requests.</p> <p data-source="spec/Section%205%20--%20Validation.md#L12-L20">Typically validation is performed in the context of a request immediately before execution, however a GraphQL service may execute a request without explicitly validating it if that exact same request is known to have been validated before. For example: the request may be validated during development, provided it does not later change, or a service may validate a request once and memoize the result to avoid validating the same request again in the future. Any client-side or development-time tool should report validation errors and not allow the formulation or execution of requests known to be invalid at that given point in time.</p> <section id="sec-Validation.Type-system-evolution" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L22"><a href="#sec-Validation.Type-system-evolution" title="link to this subsection">Type system evolution</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L24-L31">As GraphQL type system schema evolves over time by adding new types and new fields, it is possible that a request which was previously valid could later become invalid. Any change that can cause a previously valid request to become invalid is considered a <em>breaking change</em>. GraphQL services and schema maintainers are encouraged to avoid breaking changes, however in order to be more resilient to these breaking changes, sophisticated GraphQL systems may still allow for the execution of requests which <em>at some point</em> were known to be free of any validation errors, and have not changed since.</p> </section> <section id="sec-Validation.Examples" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L33"><a href="#sec-Validation.Examples" title="link to this subsection">Examples</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L35-L36">For this section of this schema, we will assume the following type system in order to demonstrate examples:</p> <pre id="example-19f2a" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L38-L90"><a href="#example-19f2a">Example № 101</a><code><span class="token keyword">type</span> <span class="token class-name">Query</span> <span class="token punctuation">{</span> <span class="token attr-name">dog</span><span class="token punctuation">:</span> <span class="token class-name">Dog</span> <span class="token punctuation">}</span> <span class="token keyword">enum</span> <span class="token class-name">DogCommand</span> <span class="token punctuation">{</span> <span class="token constant">SIT</span> <span class="token constant">DOWN</span> <span class="token constant">HEEL</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">Dog</span> <span class="token keyword">implements</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span> <span class="token attr-name">nickname</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">barkVolume</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token attr-name">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token class-name">DogCommand</span><span class="token operator">!</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span> <span class="token attr-name">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span> <span class="token attr-name">owner</span><span class="token punctuation">:</span> <span class="token class-name">Human</span> <span class="token punctuation">}</span> <span class="token keyword">interface</span> <span class="token class-name">Sentient</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span> <span class="token punctuation">}</span> <span class="token keyword">interface</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">Alien</span> <span class="token keyword">implements</span> <span class="token class-name">Sentient</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span> <span class="token attr-name">homePlanet</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">Human</span> <span class="token keyword">implements</span> <span class="token class-name">Sentient</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span> <span class="token attr-name">pets</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">Pet</span><span class="token operator">!</span><span class="token punctuation">]</span> <span class="token punctuation">}</span> <span class="token keyword">enum</span> <span class="token class-name">CatCommand</span> <span class="token punctuation">{</span> <span class="token constant">JUMP</span> <span class="token punctuation">}</span> <span class="token keyword">type</span> <span class="token class-name">Cat</span> <span class="token keyword">implements</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span><span class="token operator">!</span> <span class="token attr-name">nickname</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">catCommand</span><span class="token punctuation">:</span> <span class="token class-name">CatCommand</span><span class="token operator">!</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span> <span class="token attr-name">meowVolume</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token punctuation">}</span> <span class="token keyword">union</span> <span class="token class-name">CatOrDog</span> <span class="token operator">=</span> <span class="token property">Cat</span> <span class="token operator">|</span> <span class="token property">Dog</span> <span class="token keyword">union</span> <span class="token class-name">DogOrHuman</span> <span class="token operator">=</span> <span class="token property">Dog</span> <span class="token operator">|</span> <span class="token property">Human</span> <span class="token keyword">union</span> <span class="token class-name">HumanOrAlien</span> <span class="token operator">=</span> <span class="token property">Human</span> <span class="token operator">|</span> <span class="token property">Alien</span> </code></pre> </section> <section id="sec-Documents" secid="5.1"> <h2 data-source="spec/Section%205%20--%20Validation.md#L93"><span class="spec-secid" title="link to this section"><a href="#sec-Documents">5.1</a></span>Documents</h2> <section id="sec-Executable-Definitions" secid="5.1.1"> <h3 data-source="spec/Section%205%20--%20Validation.md#L95"><span class="spec-secid" title="link to this section"><a href="#sec-Executable-Definitions">5.1.1</a></span>Executable Definitions</h3> <section id="sec-Executable-Definitions.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L97"><a href="#sec-Executable-Definitions.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L99">For each definition <var data-name="definition">definition</var> in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L100-L101"><var data-name="definition">definition</var> must be <span class="spec-nt"><a href="#ExecutableDefinition" data-name="ExecutableDefinition">ExecutableDefinition</a></span> (it must not be <span class="spec-nt"><a href="#TypeSystemDefinitionOrExtension" data-name="TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></span>).</li> </ul> </section> <section id="sec-Executable-Definitions.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L103"><a href="#sec-Executable-Definitions.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L105-L107">GraphQL execution will only consider the executable definitions Operation and Fragment. Type system definitions and extensions are not executable, and are not considered during execution.</p> <p data-source="spec/Section%205%20--%20Validation.md#L109-L110">To avoid ambiguity, a document containing <span class="spec-nt"><a href="#TypeSystemDefinitionOrExtension" data-name="TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></span> is invalid for execution.</p> <p data-source="spec/Section%205%20--%20Validation.md#L112-L113">GraphQL documents not intended to be directly executed may include <span class="spec-nt"><a href="#TypeSystemDefinitionOrExtension" data-name="TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></span>.</p> <p data-source="spec/Section%205%20--%20Validation.md#L115-L116">For example, the following document is invalid for execution since the original executing schema may not know about the provided type extension:</p> <pre id="example-12752" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L118-L129"><a href="#example-12752">Counter Example № 102</a><code><span class="token keyword">query</span> <span class="token definition-query function">getDogName</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token property">color</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">extend</span> <span class="token keyword">type</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token attr-name">color</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> </code></pre> </section> </section> </section> <section id="sec-Validation.Operations" secid="5.2"> <h2 data-source="spec/Section%205%20--%20Validation.md#L131"><span class="spec-secid" title="link to this section"><a href="#sec-Validation.Operations">5.2</a></span>Operations</h2> <section id="sec-Named-Operation-Definitions" secid="5.2.1"> <h3 data-source="spec/Section%205%20--%20Validation.md#L133"><span class="spec-secid" title="link to this section"><a href="#sec-Named-Operation-Definitions">5.2.1</a></span>Named Operation Definitions</h3> <section id="sec-Operation-Name-Uniqueness" secid="5.2.1.1"> <h4 data-source="spec/Section%205%20--%20Validation.md#L135"><span class="spec-secid" title="link to this section"><a href="#sec-Operation-Name-Uniqueness">5.2.1.1</a></span>Operation Name Uniqueness</h4> <section id="sec-Operation-Name-Uniqueness.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L137"><a href="#sec-Operation-Name-Uniqueness.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L139">For each operation definition <var data-name="operation">operation</var> in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L140">Let <var data-name="operationName">operationName</var> be the name of <var data-name="operation">operation</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L141-L143">If <var data-name="operationName">operationName</var> exists<ul> <li data-source="spec/Section%205%20--%20Validation.md#L142">Let <var data-name="operations">operations</var> be all operation definitions in the document named <var data-name="operationName">operationName</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L143"><var data-name="operations">operations</var> must be a set of one.</li> </ul> </li> </ul> </section> <section id="sec-Operation-Name-Uniqueness.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L145"><a href="#sec-Operation-Name-Uniqueness.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L147-L148">Each named operation definition must be unique within a document when referred to by its name.</p> <p data-source="spec/Section%205%20--%20Validation.md#L150">For example the following document is valid:</p> <pre id="example-069e1" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L152-L166"><a href="#example-069e1">Example № 103</a><code><span class="token keyword">query</span> <span class="token definition-query function">getDogName</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">getOwnerName</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token object">owner</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L168">While this document is invalid:</p> <pre id="example-5e409" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L170-L184"><a href="#example-5e409">Counter Example № 104</a><code><span class="token keyword">query</span> <span class="token definition-query function">getName</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">getName</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token object">owner</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L186">It is invalid even if the type of each operation is different:</p> <pre id="example-77c2e" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L188-L200"><a href="#example-77c2e">Counter Example № 105</a><code><span class="token keyword">query</span> <span class="token definition-query function">dogOperation</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">mutation</span> <span class="token definition-mutation function">dogOperation</span> <span class="token punctuation">{</span> <span class="token object">mutateDog</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> </section> <section id="sec-Anonymous-Operation-Definitions" secid="5.2.2"> <h3 data-source="spec/Section%205%20--%20Validation.md#L202"><span class="spec-secid" title="link to this section"><a href="#sec-Anonymous-Operation-Definitions">5.2.2</a></span>Anonymous Operation Definitions</h3> <section id="sec-Lone-Anonymous-Operation" secid="5.2.2.1"> <h4 data-source="spec/Section%205%20--%20Validation.md#L204"><span class="spec-secid" title="link to this section"><a href="#sec-Lone-Anonymous-Operation">5.2.2.1</a></span>Lone Anonymous Operation</h4> <section id="sec-Lone-Anonymous-Operation.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L206"><a href="#sec-Lone-Anonymous-Operation.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L208">Let <var data-name="operations">operations</var> be all operation definitions in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L209">Let <var data-name="anonymous">anonymous</var> be all anonymous operation definitions in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L210-L211">If <var data-name="operations">operations</var> is a set of more than 1:<ul> <li data-source="spec/Section%205%20--%20Validation.md#L211"><var data-name="anonymous">anonymous</var> must be empty.</li> </ul> </li> </ul> </section> <section id="sec-Lone-Anonymous-Operation.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L213"><a href="#sec-Lone-Anonymous-Operation.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L215-L216">GraphQL allows a short-hand form for defining query operations when only that one operation exists in the document.</p> <p data-source="spec/Section%205%20--%20Validation.md#L218">For example the following document is valid:</p> <pre id="example-be853" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L220-L226"><a href="#example-be853">Example № 106</a><code><span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L228">While this document is invalid:</p> <pre id="example-44b85" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L230-L244"><a href="#example-44b85">Counter Example № 107</a><code><span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">getName</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token object">owner</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> </section> <section id="sec-Subscription-Operation-Definitions" secid="5.2.3"> <h3 data-source="spec/Section%205%20--%20Validation.md#L246"><span class="spec-secid" title="link to this section"><a href="#sec-Subscription-Operation-Definitions">5.2.3</a></span>Subscription Operation Definitions</h3> <section id="sec-Single-root-field" secid="5.2.3.1"> <h4 data-source="spec/Section%205%20--%20Validation.md#L248"><span class="spec-secid" title="link to this section"><a href="#sec-Single-root-field">5.2.3.1</a></span>Single root field</h4> <section id="sec-Single-root-field.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L250"><a href="#sec-Single-root-field.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L252">For each subscription operation definition <var data-name="subscription">subscription</var> in the document</li> <li data-source="spec/Section%205%20--%20Validation.md#L253">Let <var data-name="subscriptionType">subscriptionType</var> be the root Subscription type in <var data-name="schema">schema</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L254">Let <var data-name="selectionSet">selectionSet</var> be the top level selection set on <var data-name="subscription">subscription</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L255">Let <var data-name="variableValues">variableValues</var> be the empty set.</li> <li data-source="spec/Section%205%20--%20Validation.md#L256-L257">Let <var data-name="groupedFieldSet">groupedFieldSet</var> be the result of <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>(<var data-name="subscriptionType">subscriptionType</var>, <var data-name="selectionSet">selectionSet</var>, <var data-name="variableValues">variableValues</var>)</span>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L258-L259"><var data-name="groupedFieldSet">groupedFieldSet</var> must have exactly one entry, which must not be an introspection field.</li> </ul> </section> <section id="sec-Single-root-field.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L261"><a href="#sec-Single-root-field.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L263">Subscription operations must have exactly one root field.</p> <p data-source="spec/Section%205%20--%20Validation.md#L265">Valid examples:</p> <pre id="example-5bbc3" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L267-L274"><a href="#example-5bbc3">Example № 108</a><code><span class="token keyword">subscription</span> <span class="token object">sub</span> <span class="token punctuation">{</span> <span class="token object">newMessage</span> <span class="token punctuation">{</span> <span class="token property">body</span> <span class="token property">sender</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <pre id="example-13061" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L276-L287"><a href="#example-13061">Example № 109</a><code><span class="token keyword">subscription</span> <span class="token object">sub</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">newMessageFields</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">newMessageFields</span> <span class="token keyword">on</span> <span class="token class-name">Subscription</span> <span class="token punctuation">{</span> <span class="token object">newMessage</span> <span class="token punctuation">{</span> <span class="token property">body</span> <span class="token property">sender</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L289">Invalid:</p> <pre id="example-3997d" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L291-L299"><a href="#example-3997d">Counter Example № 110</a><code><span class="token keyword">subscription</span> <span class="token object">sub</span> <span class="token punctuation">{</span> <span class="token object">newMessage</span> <span class="token punctuation">{</span> <span class="token property">body</span> <span class="token property">sender</span> <span class="token punctuation">}</span> <span class="token property">disallowedSecondRootField</span> <span class="token punctuation">}</span> </code></pre> <pre id="example-18466" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L301-L313"><a href="#example-18466">Counter Example № 111</a><code><span class="token keyword">subscription</span> <span class="token object">sub</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">multipleSubscriptions</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">multipleSubscriptions</span> <span class="token keyword">on</span> <span class="token class-name">Subscription</span> <span class="token punctuation">{</span> <span class="token object">newMessage</span> <span class="token punctuation">{</span> <span class="token property">body</span> <span class="token property">sender</span> <span class="token punctuation">}</span> <span class="token property">disallowedSecondRootField</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L315-L316">The root field of a subscription operation must not be an introspection field. The following example is also invalid:</p> <pre id="example-a8fa1" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L318-L322"><a href="#example-a8fa1">Counter Example № 112</a><code><span class="token keyword">subscription</span> <span class="token object">sub</span> <span class="token punctuation">{</span> <span class="token property">__typename</span> <span class="token punctuation">}</span> </code></pre> <div id="note-80ec0" class="spec-note" data-source="spec/Section%205%20--%20Validation.md#L324-L327"> <a href="#note-80ec0">Note</a> While each subscription must have exactly one root field, a document may contain any number of operations, each of which may contain different root fields. When executed, a document containing multiple subscription operations must provide the operation name as described in <span class="spec-call"><a href="#GetOperation()" data-name="GetOperation">GetOperation</a>()</span>.</div> </section> </section> </section> </section> <section id="sec-Validation.Fields" secid="5.3"> <h2 data-source="spec/Section%205%20--%20Validation.md#L329"><span class="spec-secid" title="link to this section"><a href="#sec-Validation.Fields">5.3</a></span>Fields</h2> <section id="sec-Field-Selections" secid="5.3.1"> <h3 data-source="spec/Section%205%20--%20Validation.md#L331"><span class="spec-secid" title="link to this section"><a href="#sec-Field-Selections">5.3.1</a></span>Field Selections</h3> <p data-source="spec/Section%205%20--%20Validation.md#L333">Field selections must exist on Object, Interface, and Union types.</p> <section id="sec-Field-Selections.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L335"><a href="#sec-Field-Selections.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L337">For each <var data-name="selection">selection</var> in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L338">Let <var data-name="fieldName">fieldName</var> be the target field of <var data-name="selection">selection</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L339"><var data-name="fieldName">fieldName</var> must be defined on type in scope</li> </ul> </section> <section id="sec-Field-Selections.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L341"><a href="#sec-Field-Selections.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L343-L344">The target field of a field selection must be defined on the scoped type of the selection set. There are no limitations on alias names.</p> <p data-source="spec/Section%205%20--%20Validation.md#L346">For example the following fragment would not pass validation:</p> <pre id="example-48706" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L348-L356"><a href="#example-48706">Counter Example № 113</a><code><span class="token keyword">fragment</span> <span class="token fragment function">fieldNotDefined</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">meowVolume</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">aliasedLyingFieldTargetNotDefined</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token attr-name">barkVolume</span><span class="token punctuation">:</span> <span class="token property">kawVolume</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L358-L360">For interfaces, direct field selection can only be done on fields. Fields of concrete implementors are not relevant to the validity of the given interface-typed selection set.</p> <p data-source="spec/Section%205%20--%20Validation.md#L362">For example, the following is valid:</p> <pre id="example-d34e0" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L364-L368"><a href="#example-d34e0">Example № 114</a><code><span class="token keyword">fragment</span> <span class="token fragment function">interfaceFieldSelection</span> <span class="token keyword">on</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L370">and the following is invalid:</p> <pre id="example-db33b" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L372-L376"><a href="#example-db33b">Counter Example № 115</a><code><span class="token keyword">fragment</span> <span class="token fragment function">definedOnImplementorsButNotInterface</span> <span class="token keyword">on</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token property">nickname</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L378-L381">Because unions do not define fields, fields may not be directly selected from a union-typed selection set, with the exception of the meta-field <var data-name="__typename">__typename</var>. Fields from a union-typed selection set must only be queried indirectly via a fragment.</p> <p data-source="spec/Section%205%20--%20Validation.md#L383">For example the following is valid:</p> <pre id="example-245fa" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L385-L395"><a href="#example-245fa">Example № 116</a><code><span class="token keyword">fragment</span> <span class="token fragment function">inDirectFieldSelectionOnUnion</span> <span class="token keyword">on</span> <span class="token class-name">CatOrDog</span> <span class="token punctuation">{</span> <span class="token property">__typename</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">barkVolume</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L397">But the following is invalid:</p> <pre id="example-252ad" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L399-L404"><a href="#example-252ad">Counter Example № 117</a><code><span class="token keyword">fragment</span> <span class="token fragment function">directFieldSelectionOnUnion</span> <span class="token keyword">on</span> <span class="token class-name">CatOrDog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token property">barkVolume</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Field-Selection-Merging" secid="5.3.2"> <h3 data-source="spec/Section%205%20--%20Validation.md#L407"><span class="spec-secid" title="link to this section"><a href="#sec-Field-Selection-Merging">5.3.2</a></span>Field Selection Merging</h3> <section id="sec-Field-Selection-Merging.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L409"><a href="#sec-Field-Selection-Merging.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L411">Let <var data-name="set">set</var> be any selection set defined in the GraphQL document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L412"><span class="spec-call"><a href="#FieldsInSetCanMerge()" data-name="FieldsInSetCanMerge">FieldsInSetCanMerge</a>(<var data-name="set">set</var>)</span> must be true.</li> </ul> <div class="spec-algo" id="FieldsInSetCanMerge()" data-source="spec/Section%205%20--%20Validation.md#L414-L426"> <span class="spec-call"><a href="#FieldsInSetCanMerge()" data-name="FieldsInSetCanMerge">FieldsInSetCanMerge</a>(<var data-name="set">set</var>)</span><ol> <li data-source="spec/Section%205%20--%20Validation.md#L416-L417">Let <var data-name="fieldsForName">fieldsForName</var> be the set of selections with a given response name in <var data-name="set">set</var> including visiting fragments and inline fragments.</li> <li data-source="spec/Section%205%20--%20Validation.md#L418-L426">Given each pair of members <var data-name="fieldA">fieldA</var> and <var data-name="fieldB">fieldB</var> in <var data-name="fieldsForName">fieldsForName</var>:<ol> <li data-source="spec/Section%205%20--%20Validation.md#L419"><span class="spec-call"><a href="#SameResponseShape()" data-name="SameResponseShape">SameResponseShape</a>(<var data-name="fieldA">fieldA</var>, <var data-name="fieldB">fieldB</var>)</span> must be true.</li> <li data-source="spec/Section%205%20--%20Validation.md#L420-L426">If the parent types of <var data-name="fieldA">fieldA</var> and <var data-name="fieldB">fieldB</var> are equal or if either is not an Object Type:<ol> <li data-source="spec/Section%205%20--%20Validation.md#L422"><var data-name="fieldA">fieldA</var> and <var data-name="fieldB">fieldB</var> must have identical field names.</li> <li data-source="spec/Section%205%20--%20Validation.md#L423"><var data-name="fieldA">fieldA</var> and <var data-name="fieldB">fieldB</var> must have identical sets of arguments.</li> <li data-source="spec/Section%205%20--%20Validation.md#L424-L425">Let <var data-name="mergedSet">mergedSet</var> be the result of adding the selection set of <var data-name="fieldA">fieldA</var> and the selection set of <var data-name="fieldB">fieldB</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L426"><span class="spec-call"><a href="#FieldsInSetCanMerge()" data-name="FieldsInSetCanMerge">FieldsInSetCanMerge</a>(<var data-name="mergedSet">mergedSet</var>)</span> must be true.</li> </ol> </li> </ol> </li> </ol> </div> <div class="spec-algo" id="SameResponseShape()" data-source="spec/Section%205%20--%20Validation.md#L428-L451"> <span class="spec-call"><a href="#SameResponseShape()" data-name="SameResponseShape">SameResponseShape</a>(<var data-name="fieldA">fieldA</var>, <var data-name="fieldB">fieldB</var>)</span><ol> <li data-source="spec/Section%205%20--%20Validation.md#L430">Let <var data-name="typeA">typeA</var> be the return type of <var data-name="fieldA">fieldA</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L431">Let <var data-name="typeB">typeB</var> be the return type of <var data-name="fieldB">fieldB</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L432-L435">If <var data-name="typeA">typeA</var> or <var data-name="typeB">typeB</var> is Non-Null.<ol> <li data-source="spec/Section%205%20--%20Validation.md#L433">If <var data-name="typeA">typeA</var> or <var data-name="typeB">typeB</var> is nullable, return false.</li> <li data-source="spec/Section%205%20--%20Validation.md#L434">Let <var data-name="typeA">typeA</var> be the nullable type of <var data-name="typeA">typeA</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L435">Let <var data-name="typeB">typeB</var> be the nullable type of <var data-name="typeB">typeB</var></li> </ol> </li> <li data-source="spec/Section%205%20--%20Validation.md#L436-L440">If <var data-name="typeA">typeA</var> or <var data-name="typeB">typeB</var> is List.<ol> <li data-source="spec/Section%205%20--%20Validation.md#L437">If <var data-name="typeA">typeA</var> or <var data-name="typeB">typeB</var> is not List, return false.</li> <li data-source="spec/Section%205%20--%20Validation.md#L438">Let <var data-name="typeA">typeA</var> be the item type of <var data-name="typeA">typeA</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L439">Let <var data-name="typeB">typeB</var> be the item type of <var data-name="typeB">typeB</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L440">Repeat from step 3.</li> </ol> </li> <li data-source="spec/Section%205%20--%20Validation.md#L441-L443">If <var data-name="typeA">typeA</var> or <var data-name="typeB">typeB</var> is Scalar or Enum.<ol> <li data-source="spec/Section%205%20--%20Validation.md#L442-L443">If <var data-name="typeA">typeA</var> and <var data-name="typeB">typeB</var> are the same type return true, otherwise return false.</li> </ol> </li> <li data-source="spec/Section%205%20--%20Validation.md#L444">Assert: <var data-name="typeA">typeA</var> and <var data-name="typeB">typeB</var> are both composite types.</li> <li data-source="spec/Section%205%20--%20Validation.md#L445-L446">Let <var data-name="mergedSet">mergedSet</var> be the result of adding the selection set of <var data-name="fieldA">fieldA</var> and the selection set of <var data-name="fieldB">fieldB</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L447-L448">Let <var data-name="fieldsForName">fieldsForName</var> be the set of selections with a given response name in <var data-name="mergedSet">mergedSet</var> including visiting fragments and inline fragments.</li> <li data-source="spec/Section%205%20--%20Validation.md#L449-L450">Given each pair of members <var data-name="subfieldA">subfieldA</var> and <var data-name="subfieldB">subfieldB</var> in <var data-name="fieldsForName">fieldsForName</var>:<ol> <li data-source="spec/Section%205%20--%20Validation.md#L450">If <span class="spec-call"><a href="#SameResponseShape()" data-name="SameResponseShape">SameResponseShape</a>(<var data-name="subfieldA">subfieldA</var>, <var data-name="subfieldB">subfieldB</var>)</span> is false, return false.</li> </ol> </li> <li data-source="spec/Section%205%20--%20Validation.md#L451">Return true.</li> </ol> </div> </section> <section id="sec-Field-Selection-Merging.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L453"><a href="#sec-Field-Selection-Merging.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L455-L458">If multiple field selections with the same response names are encountered during execution, the field and arguments to execute and the resulting value should be unambiguous. Therefore any two field selections which might both be encountered for the same object are only valid if they are equivalent.</p> <p data-source="spec/Section%205%20--%20Validation.md#L460-L461">During execution, the simultaneous execution of fields with the same response name is accomplished by <span class="spec-call"><a href="#MergeSelectionSets()" data-name="MergeSelectionSets">MergeSelectionSets</a>()</span> and <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>()</span>.</p> <p data-source="spec/Section%205%20--%20Validation.md#L463-L464">For simple hand-written GraphQL, this rule is obviously a clear developer error, however nested fragments can make this difficult to detect manually.</p> <p data-source="spec/Section%205%20--%20Validation.md#L466">The following selections correctly merge:</p> <pre id="example-4e10c" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L468-L478"><a href="#example-4e10c">Example № 118</a><code><span class="token keyword">fragment</span> <span class="token fragment function">mergeIdenticalFields</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">mergeIdenticalAliasesAndFields</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token attr-name">otherName</span><span class="token punctuation">:</span> <span class="token property">name</span> <span class="token attr-name">otherName</span><span class="token punctuation">:</span> <span class="token property">name</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L480">The following is not able to merge:</p> <pre id="example-a2230" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L482-L487"><a href="#example-a2230">Counter Example № 119</a><code><span class="token keyword">fragment</span> <span class="token fragment function">conflictingBecauseAlias</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token property">nickname</span> <span class="token property">name</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L489-L490">Identical arguments are also merged if they have identical arguments. Both values and variables can be correctly merged.</p> <p data-source="spec/Section%205%20--%20Validation.md#L492">For example the following correctly merge:</p> <pre id="example-b6369" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L494-L504"><a href="#example-b6369">Example № 120</a><code><span class="token keyword">fragment</span> <span class="token fragment function">mergeIdenticalFieldsWithIdenticalArgs</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token constant">SIT</span><span class="token punctuation">)</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token constant">SIT</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">mergeIdenticalFieldsWithIdenticalValues</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token variable">$dogCommand</span><span class="token punctuation">)</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token variable">$dogCommand</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L506">The following do not correctly merge:</p> <pre id="example-00fbf" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L508-L528"><a href="#example-00fbf">Counter Example № 121</a><code><span class="token keyword">fragment</span> <span class="token fragment function">conflictingArgsOnValues</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token constant">SIT</span><span class="token punctuation">)</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token constant">HEEL</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">conflictingArgsValueAndVar</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token constant">SIT</span><span class="token punctuation">)</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token variable">$dogCommand</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">conflictingArgsWithVars</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token variable">$varOne</span><span class="token punctuation">)</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token variable">$varTwo</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">differingArgs</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token constant">SIT</span><span class="token punctuation">)</span> <span class="token property">doesKnowCommand</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L530-L531">The following fields would not merge together, however both cannot be encountered against the same object, so they are safe:</p> <pre id="example-a8406" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L533-L551"><a href="#example-a8406">Example № 122</a><code><span class="token keyword">fragment</span> <span class="token fragment function">safeDifferingFields</span> <span class="token keyword">on</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token attr-name">volume</span><span class="token punctuation">:</span> <span class="token property">barkVolume</span> <span class="token punctuation">}</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Cat</span> <span class="token punctuation">{</span> <span class="token attr-name">volume</span><span class="token punctuation">:</span> <span class="token property">meowVolume</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">safeDifferingArgs</span> <span class="token keyword">on</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token constant">SIT</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Cat</span> <span class="token punctuation">{</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">catCommand</span><span class="token punctuation">:</span> <span class="token constant">JUMP</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L553-L555">However, the field responses must be shapes which can be merged. For example, scalar values must not differ. In this example, <code>someValue</code> might be a <code>String</code> or an <code>Int</code>:</p> <pre id="example-54e3d" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L557-L566"><a href="#example-54e3d">Counter Example № 123</a><code><span class="token keyword">fragment</span> <span class="token fragment function">conflictingDifferingResponses</span> <span class="token keyword">on</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token attr-name">someValue</span><span class="token punctuation">:</span> <span class="token property">nickname</span> <span class="token punctuation">}</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Cat</span> <span class="token punctuation">{</span> <span class="token attr-name">someValue</span><span class="token punctuation">:</span> <span class="token property">meowVolume</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Leaf-Field-Selections" secid="5.3.3"> <h3 data-source="spec/Section%205%20--%20Validation.md#L569"><span class="spec-secid" title="link to this section"><a href="#sec-Leaf-Field-Selections">5.3.3</a></span>Leaf Field Selections</h3> <section id="sec-Leaf-Field-Selections.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L571"><a href="#sec-Leaf-Field-Selections.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L573">For each <var data-name="selection">selection</var> in the document</li> <li data-source="spec/Section%205%20--%20Validation.md#L574">Let <var data-name="selectionType">selectionType</var> be the result type of <var data-name="selection">selection</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L575-L576">If <var data-name="selectionType">selectionType</var> is a scalar or enum:<ul> <li data-source="spec/Section%205%20--%20Validation.md#L576">The subselection set of that selection must be empty</li> </ul> </li> <li data-source="spec/Section%205%20--%20Validation.md#L577-L578">If <var data-name="selectionType">selectionType</var> is an interface, union, or object<ul> <li data-source="spec/Section%205%20--%20Validation.md#L578">The subselection set of that selection must NOT BE empty</li> </ul> </li> </ul> </section> <section id="sec-Leaf-Field-Selections.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L580"><a href="#sec-Leaf-Field-Selections.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L582-L583">Field selections on scalars or enums are never allowed, because they are the leaf nodes of any GraphQL operation.</p> <p data-source="spec/Section%205%20--%20Validation.md#L585">The following is valid.</p> <pre id="example-e23c5" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L587-L591"><a href="#example-e23c5">Example № 124</a><code><span class="token keyword">fragment</span> <span class="token fragment function">scalarSelection</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">barkVolume</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L593">The following is invalid.</p> <pre id="example-13b69" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L595-L601"><a href="#example-13b69">Counter Example № 125</a><code><span class="token keyword">fragment</span> <span class="token fragment function">scalarSelectionsNotAllowedOnInt</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token object">barkVolume</span> <span class="token punctuation">{</span> <span class="token property">sinceWhen</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L603-L605">Conversely the leaf field selections of GraphQL operations must be of type scalar or enum. Leaf selections on objects, interfaces, and unions without subfields are disallowed.</p> <p data-source="spec/Section%205%20--%20Validation.md#L607-L608">Let’s assume the following additions to the query root operation type of the schema:</p> <pre id="example-9bada" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L610-L616"><a href="#example-9bada">Example № 126</a><code><span class="token keyword">extend</span> <span class="token keyword">type</span> <span class="token class-name">Query</span> <span class="token punctuation">{</span> <span class="token attr-name">human</span><span class="token punctuation">:</span> <span class="token class-name">Human</span> <span class="token attr-name">pet</span><span class="token punctuation">:</span> <span class="token class-name">Pet</span> <span class="token attr-name">catOrDog</span><span class="token punctuation">:</span> <span class="token class-name">CatOrDog</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L618">The following examples are invalid</p> <pre id="example-d68ee" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L620-L632"><a href="#example-d68ee">Counter Example № 127</a><code><span class="token keyword">query</span> <span class="token definition-query function">directQueryOnObjectWithoutSubFields</span> <span class="token punctuation">{</span> <span class="token property">human</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">directQueryOnInterfaceWithoutSubFields</span> <span class="token punctuation">{</span> <span class="token property">pet</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">directQueryOnUnionWithoutSubFields</span> <span class="token punctuation">{</span> <span class="token property">catOrDog</span> <span class="token punctuation">}</span> </code></pre> </section> </section> </section> <section id="sec-Validation.Arguments" secid="5.4"> <h2 data-source="spec/Section%205%20--%20Validation.md#L635"><span class="spec-secid" title="link to this section"><a href="#sec-Validation.Arguments">5.4</a></span>Arguments</h2> <p data-source="spec/Section%205%20--%20Validation.md#L637-L638">Arguments are provided to both fields and directives. The following validation rules apply in both cases.</p> <section id="sec-Argument-Names" secid="5.4.1"> <h3 data-source="spec/Section%205%20--%20Validation.md#L641"><span class="spec-secid" title="link to this section"><a href="#sec-Argument-Names">5.4.1</a></span>Argument Names</h3> <section id="sec-Argument-Names.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L643"><a href="#sec-Argument-Names.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L645">For each <var data-name="argument">argument</var> in the document</li> <li data-source="spec/Section%205%20--%20Validation.md#L646">Let <var data-name="argumentName">argumentName</var> be the Name of <var data-name="argument">argument</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L647">Let <var data-name="argumentDefinition">argumentDefinition</var> be the argument definition provided by the parent field or definition named <var data-name="argumentName">argumentName</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L648"><var data-name="argumentDefinition">argumentDefinition</var> must exist.</li> </ul> </section> <section id="sec-Argument-Names.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L650"><a href="#sec-Argument-Names.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L652-L653">Every argument provided to a field or directive must be defined in the set of possible arguments of that field or directive.</p> <p data-source="spec/Section%205%20--%20Validation.md#L655">For example the following are valid:</p> <pre id="example-dfd15" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L657-L665"><a href="#example-dfd15">Example № 128</a><code><span class="token keyword">fragment</span> <span class="token fragment function">argOnRequiredArg</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">dogCommand</span><span class="token punctuation">:</span> <span class="token constant">SIT</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">argOnOptional</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token directive function">@include</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L667">the following is invalid since <code>command</code> is not defined on <code>DogCommand</code>.</p> <pre id="example-d5639" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L669-L673"><a href="#example-d5639">Counter Example № 129</a><code><span class="token keyword">fragment</span> <span class="token fragment function">invalidArgName</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">doesKnowCommand</span><span class="token punctuation">(</span><span class="token attr-name">command</span><span class="token punctuation">:</span> <span class="token constant">CLEAN_UP_HOUSE</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L675">and this is also invalid as <code>unless</code> is not defined on <code>@include</code>.</p> <pre id="example-df41e" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L677-L681"><a href="#example-df41e">Counter Example № 130</a><code><span class="token keyword">fragment</span> <span class="token fragment function">invalidArgName</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token directive function">@include</span><span class="token punctuation">(</span><span class="token attr-name">unless</span><span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L683-L684">In order to explore more complicated argument examples, let’s add the following to our type system:</p> <pre id="example-73706" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L686-L700"><a href="#example-73706">Example № 131</a><code><span class="token keyword">type</span> <span class="token class-name">Arguments</span> <span class="token punctuation">{</span> <span class="token attr-name">multipleRequirements</span><span class="token punctuation">(</span><span class="token attr-name">x</span><span class="token punctuation">:</span> <span class="token scalar">Int</span><span class="token operator">!</span><span class="token punctuation">,</span> <span class="token attr-name">y</span><span class="token punctuation">:</span> <span class="token scalar">Int</span><span class="token operator">!</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">Int</span><span class="token operator">!</span> <span class="token attr-name">booleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">booleanArg</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span> <span class="token attr-name">floatArgField</span><span class="token punctuation">(</span><span class="token attr-name">floatArg</span><span class="token punctuation">:</span> <span class="token scalar">Float</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">Float</span> <span class="token attr-name">intArgField</span><span class="token punctuation">(</span><span class="token attr-name">intArg</span><span class="token punctuation">:</span> <span class="token scalar">Int</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">Int</span> <span class="token attr-name">nonNullBooleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">nonNullBooleanArg</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span> <span class="token attr-name">booleanListArgField</span><span class="token punctuation">(</span><span class="token attr-name">booleanListArg</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token scalar">Boolean</span><span class="token punctuation">]</span><span class="token operator">!</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token scalar">Boolean</span><span class="token punctuation">]</span> <span class="token attr-name">optionalNonNullBooleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">optionalBooleanArg</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token operator">!</span> <span class="token punctuation">}</span> <span class="token keyword">extend</span> <span class="token keyword">type</span> <span class="token class-name">Query</span> <span class="token punctuation">{</span> <span class="token attr-name">arguments</span><span class="token punctuation">:</span> <span class="token class-name">Arguments</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L702">Order does not matter in arguments. Therefore both the following examples are valid.</p> <pre id="example-bda7e" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L704-L712"><a href="#example-bda7e">Example № 132</a><code><span class="token keyword">fragment</span> <span class="token fragment function">multipleArgs</span> <span class="token keyword">on</span> <span class="token class-name">Arguments</span> <span class="token punctuation">{</span> <span class="token property-query">multipleRequirements</span><span class="token punctuation">(</span><span class="token attr-name">x</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token attr-name">y</span><span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">multipleArgsReverseOrder</span> <span class="token keyword">on</span> <span class="token class-name">Arguments</span> <span class="token punctuation">{</span> <span class="token property-query">multipleRequirements</span><span class="token punctuation">(</span><span class="token attr-name">y</span><span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token attr-name">x</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Argument-Uniqueness" secid="5.4.2"> <h3 data-source="spec/Section%205%20--%20Validation.md#L715"><span class="spec-secid" title="link to this section"><a href="#sec-Argument-Uniqueness">5.4.2</a></span>Argument Uniqueness</h3> <p data-source="spec/Section%205%20--%20Validation.md#L717-L719">Fields and directives treat arguments as a mapping of argument name to value. More than one argument with the same name in an argument set is ambiguous and invalid.</p> <section id="sec-Argument-Uniqueness.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L721"><a href="#sec-Argument-Uniqueness.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L723">For each <var data-name="argument">argument</var> in the Document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L724">Let <var data-name="argumentName">argumentName</var> be the Name of <var data-name="argument">argument</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L725">Let <var data-name="arguments">arguments</var> be all Arguments named <var data-name="argumentName">argumentName</var> in the Argument Set which contains <var data-name="argument">argument</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L726"><var data-name="arguments">arguments</var> must be the set containing only <var data-name="argument">argument</var>.</li> </ul> </section> <section id="sec-Required-Arguments" secid="5.4.2.1"> <h4 data-source="spec/Section%205%20--%20Validation.md#L729"><span class="spec-secid" title="link to this section"><a href="#sec-Required-Arguments">5.4.2.1</a></span>Required Arguments</h4> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L731">For each Field or Directive in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L732">Let <var data-name="arguments">arguments</var> be the arguments provided by the Field or Directive.</li> <li data-source="spec/Section%205%20--%20Validation.md#L733">Let <var data-name="argumentDefinitions">argumentDefinitions</var> be the set of argument definitions of that Field or Directive.</li> <li data-source="spec/Section%205%20--%20Validation.md#L734-L742">For each <var data-name="argumentDefinition">argumentDefinition</var> in <var data-name="argumentDefinitions">argumentDefinitions</var>:<ul> <li data-source="spec/Section%205%20--%20Validation.md#L735">Let <var data-name="type">type</var> be the expected type of <var data-name="argumentDefinition">argumentDefinition</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L736">Let <var data-name="defaultValue">defaultValue</var> be the default value of <var data-name="argumentDefinition">argumentDefinition</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L737-L742">If <var data-name="type">type</var> is Non-Null and <var data-name="defaultValue">defaultValue</var> does not exist:<ul> <li data-source="spec/Section%205%20--%20Validation.md#L738">Let <var data-name="argumentName">argumentName</var> be the name of <var data-name="argumentDefinition">argumentDefinition</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L739">Let <var data-name="argument">argument</var> be the argument in <var data-name="arguments">arguments</var> named <var data-name="argumentName">argumentName</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L740"><var data-name="argument">argument</var> must exist.</li> <li data-source="spec/Section%205%20--%20Validation.md#L741">Let <var data-name="value">value</var> be the value of <var data-name="argument">argument</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L742"><var data-name="value">value</var> must not be the <span class="spec-keyword">null</span> literal.</li> </ul> </li> </ul> </li> </ul> <section id="sec-Required-Arguments.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L744"><a href="#sec-Required-Arguments.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L746-L747">Arguments can be required. An argument is required if the argument type is non-null and does not have a default value. Otherwise, the argument is optional.</p> <p data-source="spec/Section%205%20--%20Validation.md#L749">For example the following are valid:</p> <pre id="example-503bd" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L751-L759"><a href="#example-503bd">Example № 133</a><code><span class="token keyword">fragment</span> <span class="token fragment function">goodBooleanArg</span> <span class="token keyword">on</span> <span class="token class-name">Arguments</span> <span class="token punctuation">{</span> <span class="token property-query">booleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">booleanArg</span><span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">goodNonNullArg</span> <span class="token keyword">on</span> <span class="token class-name">Arguments</span> <span class="token punctuation">{</span> <span class="token property-query">nonNullBooleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">nonNullBooleanArg</span><span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L761">The argument can be omitted from a field with a nullable argument.</p> <p data-source="spec/Section%205%20--%20Validation.md#L763">Therefore the following fragment is valid:</p> <pre id="example-1f1d2" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L765-L769"><a href="#example-1f1d2">Example № 134</a><code><span class="token keyword">fragment</span> <span class="token fragment function">goodBooleanArgDefault</span> <span class="token keyword">on</span> <span class="token class-name">Arguments</span> <span class="token punctuation">{</span> <span class="token property">booleanArgField</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L771">but this is not valid on a required argument.</p> <pre id="example-f12a1" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L773-L777"><a href="#example-f12a1">Counter Example № 135</a><code><span class="token keyword">fragment</span> <span class="token fragment function">missingRequiredArg</span> <span class="token keyword">on</span> <span class="token class-name">Arguments</span> <span class="token punctuation">{</span> <span class="token property">nonNullBooleanArgField</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L779-L780">Providing the explicit value <span class="spec-keyword">null</span> is also not valid since required arguments always have a non-null type.</p> <pre id="example-0bc81" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L782-L786"><a href="#example-0bc81">Counter Example № 136</a><code><span class="token keyword">fragment</span> <span class="token fragment function">missingRequiredArg</span> <span class="token keyword">on</span> <span class="token class-name">Arguments</span> <span class="token punctuation">{</span> <span class="token property-query">nonNullBooleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">nonNullBooleanArg</span><span class="token punctuation">:</span> <span class="token property">null</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> </section> </section> </section> </section> <section id="sec-Validation.Fragments" secid="5.5"> <h2 data-source="spec/Section%205%20--%20Validation.md#L788"><span class="spec-secid" title="link to this section"><a href="#sec-Validation.Fragments">5.5</a></span>Fragments</h2> <section id="sec-Fragment-Declarations" secid="5.5.1"> <h3 data-source="spec/Section%205%20--%20Validation.md#L790"><span class="spec-secid" title="link to this section"><a href="#sec-Fragment-Declarations">5.5.1</a></span>Fragment Declarations</h3> <section id="sec-Fragment-Name-Uniqueness" secid="5.5.1.1"> <h4 data-source="spec/Section%205%20--%20Validation.md#L792"><span class="spec-secid" title="link to this section"><a href="#sec-Fragment-Name-Uniqueness">5.5.1.1</a></span>Fragment Name Uniqueness</h4> <section id="sec-Fragment-Name-Uniqueness.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L794"><a href="#sec-Fragment-Name-Uniqueness.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L796">For each fragment definition <var data-name="fragment">fragment</var> in the document</li> <li data-source="spec/Section%205%20--%20Validation.md#L797">Let <var data-name="fragmentName">fragmentName</var> be the name of <var data-name="fragment">fragment</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L798">Let <var data-name="fragments">fragments</var> be all fragment definitions in the document named <var data-name="fragmentName">fragmentName</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L799"><var data-name="fragments">fragments</var> must be a set of one.</li> </ul> </section> <section id="sec-Fragment-Name-Uniqueness.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L801"><a href="#sec-Fragment-Name-Uniqueness.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L803-L804">Fragment definitions are referenced in fragment spreads by name. To avoid ambiguity, each fragment’s name must be unique within a document.</p> <p data-source="spec/Section%205%20--%20Validation.md#L806-L807">Inline fragments are not considered fragment definitions, and are unaffected by this validation rule.</p> <p data-source="spec/Section%205%20--%20Validation.md#L809">For example the following document is valid:</p> <pre id="example-3703b" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L811-L828"><a href="#example-3703b">Example № 137</a><code><span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">fragmentOne</span> <span class="token operator">...</span><span class="token fragment function">fragmentTwo</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">fragmentOne</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">fragmentTwo</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token object">owner</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L830">While this document is invalid:</p> <pre id="example-2c3e3" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L832-L848"><a href="#example-2c3e3">Counter Example № 138</a><code><span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">fragmentOne</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">fragmentOne</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">fragmentOne</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token object">owner</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Fragment-Spread-Type-Existence" secid="5.5.1.2"> <h4 data-source="spec/Section%205%20--%20Validation.md#L851"><span class="spec-secid" title="link to this section"><a href="#sec-Fragment-Spread-Type-Existence">5.5.1.2</a></span>Fragment Spread Type Existence</h4> <section id="sec-Fragment-Spread-Type-Existence.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L853"><a href="#sec-Fragment-Spread-Type-Existence.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L855">For each named spread <var data-name="namedSpread">namedSpread</var> in the document</li> <li data-source="spec/Section%205%20--%20Validation.md#L856">Let <var data-name="fragment">fragment</var> be the target of <var data-name="namedSpread">namedSpread</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L857">The target type of <var data-name="fragment">fragment</var> must be defined in the schema</li> </ul> </section> <section id="sec-Fragment-Spread-Type-Existence.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L859"><a href="#sec-Fragment-Spread-Type-Existence.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L861-L863">Fragments must be specified on types that exist in the schema. This applies for both named and inline fragments. If they are not defined in the schema, the fragment is invalid.</p> <p data-source="spec/Section%205%20--%20Validation.md#L865">For example the following fragments are valid:</p> <pre id="example-1b2da" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L867-L883"><a href="#example-1b2da">Example № 139</a><code><span class="token keyword">fragment</span> <span class="token fragment function">correctType</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">inlineFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">inlineFragment2</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token directive function">@include</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L885">and the following do not validate:</p> <pre id="example-463f6" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L887-L897"><a href="#example-463f6">Counter Example № 140</a><code><span class="token keyword">fragment</span> <span class="token fragment function">notOnExistingType</span> <span class="token keyword">on</span> <span class="token class-name">NotInSchema</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">inlineNotExistingType</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">NotInSchema</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Fragments-On-Composite-Types" secid="5.5.1.3"> <h4 data-source="spec/Section%205%20--%20Validation.md#L900"><span class="spec-secid" title="link to this section"><a href="#sec-Fragments-On-Composite-Types">5.5.1.3</a></span>Fragments On Composite Types</h4> <section id="sec-Fragments-On-Composite-Types.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L902"><a href="#sec-Fragments-On-Composite-Types.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L904">For each <var data-name="fragment">fragment</var> defined in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L905-L906">The target type of fragment must have kind <span class="spec-nt"><span data-name="UNION">UNION</span></span>, <span class="spec-nt"><span data-name="INTERFACE">INTERFACE</span></span>, or <span class="spec-nt"><span data-name="OBJECT">OBJECT</span></span>.</li> </ul> </section> <section id="sec-Fragments-On-Composite-Types.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L908"><a href="#sec-Fragments-On-Composite-Types.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L910-L912">Fragments can only be declared on unions, interfaces, and objects. They are invalid on scalars. They can only be applied on non-leaf fields. This rule applies to both inline and named fragments.</p> <p data-source="spec/Section%205%20--%20Validation.md#L914">The following fragment declarations are valid:</p> <pre id="example-3c8d4" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L916-L930"><a href="#example-3c8d4">Example № 141</a><code><span class="token keyword">fragment</span> <span class="token fragment function">fragOnObject</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">fragOnInterface</span> <span class="token keyword">on</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">fragOnUnion</span> <span class="token keyword">on</span> <span class="token class-name">CatOrDog</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L932">and the following are invalid:</p> <pre id="example-4d5e5" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L934-L944"><a href="#example-4d5e5">Counter Example № 142</a><code><span class="token keyword">fragment</span> <span class="token fragment function">fragOnScalar</span> <span class="token keyword">on</span> <span class="token scalar">Int</span> <span class="token punctuation">{</span> <span class="token property">something</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">inlineFragOnScalar</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token scalar">Boolean</span> <span class="token punctuation">{</span> <span class="token property">somethingElse</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Fragments-Must-Be-Used" secid="5.5.1.4"> <h4 data-source="spec/Section%205%20--%20Validation.md#L947"><span class="spec-secid" title="link to this section"><a href="#sec-Fragments-Must-Be-Used">5.5.1.4</a></span>Fragments Must Be Used</h4> <section id="sec-Fragments-Must-Be-Used.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L949"><a href="#sec-Fragments-Must-Be-Used.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L951">For each <var data-name="fragment">fragment</var> defined in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L952"><var data-name="fragment">fragment</var> must be the target of at least one spread in the document</li> </ul> </section> <section id="sec-Fragments-Must-Be-Used.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L954"><a href="#sec-Fragments-Must-Be-Used.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L956">Defined fragments must be used within a document.</p> <p data-source="spec/Section%205%20--%20Validation.md#L958">For example the following is an invalid document:</p> <pre id="example-9e1e3" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L960-L970"><a href="#example-9e1e3">Counter Example № 143</a><code><span class="token keyword">fragment</span> <span class="token fragment function">nameFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token comment"># unused</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> </section> <section id="sec-Fragment-Spreads" secid="5.5.2"> <h3 data-source="spec/Section%205%20--%20Validation.md#L973"><span class="spec-secid" title="link to this section"><a href="#sec-Fragment-Spreads">5.5.2</a></span>Fragment Spreads</h3> <p data-source="spec/Section%205%20--%20Validation.md#L975-L978">Field selection is also determined by spreading fragments into one another. The selection set of the target fragment is combined into the selection set at the level at which the target fragment is referenced.</p> <section id="sec-Fragment-spread-target-defined" secid="5.5.2.1"> <h4 data-source="spec/Section%205%20--%20Validation.md#L981"><span class="spec-secid" title="link to this section"><a href="#sec-Fragment-spread-target-defined">5.5.2.1</a></span>Fragment spread target defined</h4> <section id="sec-Fragment-spread-target-defined.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L983"><a href="#sec-Fragment-spread-target-defined.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L985">For every <var data-name="namedSpread">namedSpread</var> in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L986">Let <var data-name="fragment">fragment</var> be the target of <var data-name="namedSpread">namedSpread</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L987"><var data-name="fragment">fragment</var> must be defined in the document</li> </ul> </section> <section id="sec-Fragment-spread-target-defined.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L989"><a href="#sec-Fragment-spread-target-defined.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L991-L993">Named fragment spreads must refer to fragments defined within the document. It is a validation error if the target of a spread is not defined.</p> <pre id="example-28421" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L995-L1001"><a href="#example-28421">Counter Example № 144</a><code><span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">undefinedFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Fragment-spreads-must-not-form-cycles" secid="5.5.2.2"> <h4 data-source="spec/Section%205%20--%20Validation.md#L1004"><span class="spec-secid" title="link to this section"><a href="#sec-Fragment-spreads-must-not-form-cycles">5.5.2.2</a></span>Fragment spreads must not form cycles</h4> <section id="sec-Fragment-spreads-must-not-form-cycles.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1006"><a href="#sec-Fragment-spreads-must-not-form-cycles.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1008">For each <var data-name="fragmentDefinition">fragmentDefinition</var> in the document</li> <li data-source="spec/Section%205%20--%20Validation.md#L1009">Let <var data-name="visited">visited</var> be the empty set.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1010"><span class="spec-call"><a href="#DetectFragmentCycles()" data-name="DetectFragmentCycles">DetectFragmentCycles</a>(<var data-name="fragmentDefinition">fragmentDefinition</var>, <var data-name="visited">visited</var>)</span></li> </ul> <div class="spec-algo" id="DetectFragmentCycles()" data-source="spec/Section%205%20--%20Validation.md#L1012-L1019"> <span class="spec-call"><a href="#DetectFragmentCycles()" data-name="DetectFragmentCycles">DetectFragmentCycles</a>(<var data-name="fragmentDefinition">fragmentDefinition</var>, <var data-name="visited">visited</var>)</span><ol> <li data-source="spec/Section%205%20--%20Validation.md#L1014">Let <var data-name="spreads">spreads</var> be all fragment spread descendants of <var data-name="fragmentDefinition">fragmentDefinition</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1015-L1019">For each <var data-name="spread">spread</var> in <var data-name="spreads">spreads</var><ol> <li data-source="spec/Section%205%20--%20Validation.md#L1016"><var data-name="visited">visited</var> must not contain <var data-name="spread">spread</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1017">Let <var data-name="nextVisited">nextVisited</var> be the set including <var data-name="spread">spread</var> and members of <var data-name="visited">visited</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1018">Let <var data-name="nextFragmentDefinition">nextFragmentDefinition</var> be the target of <var data-name="spread">spread</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1019"><span class="spec-call"><a href="#DetectFragmentCycles()" data-name="DetectFragmentCycles">DetectFragmentCycles</a>(<var data-name="nextFragmentDefinition">nextFragmentDefinition</var>, <var data-name="nextVisited">nextVisited</var>)</span></li> </ol> </li> </ol> </div> </section> <section id="sec-Fragment-spreads-must-not-form-cycles.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1021"><a href="#sec-Fragment-spreads-must-not-form-cycles.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1023-L1025">The graph of fragment spreads must not form any cycles including spreading itself. Otherwise an operation could infinitely spread or infinitely execute on cycles in the underlying data.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1027">This invalidates fragments that would result in an infinite spread:</p> <pre id="example-9ceb4" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1029-L1045"><a href="#example-9ceb4">Counter Example № 145</a><code><span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">nameFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">nameFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token operator">...</span><span class="token fragment function">barkVolumeFragment</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">barkVolumeFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">barkVolume</span> <span class="token operator">...</span><span class="token fragment function">nameFragment</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1047">If the above fragments were inlined, this would result in the infinitely large:</p> <pre id="example-08734" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1049-L1062"><a href="#example-08734">Example № 146</a><code><span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token property">barkVolume</span> <span class="token property">name</span> <span class="token property">barkVolume</span> <span class="token property">name</span> <span class="token property">barkVolume</span> <span class="token property">name</span> <span class="token comment"># forever...</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1064-L1065">This also invalidates fragments that would result in an infinite recursion when executed against cyclic data:</p> <pre id="example-cd11c" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1067-L1087"><a href="#example-cd11c">Counter Example № 147</a><code><span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">dogFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">dogFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token object">owner</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">ownerFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">ownerFragment</span> <span class="token keyword">on</span> <span class="token class-name">Human</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token object">pets</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">dogFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Fragment-spread-is-possible" secid="5.5.2.3"> <h4 data-source="spec/Section%205%20--%20Validation.md#L1090"><span class="spec-secid" title="link to this section"><a href="#sec-Fragment-spread-is-possible">5.5.2.3</a></span>Fragment spread is possible</h4> <section id="sec-Fragment-spread-is-possible.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1092"><a href="#sec-Fragment-spread-is-possible.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1094">For each <var data-name="spread">spread</var> (named or inline) defined in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1095">Let <var data-name="fragment">fragment</var> be the target of <var data-name="spread">spread</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1096">Let <var data-name="fragmentType">fragmentType</var> be the type condition of <var data-name="fragment">fragment</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1097">Let <var data-name="parentType">parentType</var> be the type of the selection set containing <var data-name="spread">spread</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1098-L1099">Let <var data-name="applicableTypes">applicableTypes</var> be the intersection of <span class="spec-call"><a href="#GetPossibleTypes()" data-name="GetPossibleTypes">GetPossibleTypes</a>(<var data-name="fragmentType">fragmentType</var>)</span> and <span class="spec-call"><a href="#GetPossibleTypes()" data-name="GetPossibleTypes">GetPossibleTypes</a>(<var data-name="parentType">parentType</var>)</span></li> <li data-source="spec/Section%205%20--%20Validation.md#L1100"><var data-name="applicableTypes">applicableTypes</var> must not be empty.</li> </ul> <div class="spec-algo" id="GetPossibleTypes()" data-source="spec/Section%205%20--%20Validation.md#L1102-L1106"> <span class="spec-call"><a href="#GetPossibleTypes()" data-name="GetPossibleTypes">GetPossibleTypes</a>(<var data-name="type">type</var>)</span><ol> <li data-source="spec/Section%205%20--%20Validation.md#L1104">If <var data-name="type">type</var> is an object type, return a set containing <var data-name="type">type</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1105">If <var data-name="type">type</var> is an interface type, return the set of types implementing <var data-name="type">type</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1106">If <var data-name="type">type</var> is a union type, return the set of possible types of <var data-name="type">type</var></li> </ol> </div> </section> <section id="sec-Fragment-spread-is-possible.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1108"><a href="#sec-Fragment-spread-is-possible.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1110-L1114">Fragments are declared on a type and will only apply when the runtime object type matches the type condition. They also are spread within the context of a parent type. A fragment spread is only valid if its type condition could ever apply within the parent type.</p> </section> <section id="sec-Object-Spreads-In-Object-Scope" secid="5.5.2.3.1"> <h5 data-source="spec/Section%205%20--%20Validation.md#L1117"><span class="spec-secid" title="link to this section"><a href="#sec-Object-Spreads-In-Object-Scope">5.5.2.3.1</a></span>Object Spreads In Object Scope</h5> <p data-source="spec/Section%205%20--%20Validation.md#L1119-L1121">In the scope of an object type, the only valid object type fragment spread is one that applies to the same type that is in scope.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1123">For example</p> <pre id="example-0fc38" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1125-L1131"><a href="#example-0fc38">Example № 148</a><code><span class="token keyword">fragment</span> <span class="token fragment function">dogFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">barkVolume</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1133">and the following is invalid</p> <pre id="example-4d411" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1135-L1141"><a href="#example-4d411">Counter Example № 149</a><code><span class="token keyword">fragment</span> <span class="token fragment function">catInDogFragmentInvalid</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Cat</span> <span class="token punctuation">{</span> <span class="token property">meowVolume</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-Abstract-Spreads-in-Object-Scope" secid="5.5.2.3.2"> <h5 data-source="spec/Section%205%20--%20Validation.md#L1144"><span class="spec-secid" title="link to this section"><a href="#sec-Abstract-Spreads-in-Object-Scope">5.5.2.3.2</a></span>Abstract Spreads in Object Scope</h5> <p data-source="spec/Section%205%20--%20Validation.md#L1146-L1147">In scope of an object type, unions or interface spreads can be used if the object type implements the interface or is a member of the union.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1149">For example</p> <pre id="example-2c8d0" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1151-L1159"><a href="#example-2c8d0">Example № 150</a><code><span class="token keyword">fragment</span> <span class="token fragment function">petNameFragment</span> <span class="token keyword">on</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">interfaceWithinObjectFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">petNameFragment</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1161">is valid because <span class="spec-nt"><span data-name="Dog">Dog</span></span> implements Pet.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1163">Likewise</p> <pre id="example-41843" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1165-L1175"><a href="#example-41843">Example № 151</a><code><span class="token keyword">fragment</span> <span class="token fragment function">catOrDogNameFragment</span> <span class="token keyword">on</span> <span class="token class-name">CatOrDog</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Cat</span> <span class="token punctuation">{</span> <span class="token property">meowVolume</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">unionWithObjectFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">catOrDogNameFragment</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1177-L1181">is valid because <span class="spec-nt"><span data-name="Dog">Dog</span></span> is a member of the <span class="spec-nt"><span data-name="CatOrDog">CatOrDog</span></span> union. It is worth noting that if one inspected the contents of the <span class="spec-nt"><span data-name="CatOrDogNameFragment">CatOrDogNameFragment</span></span> you could note that no valid results would ever be returned. However we do not specify this as invalid because we only consider the fragment declaration, not its body.</p> </section> <section id="sec-Object-Spreads-In-Abstract-Scope" secid="5.5.2.3.3"> <h5 data-source="spec/Section%205%20--%20Validation.md#L1184"><span class="spec-secid" title="link to this section"><a href="#sec-Object-Spreads-In-Abstract-Scope">5.5.2.3.3</a></span>Object Spreads In Abstract Scope</h5> <p data-source="spec/Section%205%20--%20Validation.md#L1186-L1188">Union or interface spreads can be used within the context of an object type fragment, but only if the object type is one of the possible types of that interface or union.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1190">For example, the following fragments are valid:</p> <pre id="example-85110" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1192-L1205"><a href="#example-85110">Example № 152</a><code><span class="token keyword">fragment</span> <span class="token fragment function">petFragment</span> <span class="token keyword">on</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">barkVolume</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">catOrDogFragment</span> <span class="token keyword">on</span> <span class="token class-name">CatOrDog</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Cat</span> <span class="token punctuation">{</span> <span class="token property">meowVolume</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1207-L1209"><var data-name="petFragment">petFragment</var> is valid because <span class="spec-nt"><span data-name="Dog">Dog</span></span> implements the interface <span class="spec-nt"><span data-name="Pet">Pet</span></span>. <var data-name="catOrDogFragment">catOrDogFragment</var> is valid because <span class="spec-nt"><span data-name="Cat">Cat</span></span> is a member of the <span class="spec-nt"><span data-name="CatOrDog">CatOrDog</span></span> union.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1211">By contrast the following fragments are invalid:</p> <pre id="example-a8dcc" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1213-L1225"><a href="#example-a8dcc">Counter Example № 153</a><code><span class="token keyword">fragment</span> <span class="token fragment function">sentientFragment</span> <span class="token keyword">on</span> <span class="token class-name">Sentient</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">barkVolume</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">humanOrAlienFragment</span> <span class="token keyword">on</span> <span class="token class-name">HumanOrAlien</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Cat</span> <span class="token punctuation">{</span> <span class="token property">meowVolume</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1227-L1230"><span class="spec-nt"><span data-name="Dog">Dog</span></span> does not implement the interface <span class="spec-nt"><span data-name="Sentient">Sentient</span></span> and therefore <var data-name="sentientFragment">sentientFragment</var> can never return meaningful results. Therefore the fragment is invalid. Likewise <span class="spec-nt"><span data-name="Cat">Cat</span></span> is not a member of the union <span class="spec-nt"><span data-name="HumanOrAlien">HumanOrAlien</span></span>, and it can also never return meaningful results, making it invalid.</p> </section> <section id="sec-Abstract-Spreads-in-Abstract-Scope" secid="5.5.2.3.4"> <h5 data-source="spec/Section%205%20--%20Validation.md#L1233"><span class="spec-secid" title="link to this section"><a href="#sec-Abstract-Spreads-in-Abstract-Scope">5.5.2.3.4</a></span>Abstract Spreads in Abstract Scope</h5> <p data-source="spec/Section%205%20--%20Validation.md#L1235-L1237">Union or interfaces fragments can be used within each other. As long as there exists at least <em>one</em> object type that exists in the intersection of the possible types of the scope and the spread, the spread is considered valid.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1239">So for example</p> <pre id="example-dc875" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1241-L1251"><a href="#example-dc875">Example № 154</a><code><span class="token keyword">fragment</span> <span class="token fragment function">unionWithInterface</span> <span class="token keyword">on</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">dogOrHumanFragment</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">dogOrHumanFragment</span> <span class="token keyword">on</span> <span class="token class-name">DogOrHuman</span> <span class="token punctuation">{</span> <span class="token operator">...</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">barkVolume</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1253-L1254">is considered valid because <span class="spec-nt"><span data-name="Dog">Dog</span></span> implements interface <span class="spec-nt"><span data-name="Pet">Pet</span></span> and is a member of <span class="spec-nt"><span data-name="DogOrHuman">DogOrHuman</span></span>.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1256">However</p> <pre id="example-c9c63" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1258-L1266"><a href="#example-c9c63">Counter Example № 155</a><code><span class="token keyword">fragment</span> <span class="token fragment function">nonIntersectingInterfaces</span> <span class="token keyword">on</span> <span class="token class-name">Pet</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">sentientFragment</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">sentientFragment</span> <span class="token keyword">on</span> <span class="token class-name">Sentient</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1268-L1269">is not valid because there exists no type that implements both <span class="spec-nt"><span data-name="Pet">Pet</span></span> and <span class="spec-nt"><span data-name="Sentient">Sentient</span></span>.</p> <section id="sec-Abstract-Spreads-in-Abstract-Scope.Interface-Spreads-in-implemented-Interface-Scope" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1272"><a href="#sec-Abstract-Spreads-in-Abstract-Scope.Interface-Spreads-in-implemented-Interface-Scope" title="link to this subsection">Interface Spreads in implemented Interface Scope</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1274-L1275">Additionally, an interface type fragment can always be spread into an interface scope which it implements.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1277-L1278">In the example below, the <code>...resourceFragment</code> fragments spreads is valid, since <code>Resource</code> implements <code>Node</code>.</p> <pre id="example-bc12a" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1280-L1297"><a href="#example-bc12a">Example № 156</a><code><span class="token keyword">interface</span> <span class="token class-name">Node</span> <span class="token punctuation">{</span> <span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token scalar">ID</span><span class="token operator">!</span> <span class="token punctuation">}</span> <span class="token keyword">interface</span> <span class="token class-name">Resource</span> <span class="token keyword">implements</span> <span class="token class-name">Node</span> <span class="token punctuation">{</span> <span class="token attr-name">id</span><span class="token punctuation">:</span> <span class="token scalar">ID</span><span class="token operator">!</span> <span class="token attr-name">url</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">interfaceWithInterface</span> <span class="token keyword">on</span> <span class="token class-name">Node</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">resourceFragment</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">resourceFragment</span> <span class="token keyword">on</span> <span class="token class-name">Resource</span> <span class="token punctuation">{</span> <span class="token property">url</span> <span class="token punctuation">}</span> </code></pre> </section> </section> </section> </section> </section> <section id="sec-Values" secid="5.6"> <h2 data-source="spec/Section%205%20--%20Validation.md#L1300"><span class="spec-secid" title="link to this section"><a href="#sec-Values">5.6</a></span>Values</h2> <section id="sec-Values-of-Correct-Type" secid="5.6.1"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1303"><span class="spec-secid" title="link to this section"><a href="#sec-Values-of-Correct-Type">5.6.1</a></span>Values of Correct Type</h3> <section id="sec-Values-of-Correct-Type.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1305"><a href="#sec-Values-of-Correct-Type.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1307-L1309">For each input Value <var data-name="value">value</var> in the document.<ul> <li data-source="spec/Section%205%20--%20Validation.md#L1308">Let <var data-name="type">type</var> be the type expected in the position <var data-name="value">value</var> is found.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1309"><var data-name="value">value</var> must be coercible to <var data-name="type">type</var>.</li> </ul> </li> </ul> </section> <section id="sec-Values-of-Correct-Type.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1311"><a href="#sec-Values-of-Correct-Type.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1313-L1314">Literal values must be compatible with the type expected in the position they are found as per the coercion rules defined in the Type System chapter.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1316-L1318">The type expected in a position includes the type defined by the argument a value is provided for, the type defined by an input object field a value is provided for, and the type of a variable definition a default value is provided for.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1320">The following examples are valid use of value literals:</p> <pre id="example-7ee0e" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1322-L1335"><a href="#example-7ee0e">Example № 157</a><code><span class="token keyword">fragment</span> <span class="token fragment function">goodBooleanArg</span> <span class="token keyword">on</span> <span class="token class-name">Arguments</span> <span class="token punctuation">{</span> <span class="token property-query">booleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">booleanArg</span><span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">coercedIntIntoFloatArg</span> <span class="token keyword">on</span> <span class="token class-name">Arguments</span> <span class="token punctuation">{</span> <span class="token comment"># Note: The input coercion rules for Float allow Int literals.</span> <span class="token property-query">floatArgField</span><span class="token punctuation">(</span><span class="token attr-name">floatArg</span><span class="token punctuation">:</span> <span class="token number">123</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">goodComplexDefaultValue</span><span class="token punctuation">(</span><span class="token variable">$search</span><span class="token punctuation">:</span> <span class="token atom-input class-name">ComplexInput</span> <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token string">"Fido"</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property-query">findDog</span><span class="token punctuation">(</span><span class="token attr-name">complex</span><span class="token punctuation">:</span> <span class="token variable">$search</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1337-L1338">Non-coercible values (such as a String into an Int) are invalid. The following examples are invalid:</p> <pre id="example-3a7c1" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1340-L1348"><a href="#example-3a7c1">Counter Example № 158</a><code><span class="token keyword">fragment</span> <span class="token fragment function">stringIntoInt</span> <span class="token keyword">on</span> <span class="token class-name">Arguments</span> <span class="token punctuation">{</span> <span class="token property-query">intArgField</span><span class="token punctuation">(</span><span class="token attr-name">intArg</span><span class="token punctuation">:</span> <span class="token string">"123"</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">badComplexValue</span> <span class="token punctuation">{</span> <span class="token property-query">findDog</span><span class="token punctuation">(</span><span class="token attr-name">complex</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token number">123</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Input-Object-Field-Names" secid="5.6.2"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1351"><span class="spec-secid" title="link to this section"><a href="#sec-Input-Object-Field-Names">5.6.2</a></span>Input Object Field Names</h3> <section id="sec-Input-Object-Field-Names.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1353"><a href="#sec-Input-Object-Field-Names.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1355">For each Input Object Field <var data-name="inputField">inputField</var> in the document</li> <li data-source="spec/Section%205%20--%20Validation.md#L1356">Let <var data-name="inputFieldName">inputFieldName</var> be the Name of <var data-name="inputField">inputField</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1357-L1358">Let <var data-name="inputFieldDefinition">inputFieldDefinition</var> be the input field definition provided by the parent input object type named <var data-name="inputFieldName">inputFieldName</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1359"><var data-name="inputFieldDefinition">inputFieldDefinition</var> must exist.</li> </ul> </section> <section id="sec-Input-Object-Field-Names.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1361"><a href="#sec-Input-Object-Field-Names.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1363-L1364">Every input field provided in an input object value must be defined in the set of possible fields of that input object’s expected type.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1366">For example the following example input object is valid:</p> <pre id="example-a940b" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1368-L1372"><a href="#example-a940b">Example № 159</a><code><span class="token punctuation">{</span> <span class="token property-query">findDog</span><span class="token punctuation">(</span><span class="token attr-name">complex</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token string">"Fido"</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1374-L1375">While the following example input-object uses a field “favoriteCookieFlavor” which is not defined on the expected type:</p> <pre id="example-1a5f6" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1377-L1381"><a href="#example-1a5f6">Counter Example № 160</a><code><span class="token punctuation">{</span> <span class="token property-query">findDog</span><span class="token punctuation">(</span><span class="token attr-name">complex</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token attr-name">favoriteCookieFlavor</span><span class="token punctuation">:</span> <span class="token string">"Bacon"</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Input-Object-Field-Uniqueness" secid="5.6.3"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1384"><span class="spec-secid" title="link to this section"><a href="#sec-Input-Object-Field-Uniqueness">5.6.3</a></span>Input Object Field Uniqueness</h3> <section id="sec-Input-Object-Field-Uniqueness.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1386"><a href="#sec-Input-Object-Field-Uniqueness.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1388">For each input object value <var data-name="inputObject">inputObject</var> in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1389-L1392">For every <var data-name="inputField">inputField</var> in <var data-name="inputObject">inputObject</var><ul> <li data-source="spec/Section%205%20--%20Validation.md#L1390">Let <var data-name="name">name</var> be the Name of <var data-name="inputField">inputField</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1391">Let <var data-name="fields">fields</var> be all Input Object Fields named <var data-name="name">name</var> in <var data-name="inputObject">inputObject</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1392"><var data-name="fields">fields</var> must be the set containing only <var data-name="inputField">inputField</var>.</li> </ul> </li> </ul> </section> <section id="sec-Input-Object-Field-Uniqueness.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1394"><a href="#sec-Input-Object-Field-Uniqueness.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1396-L1397">Input objects must not contain more than one field of the same name, otherwise an ambiguity would exist which includes an ignored portion of syntax.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1399">For example the following document will not pass validation.</p> <pre id="example-5d541" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1401-L1405"><a href="#example-5d541">Counter Example № 161</a><code><span class="token punctuation">{</span> <span class="token property-query">field</span><span class="token punctuation">(</span><span class="token attr-name">arg</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token attr-name">field</span><span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token attr-name">field</span><span class="token punctuation">:</span> <span class="token boolean">false</span> <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Input-Object-Required-Fields" secid="5.6.4"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1408"><span class="spec-secid" title="link to this section"><a href="#sec-Input-Object-Required-Fields">5.6.4</a></span>Input Object Required Fields</h3> <section id="sec-Input-Object-Required-Fields.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1410"><a href="#sec-Input-Object-Required-Fields.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1412-L1414">For each Input Object in the document.<ul> <li data-source="spec/Section%205%20--%20Validation.md#L1413">Let <var data-name="fields">fields</var> be the fields provided by that Input Object.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1414">Let <var data-name="fieldDefinitions">fieldDefinitions</var> be the set of input field definitions of that Input Object.</li> </ul> </li> <li data-source="spec/Section%205%20--%20Validation.md#L1415-L1423">For each <var data-name="fieldDefinition">fieldDefinition</var> in <var data-name="fieldDefinitions">fieldDefinitions</var>:<ul> <li data-source="spec/Section%205%20--%20Validation.md#L1416">Let <var data-name="type">type</var> be the expected type of <var data-name="fieldDefinition">fieldDefinition</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1417">Let <var data-name="defaultValue">defaultValue</var> be the default value of <var data-name="fieldDefinition">fieldDefinition</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1418-L1423">If <var data-name="type">type</var> is Non-Null and <var data-name="defaultValue">defaultValue</var> does not exist:<ul> <li data-source="spec/Section%205%20--%20Validation.md#L1419">Let <var data-name="fieldName">fieldName</var> be the name of <var data-name="fieldDefinition">fieldDefinition</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1420">Let <var data-name="field">field</var> be the input field in <var data-name="fields">fields</var> named <var data-name="fieldName">fieldName</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1421"><var data-name="field">field</var> must exist.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1422">Let <var data-name="value">value</var> be the value of <var data-name="field">field</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1423"><var data-name="value">value</var> must not be the <span class="spec-keyword">null</span> literal.</li> </ul> </li> </ul> </li> </ul> </section> <section id="sec-Input-Object-Required-Fields.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1425"><a href="#sec-Input-Object-Required-Fields.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1427-L1430">Input object fields may be required. Much like a field may have required arguments, an input object may have required fields. An input field is required if it has a non-null type and does not have a default value. Otherwise, the input object field is optional.</p> </section> </section> </section> <section id="sec-Validation.Directives" secid="5.7"> <h2 data-source="spec/Section%205%20--%20Validation.md#L1433"><span class="spec-secid" title="link to this section"><a href="#sec-Validation.Directives">5.7</a></span>Directives</h2> <section id="sec-Directives-Are-Defined" secid="5.7.1"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1436"><span class="spec-secid" title="link to this section"><a href="#sec-Directives-Are-Defined">5.7.1</a></span>Directives Are Defined</h3> <section id="sec-Directives-Are-Defined.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1438"><a href="#sec-Directives-Are-Defined.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1440">For every <var data-name="directive">directive</var> in a document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1441">Let <var data-name="directiveName">directiveName</var> be the name of <var data-name="directive">directive</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1442">Let <var data-name="directiveDefinition">directiveDefinition</var> be the directive named <var data-name="directiveName">directiveName</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1443"><var data-name="directiveDefinition">directiveDefinition</var> must exist.</li> </ul> </section> <section id="sec-Directives-Are-Defined.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1445"><a href="#sec-Directives-Are-Defined.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1447-L1448">GraphQL services define what directives they support. For each usage of a directive, the directive must be available on that service.</p> </section> </section> <section id="sec-Directives-Are-In-Valid-Locations" secid="5.7.2"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1451"><span class="spec-secid" title="link to this section"><a href="#sec-Directives-Are-In-Valid-Locations">5.7.2</a></span>Directives Are In Valid Locations</h3> <section id="sec-Directives-Are-In-Valid-Locations.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1453"><a href="#sec-Directives-Are-In-Valid-Locations.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1455">For every <var data-name="directive">directive</var> in a document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1456">Let <var data-name="directiveName">directiveName</var> be the name of <var data-name="directive">directive</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1457">Let <var data-name="directiveDefinition">directiveDefinition</var> be the directive named <var data-name="directiveName">directiveName</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1458">Let <var data-name="locations">locations</var> be the valid locations for <var data-name="directiveDefinition">directiveDefinition</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1459">Let <var data-name="adjacent">adjacent</var> be the AST node the directive affects.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1460"><var data-name="adjacent">adjacent</var> must be represented by an item within <var data-name="locations">locations</var>.</li> </ul> </section> <section id="sec-Directives-Are-In-Valid-Locations.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1462"><a href="#sec-Directives-Are-In-Valid-Locations.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1464-L1466">GraphQL services define what directives they support and where they support them. For each usage of a directive, the directive must be used in a location that the service has declared support for.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1468-L1469">For example the following document will not pass validation because <code>@skip</code> does not provide <code>QUERY</code> as a valid location.</p> <pre id="example-55f3f" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1471-L1475"><a href="#example-55f3f">Counter Example № 162</a><code><span class="token keyword">query</span> <span class="token directive function">@skip</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token variable">$foo</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">field</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Directives-Are-Unique-Per-Location" secid="5.7.3"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1478"><span class="spec-secid" title="link to this section"><a href="#sec-Directives-Are-Unique-Per-Location">5.7.3</a></span>Directives Are Unique Per Location</h3> <section id="sec-Directives-Are-Unique-Per-Location.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1480"><a href="#sec-Directives-Are-Unique-Per-Location.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1482-L1489">For every <var data-name="location">location</var> in the document for which Directives can apply:<ul> <li data-source="spec/Section%205%20--%20Validation.md#L1483-L1484">Let <var data-name="directives">directives</var> be the set of Directives which apply to <var data-name="location">location</var> and are not repeatable.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1485-L1489">For each <var data-name="directive">directive</var> in <var data-name="directives">directives</var>:<ul> <li data-source="spec/Section%205%20--%20Validation.md#L1486">Let <var data-name="directiveName">directiveName</var> be the name of <var data-name="directive">directive</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1487-L1488">Let <var data-name="namedDirectives">namedDirectives</var> be the set of all Directives named <var data-name="directiveName">directiveName</var> in <var data-name="directives">directives</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1489"><var data-name="namedDirectives">namedDirectives</var> must be a set of one.</li> </ul> </li> </ul> </li> </ul> </section> <section id="sec-Directives-Are-Unique-Per-Location.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1491"><a href="#sec-Directives-Are-Unique-Per-Location.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1493-L1496">Directives are used to describe some metadata or behavioral change on the definition they apply to. When more than one directive of the same name is used, the expected metadata or behavior becomes ambiguous, therefore only one of each directive is allowed per location.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1498-L1499">For example, the following document will not pass validation because <code>@skip</code> has been used twice for the same field:</p> <pre id="example-b2e6c" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1501-L1505"><a href="#example-b2e6c">Counter Example № 163</a><code><span class="token keyword">query</span> <span class="token punctuation">(</span><span class="token variable">$foo</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token variable">$bar</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">field</span> <span class="token directive function">@skip</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token variable">$foo</span><span class="token punctuation">)</span> <span class="token directive function">@skip</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token variable">$bar</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1507-L1509">However the following example is valid because <code>@skip</code> has been used only once per location, despite being used twice in the operation and on the same named field:</p> <pre id="example-c5ee9" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1511-L1520"><a href="#example-c5ee9">Example № 164</a><code><span class="token keyword">query</span> <span class="token punctuation">(</span><span class="token variable">$foo</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token variable">$bar</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">field</span> <span class="token directive function">@skip</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token variable">$foo</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">subfieldA</span> <span class="token punctuation">}</span> <span class="token property">field</span> <span class="token directive function">@skip</span><span class="token punctuation">(</span><span class="token attr-name">if</span><span class="token punctuation">:</span> <span class="token variable">$bar</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">subfieldB</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> </section> <section id="sec-Validation.Variables" secid="5.8"> <h2 data-source="spec/Section%205%20--%20Validation.md#L1523"><span class="spec-secid" title="link to this section"><a href="#sec-Validation.Variables">5.8</a></span>Variables</h2> <section id="sec-Variable-Uniqueness" secid="5.8.1"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1525"><span class="spec-secid" title="link to this section"><a href="#sec-Variable-Uniqueness">5.8.1</a></span>Variable Uniqueness</h3> <section id="sec-Variable-Uniqueness.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1527"><a href="#sec-Variable-Uniqueness.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1529-L1534">For every <var data-name="operation">operation</var> in the document<ul> <li data-source="spec/Section%205%20--%20Validation.md#L1530-L1534">For every <var data-name="variable">variable</var> defined on <var data-name="operation">operation</var><ul> <li data-source="spec/Section%205%20--%20Validation.md#L1531">Let <var data-name="variableName">variableName</var> be the name of <var data-name="variable">variable</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1532-L1533">Let <var data-name="variables">variables</var> be the set of all variables named <var data-name="variableName">variableName</var> on <var data-name="operation">operation</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1534"><var data-name="variables">variables</var> must be a set of one</li> </ul> </li> </ul> </li> </ul> </section> <section id="sec-Variable-Uniqueness.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1536"><a href="#sec-Variable-Uniqueness.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1538-L1540">If any operation defines more than one variable with the same name, it is ambiguous and invalid. It is invalid even if the type of the duplicate variable is the same.</p> <pre id="example-abc9c" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1542-L1548"><a href="#example-abc9c">Counter Example № 165</a><code><span class="token keyword">query</span> <span class="token definition-query function">houseTrainedQuery</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">,</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1551-L1552">It is valid for multiple operations to define a variable with the same name. If two operations reference the same fragment, it might actually be necessary:</p> <pre id="example-54c93" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1554-L1568"><a href="#example-54c93">Example № 166</a><code><span class="token keyword">query</span> <span class="token constant">A</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">HouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token constant">B</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">HouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">HouseTrainedFragment</span> <span class="token keyword">on</span> <span class="token class-name">Query</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-Variables-Are-Input-Types" secid="5.8.2"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1571"><span class="spec-secid" title="link to this section"><a href="#sec-Variables-Are-Input-Types">5.8.2</a></span>Variables Are Input Types</h3> <section id="sec-Variables-Are-Input-Types.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1573"><a href="#sec-Variables-Are-Input-Types.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1575">For every <var data-name="operation">operation</var> in a <var data-name="document">document</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1576-L1578">For every <var data-name="variable">variable</var> on each <var data-name="operation">operation</var><ul> <li data-source="spec/Section%205%20--%20Validation.md#L1577">Let <var data-name="variableType">variableType</var> be the type of <var data-name="variable">variable</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1578"><span class="spec-call"><a href="#IsInputType()" data-name="IsInputType">IsInputType</a>(<var data-name="variableType">variableType</var>)</span> must be <span class="spec-keyword">true</span></li> </ul> </li> </ul> </section> <section id="sec-Variables-Are-Input-Types.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1580"><a href="#sec-Variables-Are-Input-Types.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1582-L1583">Variables can only be input types. Objects, unions, and interfaces cannot be used as inputs.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1585">For these examples, consider the following type system additions:</p> <pre id="example-ce150" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1587-L1597"><a href="#example-ce150">Example № 167</a><code><span class="token keyword">input</span> <span class="token atom-input class-name">ComplexInput</span> <span class="token punctuation">{</span> <span class="token attr-name">name</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token attr-name">owner</span><span class="token punctuation">:</span> <span class="token scalar">String</span> <span class="token punctuation">}</span> <span class="token keyword">extend</span> <span class="token keyword">type</span> <span class="token class-name">Query</span> <span class="token punctuation">{</span> <span class="token attr-name">findDog</span><span class="token punctuation">(</span><span class="token attr-name">complex</span><span class="token punctuation">:</span> <span class="token atom-input class-name">ComplexInput</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name">Dog</span> <span class="token attr-name">booleanList</span><span class="token punctuation">(</span><span class="token attr-name">booleanListArg</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token scalar">Boolean</span><span class="token operator">!</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1599">The following operations are valid:</p> <pre id="example-a4255" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1601-L1617"><a href="#example-a4255">Example № 168</a><code><span class="token keyword">query</span> <span class="token definition-query function">takesBoolean</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">takes</span><span class="token atom-input class-name">ComplexInput</span><span class="token punctuation">(</span><span class="token variable">$complexInput</span><span class="token punctuation">:</span> <span class="token atom-input class-name">ComplexInput</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property-query">findDog</span><span class="token punctuation">(</span><span class="token attr-name">complex</span><span class="token punctuation">:</span> <span class="token variable">$complexInput</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">TakesListOfBooleanBang</span><span class="token punctuation">(</span><span class="token variable">$booleans</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token scalar">Boolean</span><span class="token operator">!</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property-query">booleanList</span><span class="token punctuation">(</span><span class="token attr-name">booleanListArg</span><span class="token punctuation">:</span> <span class="token variable">$booleans</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1619">The following operations are invalid:</p> <pre id="example-aeba9" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1621-L1637"><a href="#example-aeba9">Counter Example № 169</a><code><span class="token keyword">query</span> <span class="token definition-query function">takesCat</span><span class="token punctuation">(</span><span class="token variable">$cat</span><span class="token punctuation">:</span> <span class="token class-name">Cat</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment"># ...</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">takesDogBang</span><span class="token punctuation">(</span><span class="token variable">$dog</span><span class="token punctuation">:</span> <span class="token class-name">Dog</span><span class="token operator">!</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment"># ...</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">takesListOfPet</span><span class="token punctuation">(</span><span class="token variable">$pets</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token class-name">Pet</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment"># ...</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">takesCatOrDog</span><span class="token punctuation">(</span><span class="token variable">$catOrDog</span><span class="token punctuation">:</span> <span class="token class-name">CatOrDog</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment"># ...</span> <span class="token punctuation">}</span> </code></pre> </section> </section> <section id="sec-All-Variable-Uses-Defined" secid="5.8.3"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1640"><span class="spec-secid" title="link to this section"><a href="#sec-All-Variable-Uses-Defined">5.8.3</a></span>All Variable Uses Defined</h3> <section id="sec-All-Variable-Uses-Defined.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1642"><a href="#sec-All-Variable-Uses-Defined.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1644-L1649">For each <var data-name="operation">operation</var> in a document<ul> <li data-source="spec/Section%205%20--%20Validation.md#L1645">For each <var data-name="variableUsage">variableUsage</var> in scope, variable must be in <var data-name="operation">operation</var>‘s variable list.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1646">Let <var data-name="fragments">fragments</var> be every fragment referenced by that <var data-name="operation">operation</var> transitively</li> <li data-source="spec/Section%205%20--%20Validation.md#L1647-L1649">For each <var data-name="fragment">fragment</var> in <var data-name="fragments">fragments</var><ul> <li data-source="spec/Section%205%20--%20Validation.md#L1648-L1649">For each <var data-name="variableUsage">variableUsage</var> in scope of <var data-name="fragment">fragment</var>, variable must be in <var data-name="operation">operation</var>‘s variable list.</li> </ul> </li> </ul> </li> </ul> </section> <section id="sec-All-Variable-Uses-Defined.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1651"><a href="#sec-All-Variable-Uses-Defined.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1653-L1655">Variables are scoped on a per-operation basis. That means that any variable used within the context of an operation must be defined at the top level of that operation</p> <p data-source="spec/Section%205%20--%20Validation.md#L1657">For example:</p> <pre id="example-38119" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1659-L1665"><a href="#example-38119">Example № 170</a><code><span class="token keyword">query</span> <span class="token definition-query function">variableIsDefined</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1667">is valid. $<var data-name="atOtherHomes">atOtherHomes</var> is defined by the operation.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1669">By contrast the following document is invalid:</p> <pre id="example-5ba94" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1671-L1677"><a href="#example-5ba94">Counter Example № 171</a><code><span class="token keyword">query</span> <span class="token definition-query function">variableIsNotDefined</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1679">$<var data-name="atOtherHomes">atOtherHomes</var> is not defined by the operation.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1681-L1684">Fragments complicate this rule. Any fragment transitively included by an operation has access to the variables defined by that operation. Fragments can appear within multiple operations and therefore variable usages must correspond to variable definitions in all of those operations.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1686">For example the following is valid:</p> <pre id="example-559c2" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1688-L1698"><a href="#example-559c2">Example № 172</a><code><span class="token keyword">query</span> <span class="token definition-query function">variableIsDefinedUsedInSingleFragment</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">isHouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">isHouseTrainedFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1700-L1702">since <var data-name="isHouseTrainedFragment">isHouseTrainedFragment</var> is used within the context of the operation <var data-name="variableIsDefinedUsedInSingleFragment">variableIsDefinedUsedInSingleFragment</var> and the variable is defined by that operation.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1704-L1705">On the other hand, if a fragment is included within an operation that does not define a referenced variable, the document is invalid.</p> <pre id="example-93d3e" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1707-L1717"><a href="#example-93d3e">Counter Example № 173</a><code><span class="token keyword">query</span> <span class="token definition-query function">variableIsNotDefinedUsedInSingleFragment</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">isHouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">isHouseTrainedFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1719">This applies transitively as well, so the following also fails:</p> <pre id="example-ee7be" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1721-L1735"><a href="#example-ee7be">Counter Example № 174</a><code><span class="token keyword">query</span> <span class="token definition-query function">variableIsNotDefinedUsedInNestedFragment</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">outerHouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">outerHouseTrainedFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">isHouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">isHouseTrainedFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1737-L1738">Variables must be defined in all operations in which a fragment is used.</p> <pre id="example-d601e" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1740-L1756"><a href="#example-d601e">Example № 175</a><code><span class="token keyword">query</span> <span class="token definition-query function">houseTrainedQueryOne</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">isHouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">houseTrainedQueryTwo</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">isHouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">isHouseTrainedFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1758">However the following does not validate:</p> <pre id="example-2b284" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1760-L1776"><a href="#example-2b284">Counter Example № 176</a><code><span class="token keyword">query</span> <span class="token definition-query function">houseTrainedQueryOne</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">isHouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">houseTrainedQueryTwoNotDefined</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">isHouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">isHouseTrainedFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1778-L1780">This is because <var data-name="houseTrainedQueryTwoNotDefined">houseTrainedQueryTwoNotDefined</var> does not define a variable $<var data-name="atOtherHomes">atOtherHomes</var> but that variable is used by <var data-name="isHouseTrainedFragment">isHouseTrainedFragment</var> which is included in that operation.</p> </section> </section> <section id="sec-All-Variables-Used" secid="5.8.4"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1783"><span class="spec-secid" title="link to this section"><a href="#sec-All-Variables-Used">5.8.4</a></span>All Variables Used</h3> <section id="sec-All-Variables-Used.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1785"><a href="#sec-All-Variables-Used.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1787">For every <var data-name="operation">operation</var> in the document.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1788">Let <var data-name="variables">variables</var> be the variables defined by that <var data-name="operation">operation</var></li> <li data-source="spec/Section%205%20--%20Validation.md#L1789-L1791">Each <var data-name="variable">variable</var> in <var data-name="variables">variables</var> must be used at least once in either the operation scope itself or any fragment transitively referenced by that operation.</li> </ul> </section> <section id="sec-All-Variables-Used.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1793"><a href="#sec-All-Variables-Used.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1795-L1797">All variables defined by an operation must be used in that operation or a fragment transitively included by that operation. Unused variables cause a validation error.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1799">For example the following is invalid:</p> <pre id="example-464b6" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1801-L1807"><a href="#example-464b6">Counter Example № 177</a><code><span class="token keyword">query</span> <span class="token definition-query function">variableUnused</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token property">isHouseTrained</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1809">because $<var data-name="atOtherHomes">atOtherHomes</var> is not referenced.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1811">These rules apply to transitive fragment spreads as well:</p> <pre id="example-6d4bb" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1813-L1823"><a href="#example-6d4bb">Example № 178</a><code><span class="token keyword">query</span> <span class="token definition-query function">variableUsedInFragment</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">isHouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">isHouseTrainedFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1825-L1826">The above is valid since $<var data-name="atOtherHomes">atOtherHomes</var> is used in <var data-name="isHouseTrainedFragment">isHouseTrainedFragment</var> which is included by <var data-name="variableUsedInFragment">variableUsedInFragment</var>.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1828">If that fragment did not have a reference to $<var data-name="atOtherHomes">atOtherHomes</var> it would be not valid:</p> <pre id="example-a30e2" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1830-L1840"><a href="#example-a30e2">Counter Example № 179</a><code><span class="token keyword">query</span> <span class="token definition-query function">variableNotUsedWithinFragment</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">isHouseTrainedWithoutVariableFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">isHouseTrainedWithoutVariableFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property">isHouseTrained</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1842">All operations in a document must use all of their variables.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1844">As a result, the following document does not validate.</p> <pre id="example-e647f" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1846-L1862"><a href="#example-e647f">Counter Example № 180</a><code><span class="token keyword">query</span> <span class="token definition-query function">queryWithUsedVar</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">isHouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">query</span> <span class="token definition-query function">queryWithExtraVar</span><span class="token punctuation">(</span><span class="token variable">$atOtherHomes</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">,</span> <span class="token variable">$extra</span><span class="token punctuation">:</span> <span class="token scalar">Int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">dog</span> <span class="token punctuation">{</span> <span class="token operator">...</span><span class="token fragment function">isHouseTrainedFragment</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">isHouseTrainedFragment</span> <span class="token keyword">on</span> <span class="token class-name">Dog</span> <span class="token punctuation">{</span> <span class="token property-query">isHouseTrained</span><span class="token punctuation">(</span><span class="token attr-name">atOtherHomes</span><span class="token punctuation">:</span> <span class="token variable">$atOtherHomes</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1864-L1865">This document is not valid because <var data-name="queryWithExtraVar">queryWithExtraVar</var> defines an extraneous variable.</p> </section> </section> <section id="sec-All-Variable-Usages-are-Allowed" secid="5.8.5"> <h3 data-source="spec/Section%205%20--%20Validation.md#L1868"><span class="spec-secid" title="link to this section"><a href="#sec-All-Variable-Usages-are-Allowed">5.8.5</a></span>All Variable Usages are Allowed</h3> <section id="sec-All-Variable-Usages-are-Allowed.Formal-Specification" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1870"><a href="#sec-All-Variable-Usages-are-Allowed.Formal-Specification" title="link to this subsection">Formal Specification</a></h6> <ul> <li data-source="spec/Section%205%20--%20Validation.md#L1872">For each <var data-name="operation">operation</var> in <var data-name="document">document</var>:</li> <li data-source="spec/Section%205%20--%20Validation.md#L1873">Let <var data-name="variableUsages">variableUsages</var> be all usages transitively included in the <var data-name="operation">operation</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1874-L1878">For each <var data-name="variableUsage">variableUsage</var> in <var data-name="variableUsages">variableUsages</var>:<ul> <li data-source="spec/Section%205%20--%20Validation.md#L1875">Let <var data-name="variableName">variableName</var> be the name of <var data-name="variableUsage">variableUsage</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1876-L1877">Let <var data-name="variableDefinition">variableDefinition</var> be the <span class="spec-nt"><a href="#VariableDefinition" data-name="VariableDefinition">VariableDefinition</a></span> named <var data-name="variableName">variableName</var> defined within <var data-name="operation">operation</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1878"><span class="spec-call"><a href="#IsVariableUsageAllowed()" data-name="IsVariableUsageAllowed">IsVariableUsageAllowed</a>(<var data-name="variableDefinition">variableDefinition</var>, <var data-name="variableUsage">variableUsage</var>)</span> must be <span class="spec-keyword">true</span>.</li> </ul> </li> </ul> <div class="spec-algo" id="IsVariableUsageAllowed()" data-source="spec/Section%205%20--%20Validation.md#L1880-L1894"> <span class="spec-call"><a href="#IsVariableUsageAllowed()" data-name="IsVariableUsageAllowed">IsVariableUsageAllowed</a>(<var data-name="variableDefinition">variableDefinition</var>, <var data-name="variableUsage">variableUsage</var>)</span><ol> <li data-source="spec/Section%205%20--%20Validation.md#L1882">Let <var data-name="variableType">variableType</var> be the expected type of <var data-name="variableDefinition">variableDefinition</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1883-L1884">Let <var data-name="locationType">locationType</var> be the expected type of the <span class="spec-nt"><a href="#Argument" data-name="Argument">Argument</a></span>, <span class="spec-nt"><a href="#ObjectField" data-name="ObjectField">ObjectField</a></span>, or <span class="spec-nt"><a href="#ListValue" data-name="ListValue">ListValue</a></span> entry where <var data-name="variableUsage">variableUsage</var> is located.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1885-L1893">If <var data-name="locationType">locationType</var> is a non-null type AND <var data-name="variableType">variableType</var> is NOT a non-null type:<ol> <li data-source="spec/Section%205%20--%20Validation.md#L1886-L1887">Let <var data-name="hasNonNullVariableDefaultValue">hasNonNullVariableDefaultValue</var> be <span class="spec-keyword">true</span> if a default value exists for <var data-name="variableDefinition">variableDefinition</var> and is not the value <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1888-L1889">Let <var data-name="hasLocationDefaultValue">hasLocationDefaultValue</var> be <span class="spec-keyword">true</span> if a default value exists for the <span class="spec-nt"><a href="#Argument" data-name="Argument">Argument</a></span> or <span class="spec-nt"><a href="#ObjectField" data-name="ObjectField">ObjectField</a></span> where <var data-name="variableUsage">variableUsage</var> is located.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1890-L1891">If <var data-name="hasNonNullVariableDefaultValue">hasNonNullVariableDefaultValue</var> is NOT <span class="spec-keyword">true</span> AND <var data-name="hasLocationDefaultValue">hasLocationDefaultValue</var> is NOT <span class="spec-keyword">true</span>, return <span class="spec-keyword">false</span>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1892">Let <var data-name="nullableLocationType">nullableLocationType</var> be the unwrapped nullable type of <var data-name="locationType">locationType</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1893">Return <span class="spec-call"><a href="#AreTypesCompatible()" data-name="AreTypesCompatible">AreTypesCompatible</a>(<var data-name="variableType">variableType</var>, <var data-name="nullableLocationType">nullableLocationType</var>)</span>.</li> </ol> </li> <li data-source="spec/Section%205%20--%20Validation.md#L1894">Return <span class="spec-call"><a href="#AreTypesCompatible()" data-name="AreTypesCompatible">AreTypesCompatible</a>(<var data-name="variableType">variableType</var>, <var data-name="locationType">locationType</var>)</span>.</li> </ol> </div> <div class="spec-algo" id="AreTypesCompatible()" data-source="spec/Section%205%20--%20Validation.md#L1896-L1912"> <span class="spec-call"><a href="#AreTypesCompatible()" data-name="AreTypesCompatible">AreTypesCompatible</a>(<var data-name="variableType">variableType</var>, <var data-name="locationType">locationType</var>)</span><ol> <li data-source="spec/Section%205%20--%20Validation.md#L1898-L1902">If <var data-name="locationType">locationType</var> is a non-null type:<ol> <li data-source="spec/Section%205%20--%20Validation.md#L1899">If <var data-name="variableType">variableType</var> is NOT a non-null type, return <span class="spec-keyword">false</span>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1900">Let <var data-name="nullableLocationType">nullableLocationType</var> be the unwrapped nullable type of <var data-name="locationType">locationType</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1901">Let <var data-name="nullableVariableType">nullableVariableType</var> be the unwrapped nullable type of <var data-name="variableType">variableType</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1902">Return <span class="spec-call"><a href="#AreTypesCompatible()" data-name="AreTypesCompatible">AreTypesCompatible</a>(<var data-name="nullableVariableType">nullableVariableType</var>, <var data-name="nullableLocationType">nullableLocationType</var>)</span>.</li> </ol> </li> <li data-source="spec/Section%205%20--%20Validation.md#L1903-L1905">Otherwise, if <var data-name="variableType">variableType</var> is a non-null type:<ol> <li data-source="spec/Section%205%20--%20Validation.md#L1904">Let <var data-name="nullableVariableType">nullableVariableType</var> be the nullable type of <var data-name="variableType">variableType</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1905">Return <span class="spec-call"><a href="#AreTypesCompatible()" data-name="AreTypesCompatible">AreTypesCompatible</a>(<var data-name="nullableVariableType">nullableVariableType</var>, <var data-name="locationType">locationType</var>)</span>.</li> </ol> </li> <li data-source="spec/Section%205%20--%20Validation.md#L1906-L1910">Otherwise, if <var data-name="locationType">locationType</var> is a list type:<ol> <li data-source="spec/Section%205%20--%20Validation.md#L1907">If <var data-name="variableType">variableType</var> is NOT a list type, return <span class="spec-keyword">false</span>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1908">Let <var data-name="itemLocationType">itemLocationType</var> be the unwrapped item type of <var data-name="locationType">locationType</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1909">Let <var data-name="itemVariableType">itemVariableType</var> be the unwrapped item type of <var data-name="variableType">variableType</var>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1910">Return <span class="spec-call"><a href="#AreTypesCompatible()" data-name="AreTypesCompatible">AreTypesCompatible</a>(<var data-name="itemVariableType">itemVariableType</var>, <var data-name="itemLocationType">itemLocationType</var>)</span>.</li> </ol> </li> <li data-source="spec/Section%205%20--%20Validation.md#L1911">Otherwise, if <var data-name="variableType">variableType</var> is a list type, return <span class="spec-keyword">false</span>.</li> <li data-source="spec/Section%205%20--%20Validation.md#L1912">Return <span class="spec-keyword">true</span> if <var data-name="variableType">variableType</var> and <var data-name="locationType">locationType</var> are identical, otherwise <span class="spec-keyword">false</span>.</li> </ol> </div> </section> <section id="sec-All-Variable-Usages-are-Allowed.Explanatory-Text" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1914"><a href="#sec-All-Variable-Usages-are-Allowed.Explanatory-Text" title="link to this subsection">Explanatory Text</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1916">Variable usages must be compatible with the arguments they are passed to.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1918-L1920">Validation failures occur when variables are used in the context of types that are complete mismatches, or if a nullable type in a variable is passed to a non-null argument type.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1922">Types must match:</p> <pre id="example-2028e" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1924-L1930"><a href="#example-2028e">Counter Example № 181</a><code><span class="token keyword">query</span> <span class="token definition-query function">intCannotGoIntoBoolean</span><span class="token punctuation">(</span><span class="token variable">$intArg</span><span class="token punctuation">:</span> <span class="token scalar">Int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">arguments</span> <span class="token punctuation">{</span> <span class="token property-query">booleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">booleanArg</span><span class="token punctuation">:</span> <span class="token variable">$intArg</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1932">$<var data-name="intArg">intArg</var> typed as <span class="spec-nt"><span data-name="Int">Int</span></span> cannot be used as an argument to <var data-name="booleanArg">booleanArg</var>, typed as <span class="spec-nt"><span data-name="Boolean">Boolean</span></span>.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1934-L1935">List cardinality must also be the same. For example, lists cannot be passed into singular values.</p> <pre id="example-8d369" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1937-L1943"><a href="#example-8d369">Counter Example № 182</a><code><span class="token keyword">query</span> <span class="token definition-query function">booleanListCannotGoIntoBoolean</span><span class="token punctuation">(</span><span class="token variable">$booleanListArg</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token scalar">Boolean</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">arguments</span> <span class="token punctuation">{</span> <span class="token property-query">booleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">booleanArg</span><span class="token punctuation">:</span> <span class="token variable">$booleanListArg</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1945-L1946">Nullability must also be respected. In general a nullable variable cannot be passed to a non-null argument.</p> <pre id="example-ed727" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1948-L1954"><a href="#example-ed727">Counter Example № 183</a><code><span class="token keyword">query</span> <span class="token definition-query function">booleanArgQuery</span><span class="token punctuation">(</span><span class="token variable">$booleanArg</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">arguments</span> <span class="token punctuation">{</span> <span class="token property-query">nonNullBooleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">nonNullBooleanArg</span><span class="token punctuation">:</span> <span class="token variable">$booleanArg</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1956-L1959">For list types, the same rules around nullability apply to both outer types and inner types. A nullable list cannot be passed to a non-null list, and a list of nullable values cannot be passed to a list of non-null values. The following is valid:</p> <pre id="example-c5959" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1961-L1967"><a href="#example-c5959">Example № 184</a><code><span class="token keyword">query</span> <span class="token definition-query function">nonNullListToList</span><span class="token punctuation">(</span><span class="token variable">$nonNullBooleanList</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token scalar">Boolean</span><span class="token punctuation">]</span><span class="token operator">!</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">arguments</span> <span class="token punctuation">{</span> <span class="token property-query">booleanListArgField</span><span class="token punctuation">(</span><span class="token attr-name">booleanListArg</span><span class="token punctuation">:</span> <span class="token variable">$nonNullBooleanList</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1969">However, a nullable list cannot be passed to a non-null list:</p> <pre id="example-64255" class="spec-counter-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1971-L1977"><a href="#example-64255">Counter Example № 185</a><code><span class="token keyword">query</span> <span class="token definition-query function">listToNonNullList</span><span class="token punctuation">(</span><span class="token variable">$booleanList</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token scalar">Boolean</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">arguments</span> <span class="token punctuation">{</span> <span class="token property-query">nonNullBooleanListField</span><span class="token punctuation">(</span><span class="token attr-name">nonNullBooleanListArg</span><span class="token punctuation">:</span> <span class="token variable">$booleanList</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L1979-L1980">This would fail validation because a <code>[T]</code> cannot be passed to a <code>[T]!</code>. Similarly a <code>[T]</code> cannot be passed to a <code>[T!]</code>.</p> </section> <section id="sec-All-Variable-Usages-are-Allowed.Allowing-optional-variables-when-default-values-exist" class="subsec"> <h6 data-source="spec/Section%205%20--%20Validation.md#L1982"><a href="#sec-All-Variable-Usages-are-Allowed.Allowing-optional-variables-when-default-values-exist" title="link to this subsection">Allowing optional variables when default values exist</a></h6> <p data-source="spec/Section%205%20--%20Validation.md#L1984-L1986">A notable exception to typical variable type compatibility is allowing a variable definition with a nullable type to be provided to a non-null location as long as either that variable or that location provides a default value.</p> <p data-source="spec/Section%205%20--%20Validation.md#L1988-L1990">In the example below, an optional variable <code>$booleanArg</code> is allowed to be used in the non-null argument <code>optionalBooleanArg</code> because the field argument is optional since it provides a default value in the schema.</p> <pre id="example-0877c" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L1992-L1998"><a href="#example-0877c">Example № 186</a><code><span class="token keyword">query</span> <span class="token definition-query function">booleanArgQueryWithDefault</span><span class="token punctuation">(</span><span class="token variable">$booleanArg</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">arguments</span> <span class="token punctuation">{</span> <span class="token property-query">optionalNonNullBooleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">optionalBooleanArg</span><span class="token punctuation">:</span> <span class="token variable">$booleanArg</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%205%20--%20Validation.md#L2000-L2005">In the example below, an optional variable <code>$booleanArg</code> is allowed to be used in the non-null argument (<code>nonNullBooleanArg</code>) because the variable provides a default value in the operation. This behavior is explicitly supported for compatibility with earlier editions of this specification. GraphQL authoring tools may wish to report this as a warning with the suggestion to replace <code>Boolean</code> with <code>Boolean!</code> to avoid ambiguity.</p> <pre id="example-d24d9" class="spec-example" data-language="graphql" data-source="spec/Section%205%20--%20Validation.md#L2007-L2013"><a href="#example-d24d9">Example № 187</a><code><span class="token keyword">query</span> <span class="token definition-query function">booleanArgQueryWithDefault</span><span class="token punctuation">(</span><span class="token variable">$booleanArg</span><span class="token punctuation">:</span> <span class="token scalar">Boolean</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token object">arguments</span> <span class="token punctuation">{</span> <span class="token property-query">nonNullBooleanArgField</span><span class="token punctuation">(</span><span class="token attr-name">nonNullBooleanArg</span><span class="token punctuation">:</span> <span class="token variable">$booleanArg</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <div id="note-f0f28" class="spec-note" data-source="spec/Section%205%20--%20Validation.md#L2015-L2017"> <a href="#note-f0f28">Note</a> The value <span class="spec-keyword">null</span> could still be provided to such a variable at runtime. A non-null argument must raise a field error if provided a <span class="spec-keyword">null</span> value. </div> </section> </section> </section> </section> <section id="sec-Execution" secid="6"> <h1 data-source="spec/Section%206%20--%20Execution.md#L1"><span class="spec-secid" title="link to this section"><a href="#sec-Execution">6</a></span>Execution</h1> <p data-source="spec/Section%206%20--%20Execution.md#L3">GraphQL generates a response from a request via execution.</p> <p data-source="spec/Section%206%20--%20Execution.md#L5">A request for execution consists of a few pieces of information:</p> <ul> <li data-source="spec/Section%206%20--%20Execution.md#L7">The schema to use, typically solely provided by the GraphQL service.</li> <li data-source="spec/Section%206%20--%20Execution.md#L8">A <span class="spec-nt"><a href="#Document" data-name="Document">Document</a></span> which must contain GraphQL <span class="spec-nt"><a href="#OperationDefinition" data-name="OperationDefinition">OperationDefinition</a></span> and may contain <span class="spec-nt"><a href="#FragmentDefinition" data-name="FragmentDefinition">FragmentDefinition</a></span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L9">Optionally: The name of the Operation in the Document to execute.</li> <li data-source="spec/Section%206%20--%20Execution.md#L10">Optionally: Values for any Variables defined by the Operation.</li> <li data-source="spec/Section%206%20--%20Execution.md#L11-L14">An initial value corresponding to the root type being executed. Conceptually, an initial value represents the “universe” of data available via a GraphQL Service. It is common for a GraphQL Service to always use the same initial value for every request.</li> </ul> <p data-source="spec/Section%206%20--%20Execution.md#L16-L17">Given this information, the result of <span class="spec-call"><a href="#ExecuteRequest()" data-name="ExecuteRequest">ExecuteRequest</a>()</span> produces the response, to be formatted according to the Response section below.</p> <section id="sec-Executing-Requests" secid="6.1"> <h2 data-source="spec/Section%206%20--%20Execution.md#L20"><span class="spec-secid" title="link to this section"><a href="#sec-Executing-Requests">6.1</a></span>Executing Requests</h2> <p data-source="spec/Section%206%20--%20Execution.md#L22-L26">To execute a request, the executor must have a parsed <span class="spec-nt"><a href="#Document" data-name="Document">Document</a></span> and a selected operation name to run if the document defines multiple operations, otherwise the document is expected to only contain a single operation. The result of the request is determined by the result of executing this operation according to the “Executing Operations” section below.</p> <div class="spec-algo" id="ExecuteRequest()" data-source="spec/Section%206%20--%20Execution.md#L28-L37"> <span class="spec-call"><a href="#ExecuteRequest()" data-name="ExecuteRequest">ExecuteRequest</a>(<var data-name="schema">schema</var>, <var data-name="document">document</var>, <var data-name="operationName">operationName</var>, <var data-name="variableValues">variableValues</var>, <var data-name="initialValue">initialValue</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L30">Let <var data-name="operation">operation</var> be the result of <span class="spec-call"><a href="#GetOperation()" data-name="GetOperation">GetOperation</a>(<var data-name="document">document</var>, <var data-name="operationName">operationName</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L31">Let <var data-name="coercedVariableValues">coercedVariableValues</var> be the result of <span class="spec-call"><a href="#CoerceVariableValues()" data-name="CoerceVariableValues">CoerceVariableValues</a>(<var data-name="schema">schema</var>, <var data-name="operation">operation</var>, <var data-name="variableValues">variableValues</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L32-L33">If <var data-name="operation">operation</var> is a query operation:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L33">Return <span class="spec-call"><a href="#ExecuteQuery()" data-name="ExecuteQuery">ExecuteQuery</a>(<var data-name="operation">operation</var>, <var data-name="schema">schema</var>, <var data-name="coercedVariableValues">coercedVariableValues</var>, <var data-name="initialValue">initialValue</var>)</span>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L34-L35">Otherwise if <var data-name="operation">operation</var> is a mutation operation:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L35">Return <span class="spec-call"><a href="#ExecuteMutation()" data-name="ExecuteMutation">ExecuteMutation</a>(<var data-name="operation">operation</var>, <var data-name="schema">schema</var>, <var data-name="coercedVariableValues">coercedVariableValues</var>, <var data-name="initialValue">initialValue</var>)</span>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L36-L37">Otherwise if <var data-name="operation">operation</var> is a subscription operation:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L37">Return <span class="spec-call"><a href="#Subscribe()" data-name="Subscribe">Subscribe</a>(<var data-name="operation">operation</var>, <var data-name="schema">schema</var>, <var data-name="coercedVariableValues">coercedVariableValues</var>, <var data-name="initialValue">initialValue</var>)</span>.</li> </ol> </li> </ol> </div> <div class="spec-algo" id="GetOperation()" data-source="spec/Section%206%20--%20Execution.md#L39-L48"> <span class="spec-call"><a href="#GetOperation()" data-name="GetOperation">GetOperation</a>(<var data-name="document">document</var>, <var data-name="operationName">operationName</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L41-L44">If <var data-name="operationName">operationName</var> is <span class="spec-keyword">null</span>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L42-L43">If <var data-name="document">document</var> contains exactly one operation.<ol> <li data-source="spec/Section%206%20--%20Execution.md#L43">Return the Operation contained in the <var data-name="document">document</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L44">Otherwise raise a request error requiring <var data-name="operationName">operationName</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L45-L48">Otherwise:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L46">Let <var data-name="operation">operation</var> be the Operation named <var data-name="operationName">operationName</var> in <var data-name="document">document</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L47">If <var data-name="operation">operation</var> was not found, raise a request error.</li> <li data-source="spec/Section%206%20--%20Execution.md#L48">Return <var data-name="operation">operation</var>.</li> </ol> </li> </ol> </div> <section id="sec-Validating-Requests" secid="6.1.1"> <h3 data-source="spec/Section%206%20--%20Execution.md#L51"><span class="spec-secid" title="link to this section"><a href="#sec-Validating-Requests">6.1.1</a></span>Validating Requests</h3> <p data-source="spec/Section%206%20--%20Execution.md#L53-L56">As explained in the Validation section, only requests which pass all validation rules should be executed. If validation errors are known, they should be reported in the list of “errors” in the response and the request must fail without execution.</p> <p data-source="spec/Section%206%20--%20Execution.md#L58-L63">Typically validation is performed in the context of a request immediately before execution, however a GraphQL service may execute a request without immediately validating it if that exact same request is known to have been validated before. A GraphQL service should only execute requests which <em>at some point</em> were known to be free of any validation errors, and have since not changed.</p> <p data-source="spec/Section%206%20--%20Execution.md#L65-L67">For example: the request may be validated during development, provided it does not later change, or a service may validate a request once and memoize the result to avoid validating the same request again in the future.</p> </section> <section id="sec-Coercing-Variable-Values" secid="6.1.2"> <h3 data-source="spec/Section%206%20--%20Execution.md#L70"><span class="spec-secid" title="link to this section"><a href="#sec-Coercing-Variable-Values">6.1.2</a></span>Coercing Variable Values</h3> <p data-source="spec/Section%206%20--%20Execution.md#L72-L76">If the operation has defined any variables, then the values for those variables need to be coerced using the input coercion rules of variable’s declared type. If a request error is encountered during input coercion of variable values, then the operation fails without execution.</p> <div class="spec-algo" id="CoerceVariableValues()" data-source="spec/Section%206%20--%20Execution.md#L78-L107"> <span class="spec-call"><a href="#CoerceVariableValues()" data-name="CoerceVariableValues">CoerceVariableValues</a>(<var data-name="schema">schema</var>, <var data-name="operation">operation</var>, <var data-name="variableValues">variableValues</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L80">Let <var data-name="coercedValues">coercedValues</var> be an empty unordered Map.</li> <li data-source="spec/Section%206%20--%20Execution.md#L81">Let <var data-name="variableDefinitions">variableDefinitions</var> be the variables defined by <var data-name="operation">operation</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L82-L106">For each <var data-name="variableDefinition">variableDefinition</var> in <var data-name="variableDefinitions">variableDefinitions</var>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L83">Let <var data-name="variableName">variableName</var> be the name of <var data-name="variableDefinition">variableDefinition</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L84">Let <var data-name="variableType">variableType</var> be the expected type of <var data-name="variableDefinition">variableDefinition</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L85">Assert: <span class="spec-call"><a href="#IsInputType()" data-name="IsInputType">IsInputType</a>(<var data-name="variableType">variableType</var>)</span> must be <span class="spec-keyword">true</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L86">Let <var data-name="defaultValue">defaultValue</var> be the default value for <var data-name="variableDefinition">variableDefinition</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L87-L88">Let <var data-name="hasValue">hasValue</var> be <span class="spec-keyword">true</span> if <var data-name="variableValues">variableValues</var> provides a value for the name <var data-name="variableName">variableName</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L89-L90">Let <var data-name="value">value</var> be the value provided in <var data-name="variableValues">variableValues</var> for the name <var data-name="variableName">variableName</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L91-L93">If <var data-name="hasValue">hasValue</var> is not <span class="spec-keyword">true</span> and <var data-name="defaultValue">defaultValue</var> exists (including <span class="spec-keyword">null</span>):<ol> <li data-source="spec/Section%206%20--%20Execution.md#L92-L93">Add an entry to <var data-name="coercedValues">coercedValues</var> named <var data-name="variableName">variableName</var> with the value <var data-name="defaultValue">defaultValue</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L94-L95">Otherwise if <var data-name="variableType">variableType</var> is a Non-Nullable type, and either <var data-name="hasValue">hasValue</var> is not <span class="spec-keyword">true</span> or <var data-name="value">value</var> is <span class="spec-keyword">null</span>, raise a request error.</li> <li data-source="spec/Section%206%20--%20Execution.md#L96-L106">Otherwise if <var data-name="hasValue">hasValue</var> is true:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L97-L99">If <var data-name="value">value</var> is <span class="spec-keyword">null</span>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L98-L99">Add an entry to <var data-name="coercedValues">coercedValues</var> named <var data-name="variableName">variableName</var> with the value <span class="spec-keyword">null</span>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L100-L106">Otherwise:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L101-L102">If <var data-name="value">value</var> cannot be coerced according to the input coercion rules of <var data-name="variableType">variableType</var>, raise a request error.</li> <li data-source="spec/Section%206%20--%20Execution.md#L103-L104">Let <var data-name="coercedValue">coercedValue</var> be the result of coercing <var data-name="value">value</var> according to the input coercion rules of <var data-name="variableType">variableType</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L105-L106">Add an entry to <var data-name="coercedValues">coercedValues</var> named <var data-name="variableName">variableName</var> with the value <var data-name="coercedValue">coercedValue</var>.</li> </ol> </li> </ol> </li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L107">Return <var data-name="coercedValues">coercedValues</var>.</li> </ol> </div> <div id="note-38e04" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L109"> <a href="#note-38e04">Note</a> This algorithm is very similar to <span class="spec-call"><a href="#CoerceArgumentValues()" data-name="CoerceArgumentValues">CoerceArgumentValues</a>()</span>.</div> </section> </section> <section id="sec-Executing-Operations" secid="6.2"> <h2 data-source="spec/Section%206%20--%20Execution.md#L112"><span class="spec-secid" title="link to this section"><a href="#sec-Executing-Operations">6.2</a></span>Executing Operations</h2> <p data-source="spec/Section%206%20--%20Execution.md#L114-L116">The type system, as described in the “Type System” section of the spec, must provide a query root operation type. If mutations or subscriptions are supported, it must also provide a mutation or subscription root operation type, respectively.</p> <section id="sec-Query" secid="6.2.1"> <h3 data-source="spec/Section%206%20--%20Execution.md#L118"><span class="spec-secid" title="link to this section"><a href="#sec-Query">6.2.1</a></span>Query</h3> <p data-source="spec/Section%206%20--%20Execution.md#L120-L122">If the operation is a query, the result of the operation is the result of executing the operation’s top level selection set with the query root operation type.</p> <p data-source="spec/Section%206%20--%20Execution.md#L124">An initial value may be provided when executing a query operation.</p> <div class="spec-algo" id="ExecuteQuery()" data-source="spec/Section%206%20--%20Execution.md#L126-L136"> <span class="spec-call"><a href="#ExecuteQuery()" data-name="ExecuteQuery">ExecuteQuery</a>(<var data-name="query">query</var>, <var data-name="schema">schema</var>, <var data-name="variableValues">variableValues</var>, <var data-name="initialValue">initialValue</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L128">Let <var data-name="queryType">queryType</var> be the root Query type in <var data-name="schema">schema</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L129">Assert: <var data-name="queryType">queryType</var> is an Object type.</li> <li data-source="spec/Section%206%20--%20Execution.md#L130">Let <var data-name="selectionSet">selectionSet</var> be the top level Selection Set in <var data-name="query">query</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L131-L133">Let <var data-name="data">data</var> be the result of running <span class="spec-call"><a href="#ExecuteSelectionSet()" data-name="ExecuteSelectionSet">ExecuteSelectionSet</a>(<var data-name="selectionSet">selectionSet</var>, <var data-name="queryType">queryType</var>, <var data-name="initialValue">initialValue</var>, <var data-name="variableValues">variableValues</var>)</span> <em>normally</em> (allowing parallelization).</li> <li data-source="spec/Section%206%20--%20Execution.md#L134-L135">Let <var data-name="errors">errors</var> be any <em>field errors</em> produced while executing the selection set.</li> <li data-source="spec/Section%206%20--%20Execution.md#L136">Return an unordered map containing <var data-name="data">data</var> and <var data-name="errors">errors</var>.</li> </ol> </div> </section> <section id="sec-Mutation" secid="6.2.2"> <h3 data-source="spec/Section%206%20--%20Execution.md#L138"><span class="spec-secid" title="link to this section"><a href="#sec-Mutation">6.2.2</a></span>Mutation</h3> <p data-source="spec/Section%206%20--%20Execution.md#L140-L142">If the operation is a mutation, the result of the operation is the result of executing the operation’s top level selection set on the mutation root object type. This selection set should be executed serially.</p> <p data-source="spec/Section%206%20--%20Execution.md#L144-L146">It is expected that the top level fields in a mutation operation perform side-effects on the underlying data system. Serial execution of the provided mutations ensures against race conditions during these side-effects.</p> <div class="spec-algo" id="ExecuteMutation()" data-source="spec/Section%206%20--%20Execution.md#L148-L158"> <span class="spec-call"><a href="#ExecuteMutation()" data-name="ExecuteMutation">ExecuteMutation</a>(<var data-name="mutation">mutation</var>, <var data-name="schema">schema</var>, <var data-name="variableValues">variableValues</var>, <var data-name="initialValue">initialValue</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L150">Let <var data-name="mutationType">mutationType</var> be the root Mutation type in <var data-name="schema">schema</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L151">Assert: <var data-name="mutationType">mutationType</var> is an Object type.</li> <li data-source="spec/Section%206%20--%20Execution.md#L152">Let <var data-name="selectionSet">selectionSet</var> be the top level Selection Set in <var data-name="mutation">mutation</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L153-L155">Let <var data-name="data">data</var> be the result of running <span class="spec-call"><a href="#ExecuteSelectionSet()" data-name="ExecuteSelectionSet">ExecuteSelectionSet</a>(<var data-name="selectionSet">selectionSet</var>, <var data-name="mutationType">mutationType</var>, <var data-name="initialValue">initialValue</var>, <var data-name="variableValues">variableValues</var>)</span> <em>serially</em>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L156-L157">Let <var data-name="errors">errors</var> be any <em>field errors</em> produced while executing the selection set.</li> <li data-source="spec/Section%206%20--%20Execution.md#L158">Return an unordered map containing <var data-name="data">data</var> and <var data-name="errors">errors</var>.</li> </ol> </div> </section> <section id="sec-Subscription" secid="6.2.3"> <h3 data-source="spec/Section%206%20--%20Execution.md#L160"><span class="spec-secid" title="link to this section"><a href="#sec-Subscription">6.2.3</a></span>Subscription</h3> <p data-source="spec/Section%206%20--%20Execution.md#L162-L164">If the operation is a subscription, the result is an event stream called the “Response Stream” where each event in the event stream is the result of executing the operation for each new event on an underlying “Source Stream”.</p> <p data-source="spec/Section%206%20--%20Execution.md#L166-L167">Executing a subscription operation creates a persistent function on the service that maps an underlying Source Stream to a returned Response Stream.</p> <div class="spec-algo" id="Subscribe()" data-source="spec/Section%206%20--%20Execution.md#L169-L173"> <span class="spec-call"><a href="#Subscribe()" data-name="Subscribe">Subscribe</a>(<var data-name="subscription">subscription</var>, <var data-name="schema">schema</var>, <var data-name="variableValues">variableValues</var>, <var data-name="initialValue">initialValue</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L171">Let <var data-name="sourceStream">sourceStream</var> be the result of running <span class="spec-call"><a href="#CreateSourceEventStream()" data-name="CreateSourceEventStream">CreateSourceEventStream</a>(<var data-name="subscription">subscription</var>, <var data-name="schema">schema</var>, <var data-name="variableValues">variableValues</var>, <var data-name="initialValue">initialValue</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L172">Let <var data-name="responseStream">responseStream</var> be the result of running <span class="spec-call"><a href="#MapSourceToResponseEvent()" data-name="MapSourceToResponseEvent">MapSourceToResponseEvent</a>(<var data-name="sourceStream">sourceStream</var>, <var data-name="subscription">subscription</var>, <var data-name="schema">schema</var>, <var data-name="variableValues">variableValues</var>)</span></li> <li data-source="spec/Section%206%20--%20Execution.md#L173">Return <var data-name="responseStream">responseStream</var>.</li> </ol> </div> <div id="note-79d56" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L175-L178"> <a href="#note-79d56">Note</a> In large scale subscription systems, the <span class="spec-call"><a href="#Subscribe()" data-name="Subscribe">Subscribe</a>()</span> and <span class="spec-call"><a href="#ExecuteSubscriptionEvent()" data-name="ExecuteSubscriptionEvent">ExecuteSubscriptionEvent</a>()</span> algorithms may be run on separate services to maintain predictable scaling properties. See the section below on Supporting Subscriptions at Scale.</div> <p data-source="spec/Section%206%20--%20Execution.md#L180-L181">As an example, consider a chat application. To subscribe to new messages posted to the chat room, the client sends a request like so:</p> <pre id="example-2a5f0" class="spec-example" data-language="graphql" data-source="spec/Section%206%20--%20Execution.md#L183-L190"><a href="#example-2a5f0">Example № 188</a><code><span class="token keyword">subscription</span> <span class="token object">NewMessages</span> <span class="token punctuation">{</span> <span class="token property-query">newMessage</span><span class="token punctuation">(</span><span class="token attr-name">roomId</span><span class="token punctuation">:</span> <span class="token number">123</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">sender</span> <span class="token property">text</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%206%20--%20Execution.md#L192-L194">While the client is subscribed, whenever new messages are posted to chat room with ID “123”, the selection for “sender” and “text” will be evaluated and published to the client, for example:</p> <pre id="example-a4629" class="spec-example" data-language="json" data-source="spec/Section%206%20--%20Execution.md#L196-L205"><a href="#example-a4629">Example № 189</a><code><span class="token punctuation">{</span> <span class="token property">"data"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"newMessage"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"sender"</span><span class="token operator">:</span> <span class="token string">"Hagrid"</span><span class="token punctuation">,</span> <span class="token property">"text"</span><span class="token operator">:</span> <span class="token string">"You're a wizard!"</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%206%20--%20Execution.md#L207-L208">The “new message posted to chat room” could use a “Pub-Sub” system where the chat room ID is the “topic” and each “publish” contains the sender and text.</p> <section id="sec-Subscription.Event-Streams" class="subsec"> <h6 data-source="spec/Section%206%20--%20Execution.md#L210"><a href="#sec-Subscription.Event-Streams" title="link to this subsection">Event Streams</a></h6> <p data-source="spec/Section%206%20--%20Execution.md#L212-L219">An event stream represents a sequence of discrete events over time which can be observed. As an example, a “Pub-Sub” system may produce an event stream when “subscribing to a topic”, with an event occurring on that event stream for each “publish” to that topic. Event streams may produce an infinite sequence of events or may complete at any point. Event streams may complete in response to an error or simply because no more events will occur. An observer may at any point decide to stop observing an event stream by cancelling it, after which it must receive no more events from that event stream.</p> </section> <section id="sec-Subscription.Supporting-Subscriptions-at-Scale" class="subsec"> <h6 data-source="spec/Section%206%20--%20Execution.md#L221"><a href="#sec-Subscription.Supporting-Subscriptions-at-Scale" title="link to this subsection">Supporting Subscriptions at Scale</a></h6> <p data-source="spec/Section%206%20--%20Execution.md#L223-L227">Supporting subscriptions is a significant change for any GraphQL service. Query and mutation operations are stateless, allowing scaling via cloning of GraphQL service instances. Subscriptions, by contrast, are stateful and require maintaining the GraphQL document, variables, and other context over the lifetime of the subscription.</p> <p data-source="spec/Section%206%20--%20Execution.md#L229-L232">Consider the behavior of your system when state is lost due to the failure of a single machine in a service. Durability and availability may be improved by having separate dedicated services for managing subscription state and client connectivity.</p> </section> <section id="sec-Subscription.Delivery-Agnostic" class="subsec"> <h6 data-source="spec/Section%206%20--%20Execution.md#L234"><a href="#sec-Subscription.Delivery-Agnostic" title="link to this subsection">Delivery Agnostic</a></h6> <p data-source="spec/Section%206%20--%20Execution.md#L236-L242">GraphQL subscriptions do not require any specific serialization format or transport mechanism. Subscriptions specifies algorithms for the creation of a stream, the content of each payload on that stream, and the closing of that stream. There are intentionally no specifications for message acknowledgement, buffering, resend requests, or any other quality of service (QoS) details. Message serialization, transport mechanisms, and quality of service details should be chosen by the implementing service.</p> </section> <section id="sec-Source-Stream" secid="6.2.3.1"> <h4 data-source="spec/Section%206%20--%20Execution.md#L244"><span class="spec-secid" title="link to this section"><a href="#sec-Source-Stream">6.2.3.1</a></span>Source Stream</h4> <p data-source="spec/Section%206%20--%20Execution.md#L246-L248">A Source Stream represents the sequence of events, each of which will trigger a GraphQL execution corresponding to that event. Like field value resolution, the logic to create a Source Stream is application-specific.</p> <div class="spec-algo" id="CreateSourceEventStream()" data-source="spec/Section%206%20--%20Execution.md#L250-L264"> <span class="spec-call"><a href="#CreateSourceEventStream()" data-name="CreateSourceEventStream">CreateSourceEventStream</a>(<var data-name="subscription">subscription</var>, <var data-name="schema">schema</var>, <var data-name="variableValues">variableValues</var>, <var data-name="initialValue">initialValue</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L252">Let <var data-name="subscriptionType">subscriptionType</var> be the root Subscription type in <var data-name="schema">schema</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L253">Assert: <var data-name="subscriptionType">subscriptionType</var> is an Object type.</li> <li data-source="spec/Section%206%20--%20Execution.md#L254">Let <var data-name="selectionSet">selectionSet</var> be the top level Selection Set in <var data-name="subscription">subscription</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L255-L256">Let <var data-name="groupedFieldSet">groupedFieldSet</var> be the result of <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>(<var data-name="subscriptionType">subscriptionType</var>, <var data-name="selectionSet">selectionSet</var>, <var data-name="variableValues">variableValues</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L257">If <var data-name="groupedFieldSet">groupedFieldSet</var> does not have exactly one entry, raise a request error.</li> <li data-source="spec/Section%206%20--%20Execution.md#L258">Let <var data-name="fields">fields</var> be the value of the first entry in <var data-name="groupedFieldSet">groupedFieldSet</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L259-L260">Let <var data-name="fieldName">fieldName</var> be the name of the first entry in <var data-name="fields">fields</var>. Note: This value is unaffected if an alias is used.</li> <li data-source="spec/Section%206%20--%20Execution.md#L261">Let <var data-name="field">field</var> be the first entry in <var data-name="fields">fields</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L262">Let <var data-name="argumentValues">argumentValues</var> be the result of <span class="spec-call"><a href="#CoerceArgumentValues()" data-name="CoerceArgumentValues">CoerceArgumentValues</a>(<var data-name="subscriptionType">subscriptionType</var>, <var data-name="field">field</var>, <var data-name="variableValues">variableValues</var>)</span></li> <li data-source="spec/Section%206%20--%20Execution.md#L263">Let <var data-name="fieldStream">fieldStream</var> be the result of running <span class="spec-call"><a href="#ResolveFieldEventStream()" data-name="ResolveFieldEventStream">ResolveFieldEventStream</a>(<var data-name="subscriptionType">subscriptionType</var>, <var data-name="initialValue">initialValue</var>, <var data-name="fieldName">fieldName</var>, <var data-name="argumentValues">argumentValues</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L264">Return <var data-name="fieldStream">fieldStream</var>.</li> </ol> </div> <div class="spec-algo" id="ResolveFieldEventStream()" data-source="spec/Section%206%20--%20Execution.md#L266-L269"> <span class="spec-call"><a href="#ResolveFieldEventStream()" data-name="ResolveFieldEventStream">ResolveFieldEventStream</a>(<var data-name="subscriptionType">subscriptionType</var>, <var data-name="rootValue">rootValue</var>, <var data-name="fieldName">fieldName</var>, <var data-name="argumentValues">argumentValues</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L267-L268">Let <var data-name="resolver">resolver</var> be the internal function provided by <var data-name="subscriptionType">subscriptionType</var> for determining the resolved event stream of a subscription field named <var data-name="fieldName">fieldName</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L269">Return the result of calling <var data-name="resolver">resolver</var>, providing <var data-name="rootValue">rootValue</var> and <var data-name="argumentValues">argumentValues</var>.</li> </ol> </div> <div id="note-5869a" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L271-L273"> <a href="#note-5869a">Note</a> This <span class="spec-call"><a href="#ResolveFieldEventStream()" data-name="ResolveFieldEventStream">ResolveFieldEventStream</a>()</span> algorithm is intentionally similar to <span class="spec-call"><a href="#ResolveFieldValue()" data-name="ResolveFieldValue">ResolveFieldValue</a>()</span> to enable consistency when defining resolvers on any operation type.</div> </section> <section id="sec-Response-Stream" secid="6.2.3.2"> <h4 data-source="spec/Section%206%20--%20Execution.md#L275"><span class="spec-secid" title="link to this section"><a href="#sec-Response-Stream">6.2.3.2</a></span>Response Stream</h4> <p data-source="spec/Section%206%20--%20Execution.md#L277-L278">Each event in the underlying Source Stream triggers execution of the subscription selection set using that event as a root value.</p> <div class="spec-algo" id="MapSourceToResponseEvent()" data-source="spec/Section%206%20--%20Execution.md#L280-L287"> <span class="spec-call"><a href="#MapSourceToResponseEvent()" data-name="MapSourceToResponseEvent">MapSourceToResponseEvent</a>(<var data-name="sourceStream">sourceStream</var>, <var data-name="subscription">subscription</var>, <var data-name="schema">schema</var>, <var data-name="variableValues">variableValues</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L282">Return a new event stream <var data-name="responseStream">responseStream</var> which yields events as follows:</li> <li data-source="spec/Section%206%20--%20Execution.md#L283-L286">For each <var data-name="event">event</var> on <var data-name="sourceStream">sourceStream</var>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L284-L285">Let <var data-name="response">response</var> be the result of running <span class="spec-call"><a href="#ExecuteSubscriptionEvent()" data-name="ExecuteSubscriptionEvent">ExecuteSubscriptionEvent</a>(<var data-name="subscription">subscription</var>, <var data-name="schema">schema</var>, <var data-name="variableValues">variableValues</var>, <var data-name="event">event</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L286">Yield an event containing <var data-name="response">response</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L287">When <var data-name="responseStream">responseStream</var> completes: complete this event stream.</li> </ol> </div> <div class="spec-algo" id="ExecuteSubscriptionEvent()" data-source="spec/Section%206%20--%20Execution.md#L289-L299"> <span class="spec-call"><a href="#ExecuteSubscriptionEvent()" data-name="ExecuteSubscriptionEvent">ExecuteSubscriptionEvent</a>(<var data-name="subscription">subscription</var>, <var data-name="schema">schema</var>, <var data-name="variableValues">variableValues</var>, <var data-name="initialValue">initialValue</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L291">Let <var data-name="subscriptionType">subscriptionType</var> be the root Subscription type in <var data-name="schema">schema</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L292">Assert: <var data-name="subscriptionType">subscriptionType</var> is an Object type.</li> <li data-source="spec/Section%206%20--%20Execution.md#L293">Let <var data-name="selectionSet">selectionSet</var> be the top level Selection Set in <var data-name="subscription">subscription</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L294-L296">Let <var data-name="data">data</var> be the result of running <span class="spec-call"><a href="#ExecuteSelectionSet()" data-name="ExecuteSelectionSet">ExecuteSelectionSet</a>(<var data-name="selectionSet">selectionSet</var>, <var data-name="subscriptionType">subscriptionType</var>, <var data-name="initialValue">initialValue</var>, <var data-name="variableValues">variableValues</var>)</span> <em>normally</em> (allowing parallelization).</li> <li data-source="spec/Section%206%20--%20Execution.md#L297-L298">Let <var data-name="errors">errors</var> be any <em>field errors</em> produced while executing the selection set.</li> <li data-source="spec/Section%206%20--%20Execution.md#L299">Return an unordered map containing <var data-name="data">data</var> and <var data-name="errors">errors</var>.</li> </ol> </div> <div id="note-5fb9c" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L301-L302"> <a href="#note-5fb9c">Note</a> The <span class="spec-call"><a href="#ExecuteSubscriptionEvent()" data-name="ExecuteSubscriptionEvent">ExecuteSubscriptionEvent</a>()</span> algorithm is intentionally similar to <span class="spec-call"><a href="#ExecuteQuery()" data-name="ExecuteQuery">ExecuteQuery</a>()</span> since this is how each event result is produced.</div> </section> <section id="sec-Unsubscribe" secid="6.2.3.3"> <h4 data-source="spec/Section%206%20--%20Execution.md#L304"><span class="spec-secid" title="link to this section"><a href="#sec-Unsubscribe">6.2.3.3</a></span>Unsubscribe</h4> <p data-source="spec/Section%206%20--%20Execution.md#L306-L309">Unsubscribe cancels the Response Stream when a client no longer wishes to receive payloads for a subscription. This may in turn also cancel the Source Stream. This is also a good opportunity to clean up any other resources used by the subscription.</p> <div class="spec-algo" id="Unsubscribe()" data-source="spec/Section%206%20--%20Execution.md#L311-L313"> <span class="spec-call"><a href="#Unsubscribe()" data-name="Unsubscribe">Unsubscribe</a>(<var data-name="responseStream">responseStream</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L313">Cancel <var data-name="responseStream">responseStream</var></li> </ol> </div> </section> </section> </section> <section id="sec-Executing-Selection-Sets" secid="6.3"> <h2 data-source="spec/Section%206%20--%20Execution.md#L315"><span class="spec-secid" title="link to this section"><a href="#sec-Executing-Selection-Sets">6.3</a></span>Executing Selection Sets</h2> <p data-source="spec/Section%206%20--%20Execution.md#L317-L319">To execute a selection set, the object value being evaluated and the object type need to be known, as well as whether it must be executed serially, or may be executed in parallel.</p> <p data-source="spec/Section%206%20--%20Execution.md#L321-L323">First, the selection set is turned into a grouped field set; then, each represented field in the grouped field set produces an entry into a response map.</p> <div class="spec-algo" id="ExecuteSelectionSet()" data-source="spec/Section%206%20--%20Execution.md#L325-L337"> <span class="spec-call"><a href="#ExecuteSelectionSet()" data-name="ExecuteSelectionSet">ExecuteSelectionSet</a>(<var data-name="selectionSet">selectionSet</var>, <var data-name="objectType">objectType</var>, <var data-name="objectValue">objectValue</var>, <var data-name="variableValues">variableValues</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L327-L328">Let <var data-name="groupedFieldSet">groupedFieldSet</var> be the result of <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>(<var data-name="objectType">objectType</var>, <var data-name="selectionSet">selectionSet</var>, <var data-name="variableValues">variableValues</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L329">Initialize <var data-name="resultMap">resultMap</var> to an empty ordered map.</li> <li data-source="spec/Section%206%20--%20Execution.md#L330-L336">For each <var data-name="groupedFieldSet">groupedFieldSet</var> as <var data-name="responseKey">responseKey</var> and <var data-name="fields">fields</var>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L331-L332">Let <var data-name="fieldName">fieldName</var> be the name of the first entry in <var data-name="fields">fields</var>. Note: This value is unaffected if an alias is used.</li> <li data-source="spec/Section%206%20--%20Execution.md#L333">Let <var data-name="fieldType">fieldType</var> be the return type defined for the field <var data-name="fieldName">fieldName</var> of <var data-name="objectType">objectType</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L334-L336">If <var data-name="fieldType">fieldType</var> is defined:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L335">Let <var data-name="responseValue">responseValue</var> be <span class="spec-call"><a href="#ExecuteField()" data-name="ExecuteField">ExecuteField</a>(<var data-name="objectType">objectType</var>, <var data-name="objectValue">objectValue</var>, <var data-name="fieldType">fieldType</var>, <var data-name="fields">fields</var>, <var data-name="variableValues">variableValues</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L336">Set <var data-name="responseValue">responseValue</var> as the value for <var data-name="responseKey">responseKey</var> in <var data-name="resultMap">resultMap</var>.</li> </ol> </li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L337">Return <var data-name="resultMap">resultMap</var>.</li> </ol> </div> <div id="note-b8f81" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L339-L340"> <a href="#note-b8f81">Note</a> <var data-name="resultMap">resultMap</var> is ordered by which fields appear first in the operation. This is explained in greater detail in the Field Collection section below.</div> <section id="sec-Executing-Selection-Sets.Errors-and-Non-Null-Fields" class="subsec"> <h6 data-source="spec/Section%206%20--%20Execution.md#L342"><a href="#sec-Executing-Selection-Sets.Errors-and-Non-Null-Fields" title="link to this subsection">Errors and Non-Null Fields</a></h6> <p data-source="spec/Section%206%20--%20Execution.md#L344-L346">If during <span class="spec-call"><a href="#ExecuteSelectionSet()" data-name="ExecuteSelectionSet">ExecuteSelectionSet</a>()</span> a field with a non-null <var data-name="fieldType">fieldType</var> raises a field error then that error must propagate to this entire selection set, either resolving to <span class="spec-keyword">null</span> if allowed or further propagated to a parent field.</p> <p data-source="spec/Section%206%20--%20Execution.md#L348-L349">If this occurs, any sibling fields which have not yet executed or have not yet yielded a value may be cancelled to avoid unnecessary work.</p> <div id="note-4dd38" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L351-L352"> <a href="#note-4dd38">Note</a> See <a href="#sec-Handling-Field-Errors">Handling Field Errors</a> for more about this behavior.</div> </section> <section id="sec-Normal-and-Serial-Execution" secid="6.3.1"> <h3 data-source="spec/Section%206%20--%20Execution.md#L354"><span class="spec-secid" title="link to this section"><a href="#sec-Normal-and-Serial-Execution">6.3.1</a></span>Normal and Serial Execution</h3> <p data-source="spec/Section%206%20--%20Execution.md#L356-L360">Normally the executor can execute the entries in a grouped field set in whatever order it chooses (normally in parallel). Because the resolution of fields other than top-level mutation fields must always be side effect-free and idempotent, the execution order must not affect the result, and hence the service has the freedom to execute the field entries in whatever order it deems optimal.</p> <p data-source="spec/Section%206%20--%20Execution.md#L362">For example, given the following grouped field set to be executed normally:</p> <pre id="example-65e7d" class="spec-example" data-language="graphql" data-source="spec/Section%206%20--%20Execution.md#L364-L373"><a href="#example-65e7d">Example № 190</a><code><span class="token punctuation">{</span> <span class="token object">birthday</span> <span class="token punctuation">{</span> <span class="token property">month</span> <span class="token punctuation">}</span> <span class="token object">address</span> <span class="token punctuation">{</span> <span class="token property">street</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%206%20--%20Execution.md#L375-L377">A valid GraphQL executor can resolve the four fields in whatever order it chose (however of course <code>birthday</code> must be resolved before <code>month</code>, and <code>address</code> before <code>street</code>).</p> <p data-source="spec/Section%206%20--%20Execution.md#L379-L380">When executing a mutation, the selections in the top most selection set will be executed in serial order, starting with the first appearing field textually.</p> <p data-source="spec/Section%206%20--%20Execution.md#L382-L385">When executing a grouped field set serially, the executor must consider each entry from the grouped field set in the order provided in the grouped field set. It must determine the corresponding entry in the result map for each item to completion before it continues on to the next item in the grouped field set:</p> <p data-source="spec/Section%206%20--%20Execution.md#L387">For example, given the following selection set to be executed serially:</p> <pre id="example-33b6a" class="spec-example" data-language="graphql" data-source="spec/Section%206%20--%20Execution.md#L389-L398"><a href="#example-33b6a">Example № 191</a><code><span class="token punctuation">{</span> <span class="token property-query">changeBirthday</span><span class="token punctuation">(</span><span class="token attr-name">birthday</span><span class="token punctuation">:</span> <span class="token variable">$newBirthday</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">month</span> <span class="token punctuation">}</span> <span class="token property-query">changeAddress</span><span class="token punctuation">(</span><span class="token attr-name">address</span><span class="token punctuation">:</span> <span class="token variable">$newAddress</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">street</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%206%20--%20Execution.md#L400">The executor must, in serial:</p> <ul> <li data-source="spec/Section%206%20--%20Execution.md#L402-L403">Run <span class="spec-call"><a href="#ExecuteField()" data-name="ExecuteField">ExecuteField</a>()</span> for <code>changeBirthday</code>, which during <span class="spec-call"><a href="#CompleteValue()" data-name="CompleteValue">CompleteValue</a>()</span> will execute the <code>{ month }</code> sub-selection set normally.</li> <li data-source="spec/Section%206%20--%20Execution.md#L404-L405">Run <span class="spec-call"><a href="#ExecuteField()" data-name="ExecuteField">ExecuteField</a>()</span> for <code>changeAddress</code>, which during <span class="spec-call"><a href="#CompleteValue()" data-name="CompleteValue">CompleteValue</a>()</span> will execute the <code>{ street }</code> sub-selection set normally.</li> </ul> <p data-source="spec/Section%206%20--%20Execution.md#L407-L409">As an illustrative example, let’s assume we have a mutation field <code>changeTheNumber</code> that returns an object containing one field, <code>theNumber</code>. If we execute the following selection set serially:</p> <pre id="example-c91a3" class="spec-example" data-language="graphql" data-source="spec/Section%206%20--%20Execution.md#L411-L423"><a href="#example-c91a3">Example № 192</a><code><span class="token punctuation">{</span> <span class="token attr-name">first</span><span class="token punctuation">:</span> <span class="token property-query">changeTheNumber</span><span class="token punctuation">(</span><span class="token attr-name">newNumber</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">theNumber</span> <span class="token punctuation">}</span> <span class="token attr-name">second</span><span class="token punctuation">:</span> <span class="token property-query">changeTheNumber</span><span class="token punctuation">(</span><span class="token attr-name">newNumber</span><span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">theNumber</span> <span class="token punctuation">}</span> <span class="token attr-name">third</span><span class="token punctuation">:</span> <span class="token property-query">changeTheNumber</span><span class="token punctuation">(</span><span class="token attr-name">newNumber</span><span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">theNumber</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%206%20--%20Execution.md#L425">The executor will execute the following serially:</p> <ul> <li data-source="spec/Section%206%20--%20Execution.md#L427">Resolve the <code>changeTheNumber(newNumber: 1)</code> field</li> <li data-source="spec/Section%206%20--%20Execution.md#L428">Execute the <code>{ theNumber }</code> sub-selection set of <code>first</code> normally</li> <li data-source="spec/Section%206%20--%20Execution.md#L429">Resolve the <code>changeTheNumber(newNumber: 3)</code> field</li> <li data-source="spec/Section%206%20--%20Execution.md#L430">Execute the <code>{ theNumber }</code> sub-selection set of <code>second</code> normally</li> <li data-source="spec/Section%206%20--%20Execution.md#L431">Resolve the <code>changeTheNumber(newNumber: 2)</code> field</li> <li data-source="spec/Section%206%20--%20Execution.md#L432">Execute the <code>{ theNumber }</code> sub-selection set of <code>third</code> normally</li> </ul> <p data-source="spec/Section%206%20--%20Execution.md#L434">A correct executor must generate the following result for that selection set:</p> <pre id="example-1d82c" class="spec-example" data-language="json" data-source="spec/Section%206%20--%20Execution.md#L436-L448"><a href="#example-1d82c">Example № 193</a><code><span class="token punctuation">{</span> <span class="token property">"first"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"theNumber"</span><span class="token operator">:</span> <span class="token number">1</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"second"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"theNumber"</span><span class="token operator">:</span> <span class="token number">3</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"third"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"theNumber"</span><span class="token operator">:</span> <span class="token number">2</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> </section> <section id="sec-Field-Collection" secid="6.3.2"> <h3 data-source="spec/Section%206%20--%20Execution.md#L451"><span class="spec-secid" title="link to this section"><a href="#sec-Field-Collection">6.3.2</a></span>Field Collection</h3> <p data-source="spec/Section%206%20--%20Execution.md#L453-L457">Before execution, the selection set is converted to a grouped field set by calling <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>()</span>. Each entry in the grouped field set is a list of fields that share a response key (the alias if defined, otherwise the field name). This ensures all fields with the same response key (including those in referenced fragments) are executed at the same time.</p> <p data-source="spec/Section%206%20--%20Execution.md#L459-L460">As an example, collecting the fields of this selection set would collect two instances of the field <code>a</code> and one of field <code>b</code>:</p> <pre id="example-fdbb7" class="spec-example" data-language="graphql" data-source="spec/Section%206%20--%20Execution.md#L462-L476"><a href="#example-fdbb7">Example № 194</a><code><span class="token punctuation">{</span> <span class="token object">a</span> <span class="token punctuation">{</span> <span class="token property">subfield1</span> <span class="token punctuation">}</span> <span class="token operator">...</span><span class="token fragment function">ExampleFragment</span> <span class="token punctuation">}</span> <span class="token keyword">fragment</span> <span class="token fragment function">ExampleFragment</span> <span class="token keyword">on</span> <span class="token class-name">Query</span> <span class="token punctuation">{</span> <span class="token object">a</span> <span class="token punctuation">{</span> <span class="token property">subfield2</span> <span class="token punctuation">}</span> <span class="token property">b</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%206%20--%20Execution.md#L478-L480">The depth-first-search order of the field groups produced by <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>()</span> is maintained through execution, ensuring that fields appear in the executed response in a stable and predictable order.</p> <div class="spec-algo" id="CollectFields()" data-source="spec/Section%206%20--%20Execution.md#L482-L529"> <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>(<var data-name="objectType">objectType</var>, <var data-name="selectionSet">selectionSet</var>, <var data-name="variableValues">variableValues</var>, <var data-name="visitedFragments">visitedFragments</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L484">If <var data-name="visitedFragments">visitedFragments</var> is not provided, initialize it to the empty set.</li> <li data-source="spec/Section%206%20--%20Execution.md#L485">Initialize <var data-name="groupedFields">groupedFields</var> to an empty ordered map of lists.</li> <li data-source="spec/Section%206%20--%20Execution.md#L486-L528">For each <var data-name="selection">selection</var> in <var data-name="selectionSet">selectionSet</var>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L487-L489">If <var data-name="selection">selection</var> provides the directive <code>@skip</code>, let <var data-name="skipDirective">skipDirective</var> be that directive.<ol> <li data-source="spec/Section%206%20--%20Execution.md#L488-L489">If <var data-name="skipDirective">skipDirective</var>‘s <var data-name="if">if</var> argument is <span class="spec-keyword">true</span> or is a variable in <var data-name="variableValues">variableValues</var> with the value <span class="spec-keyword">true</span>, continue with the next <var data-name="selection">selection</var> in <var data-name="selectionSet">selectionSet</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L490-L492">If <var data-name="selection">selection</var> provides the directive <code>@include</code>, let <var data-name="includeDirective">includeDirective</var> be that directive.<ol> <li data-source="spec/Section%206%20--%20Execution.md#L491-L492">If <var data-name="includeDirective">includeDirective</var>‘s <var data-name="if">if</var> argument is not <span class="spec-keyword">true</span> and is not a variable in <var data-name="variableValues">variableValues</var> with the value <span class="spec-keyword">true</span>, continue with the next <var data-name="selection">selection</var> in <var data-name="selectionSet">selectionSet</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L493-L497">If <var data-name="selection">selection</var> is a <span class="spec-nt"><a href="#Field" data-name="Field">Field</a></span>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L494">Let <var data-name="responseKey">responseKey</var> be the response key of <var data-name="selection">selection</var> (the alias if defined, otherwise the field name).</li> <li data-source="spec/Section%206%20--%20Execution.md#L495-L496">Let <var data-name="groupForResponseKey">groupForResponseKey</var> be the list in <var data-name="groupedFields">groupedFields</var> for <var data-name="responseKey">responseKey</var>; if no such list exists, create it as an empty list.</li> <li data-source="spec/Section%206%20--%20Execution.md#L497">Append <var data-name="selection">selection</var> to the <var data-name="groupForResponseKey">groupForResponseKey</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L498-L517">If <var data-name="selection">selection</var> is a <span class="spec-nt"><a href="#FragmentSpread" data-name="FragmentSpread">FragmentSpread</a></span>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L499">Let <var data-name="fragmentSpreadName">fragmentSpreadName</var> be the name of <var data-name="selection">selection</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L500-L501">If <var data-name="fragmentSpreadName">fragmentSpreadName</var> is in <var data-name="visitedFragments">visitedFragments</var>, continue with the next <var data-name="selection">selection</var> in <var data-name="selectionSet">selectionSet</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L502">Add <var data-name="fragmentSpreadName">fragmentSpreadName</var> to <var data-name="visitedFragments">visitedFragments</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L503-L504">Let <var data-name="fragment">fragment</var> be the Fragment in the current Document whose name is <var data-name="fragmentSpreadName">fragmentSpreadName</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L505-L506">If no such <var data-name="fragment">fragment</var> exists, continue with the next <var data-name="selection">selection</var> in <var data-name="selectionSet">selectionSet</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L507">Let <var data-name="fragmentType">fragmentType</var> be the type condition on <var data-name="fragment">fragment</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L508-L509">If <span class="spec-call"><a href="#DoesFragmentTypeApply()" data-name="DoesFragmentTypeApply">DoesFragmentTypeApply</a>(<var data-name="objectType">objectType</var>, <var data-name="fragmentType">fragmentType</var>)</span> is false, continue with the next <var data-name="selection">selection</var> in <var data-name="selectionSet">selectionSet</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L510">Let <var data-name="fragmentSelectionSet">fragmentSelectionSet</var> be the top-level selection set of <var data-name="fragment">fragment</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L511-L512">Let <var data-name="fragmentGroupedFieldSet">fragmentGroupedFieldSet</var> be the result of calling <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>(<var data-name="objectType">objectType</var>, <var data-name="fragmentSelectionSet">fragmentSelectionSet</var>, <var data-name="variableValues">variableValues</var>, <var data-name="visitedFragments">visitedFragments</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L513-L517">For each <var data-name="fragmentGroup">fragmentGroup</var> in <var data-name="fragmentGroupedFieldSet">fragmentGroupedFieldSet</var>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L514">Let <var data-name="responseKey">responseKey</var> be the response key shared by all fields in <var data-name="fragmentGroup">fragmentGroup</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L515-L516">Let <var data-name="groupForResponseKey">groupForResponseKey</var> be the list in <var data-name="groupedFields">groupedFields</var> for <var data-name="responseKey">responseKey</var>; if no such list exists, create it as an empty list.</li> <li data-source="spec/Section%206%20--%20Execution.md#L517">Append all items in <var data-name="fragmentGroup">fragmentGroup</var> to <var data-name="groupForResponseKey">groupForResponseKey</var>.</li> </ol> </li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L518-L528">If <var data-name="selection">selection</var> is an <span class="spec-nt"><a href="#InlineFragment" data-name="InlineFragment">InlineFragment</a></span>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L519">Let <var data-name="fragmentType">fragmentType</var> be the type condition on <var data-name="selection">selection</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L520-L521">If <var data-name="fragmentType">fragmentType</var> is not <span class="spec-keyword">null</span> and <span class="spec-call"><a href="#DoesFragmentTypeApply()" data-name="DoesFragmentTypeApply">DoesFragmentTypeApply</a>(<var data-name="objectType">objectType</var>, <var data-name="fragmentType">fragmentType</var>)</span> is false, continue with the next <var data-name="selection">selection</var> in <var data-name="selectionSet">selectionSet</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L522">Let <var data-name="fragmentSelectionSet">fragmentSelectionSet</var> be the top-level selection set of <var data-name="selection">selection</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L523">Let <var data-name="fragmentGroupedFieldSet">fragmentGroupedFieldSet</var> be the result of calling <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>(<var data-name="objectType">objectType</var>, <var data-name="fragmentSelectionSet">fragmentSelectionSet</var>, <var data-name="variableValues">variableValues</var>, <var data-name="visitedFragments">visitedFragments</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L524-L528">For each <var data-name="fragmentGroup">fragmentGroup</var> in <var data-name="fragmentGroupedFieldSet">fragmentGroupedFieldSet</var>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L525">Let <var data-name="responseKey">responseKey</var> be the response key shared by all fields in <var data-name="fragmentGroup">fragmentGroup</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L526-L527">Let <var data-name="groupForResponseKey">groupForResponseKey</var> be the list in <var data-name="groupedFields">groupedFields</var> for <var data-name="responseKey">responseKey</var>; if no such list exists, create it as an empty list.</li> <li data-source="spec/Section%206%20--%20Execution.md#L528">Append all items in <var data-name="fragmentGroup">fragmentGroup</var> to <var data-name="groupForResponseKey">groupForResponseKey</var>.</li> </ol> </li> </ol> </li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L529">Return <var data-name="groupedFields">groupedFields</var>.</li> </ol> </div> <div class="spec-algo" id="DoesFragmentTypeApply()" data-source="spec/Section%206%20--%20Execution.md#L531-L538"> <span class="spec-call"><a href="#DoesFragmentTypeApply()" data-name="DoesFragmentTypeApply">DoesFragmentTypeApply</a>(<var data-name="objectType">objectType</var>, <var data-name="fragmentType">fragmentType</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L533-L534">If <var data-name="fragmentType">fragmentType</var> is an Object Type:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L534">if <var data-name="objectType">objectType</var> and <var data-name="fragmentType">fragmentType</var> are the same type, return <span class="spec-keyword">true</span>, otherwise return <span class="spec-keyword">false</span>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L535-L536">If <var data-name="fragmentType">fragmentType</var> is an Interface Type:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L536">if <var data-name="objectType">objectType</var> is an implementation of <var data-name="fragmentType">fragmentType</var>, return <span class="spec-keyword">true</span> otherwise return <span class="spec-keyword">false</span>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L537-L538">If <var data-name="fragmentType">fragmentType</var> is a Union:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L538">if <var data-name="objectType">objectType</var> is a possible type of <var data-name="fragmentType">fragmentType</var>, return <span class="spec-keyword">true</span> otherwise return <span class="spec-keyword">false</span>.</li> </ol> </li> </ol> </div> <div id="note-f1a76" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L540-L541"> <a href="#note-f1a76">Note</a> The steps in <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>()</span> evaluating the <code>@skip</code> and <code>@include</code> directives may be applied in either order since they apply commutatively.</div> </section> </section> <section id="sec-Executing-Fields" secid="6.4"> <h2 data-source="spec/Section%206%20--%20Execution.md#L544"><span class="spec-secid" title="link to this section"><a href="#sec-Executing-Fields">6.4</a></span>Executing Fields</h2> <p data-source="spec/Section%206%20--%20Execution.md#L546-L550">Each field requested in the grouped field set that is defined on the selected objectType will result in an entry in the response map. Field execution first coerces any provided argument values, then resolves a value for the field, and finally completes that value either by recursively executing another selection set or coercing a scalar value.</p> <div class="spec-algo" id="ExecuteField()" data-source="spec/Section%206%20--%20Execution.md#L552-L557"> <span class="spec-call"><a href="#ExecuteField()" data-name="ExecuteField">ExecuteField</a>(<var data-name="objectType">objectType</var>, <var data-name="objectValue">objectValue</var>, <var data-name="fieldType">fieldType</var>, <var data-name="fields">fields</var>, <var data-name="variableValues">variableValues</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L553">Let <var data-name="field">field</var> be the first entry in <var data-name="fields">fields</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L554">Let <var data-name="fieldName">fieldName</var> be the field name of <var data-name="field">field</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L555">Let <var data-name="argumentValues">argumentValues</var> be the result of <span class="spec-call"><a href="#CoerceArgumentValues()" data-name="CoerceArgumentValues">CoerceArgumentValues</a>(<var data-name="objectType">objectType</var>, <var data-name="field">field</var>, <var data-name="variableValues">variableValues</var>)</span></li> <li data-source="spec/Section%206%20--%20Execution.md#L556">Let <var data-name="resolvedValue">resolvedValue</var> be <span class="spec-call"><a href="#ResolveFieldValue()" data-name="ResolveFieldValue">ResolveFieldValue</a>(<var data-name="objectType">objectType</var>, <var data-name="objectValue">objectValue</var>, <var data-name="fieldName">fieldName</var>, <var data-name="argumentValues">argumentValues</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L557">Return the result of <span class="spec-call"><a href="#CompleteValue()" data-name="CompleteValue">CompleteValue</a>(<var data-name="fieldType">fieldType</var>, <var data-name="fields">fields</var>, <var data-name="resolvedValue">resolvedValue</var>, <var data-name="variableValues">variableValues</var>)</span>.</li> </ol> </div> <section id="sec-Coercing-Field-Arguments" secid="6.4.1"> <h3 data-source="spec/Section%206%20--%20Execution.md#L560"><span class="spec-secid" title="link to this section"><a href="#sec-Coercing-Field-Arguments">6.4.1</a></span>Coercing Field Arguments</h3> <p data-source="spec/Section%206%20--%20Execution.md#L562-L564">Fields may include arguments which are provided to the underlying runtime in order to correctly produce a value. These arguments are defined by the field in the type system to have a specific input type.</p> <p data-source="spec/Section%206%20--%20Execution.md#L566-L567">At each argument position in an operation may be a literal <span class="spec-nt"><a href="#Value" data-name="Value">Value</a></span>, or a <span class="spec-nt"><a href="#Variable" data-name="Variable">Variable</a></span> to be provided at runtime.</p> <div class="spec-algo" id="CoerceArgumentValues()" data-source="spec/Section%206%20--%20Execution.md#L569-L609"> <span class="spec-call"><a href="#CoerceArgumentValues()" data-name="CoerceArgumentValues">CoerceArgumentValues</a>(<var data-name="objectType">objectType</var>, <var data-name="field">field</var>, <var data-name="variableValues">variableValues</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L570">Let <var data-name="coercedValues">coercedValues</var> be an empty unordered Map.</li> <li data-source="spec/Section%206%20--%20Execution.md#L571">Let <var data-name="argumentValues">argumentValues</var> be the argument values provided in <var data-name="field">field</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L572">Let <var data-name="fieldName">fieldName</var> be the name of <var data-name="field">field</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L573-L574">Let <var data-name="argumentDefinitions">argumentDefinitions</var> be the arguments defined by <var data-name="objectType">objectType</var> for the field named <var data-name="fieldName">fieldName</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L575-L608">For each <var data-name="argumentDefinition">argumentDefinition</var> in <var data-name="argumentDefinitions">argumentDefinitions</var>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L576">Let <var data-name="argumentName">argumentName</var> be the name of <var data-name="argumentDefinition">argumentDefinition</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L577">Let <var data-name="argumentType">argumentType</var> be the expected type of <var data-name="argumentDefinition">argumentDefinition</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L578">Let <var data-name="defaultValue">defaultValue</var> be the default value for <var data-name="argumentDefinition">argumentDefinition</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L579-L580">Let <var data-name="hasValue">hasValue</var> be <span class="spec-keyword">true</span> if <var data-name="argumentValues">argumentValues</var> provides a value for the name <var data-name="argumentName">argumentName</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L581-L582">Let <var data-name="argumentValue">argumentValue</var> be the value provided in <var data-name="argumentValues">argumentValues</var> for the name <var data-name="argumentName">argumentName</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L583-L588">If <var data-name="argumentValue">argumentValue</var> is a <span class="spec-nt"><a href="#Variable" data-name="Variable">Variable</a></span>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L584">Let <var data-name="variableName">variableName</var> be the name of <var data-name="argumentValue">argumentValue</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L585-L586">Let <var data-name="hasValue">hasValue</var> be <span class="spec-keyword">true</span> if <var data-name="variableValues">variableValues</var> provides a value for the name <var data-name="variableName">variableName</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L587-L588">Let <var data-name="value">value</var> be the value provided in <var data-name="variableValues">variableValues</var> for the name <var data-name="variableName">variableName</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L589">Otherwise, let <var data-name="value">value</var> be <var data-name="argumentValue">argumentValue</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L590-L592">If <var data-name="hasValue">hasValue</var> is not <span class="spec-keyword">true</span> and <var data-name="defaultValue">defaultValue</var> exists (including <span class="spec-keyword">null</span>):<ol> <li data-source="spec/Section%206%20--%20Execution.md#L591-L592">Add an entry to <var data-name="coercedValues">coercedValues</var> named <var data-name="argumentName">argumentName</var> with the value <var data-name="defaultValue">defaultValue</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L593-L594">Otherwise if <var data-name="argumentType">argumentType</var> is a Non-Nullable type, and either <var data-name="hasValue">hasValue</var> is not <span class="spec-keyword">true</span> or <var data-name="value">value</var> is <span class="spec-keyword">null</span>, raise a field error.</li> <li data-source="spec/Section%206%20--%20Execution.md#L595-L608">Otherwise if <var data-name="hasValue">hasValue</var> is true:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L596-L598">If <var data-name="value">value</var> is <span class="spec-keyword">null</span>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L597-L598">Add an entry to <var data-name="coercedValues">coercedValues</var> named <var data-name="argumentName">argumentName</var> with the value <span class="spec-keyword">null</span>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L599-L601">Otherwise, if <var data-name="argumentValue">argumentValue</var> is a <span class="spec-nt"><a href="#Variable" data-name="Variable">Variable</a></span>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L600-L601">Add an entry to <var data-name="coercedValues">coercedValues</var> named <var data-name="argumentName">argumentName</var> with the value <var data-name="value">value</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L602-L608">Otherwise:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L603-L604">If <var data-name="value">value</var> cannot be coerced according to the input coercion rules of <var data-name="argumentType">argumentType</var>, raise a field error.</li> <li data-source="spec/Section%206%20--%20Execution.md#L605-L606">Let <var data-name="coercedValue">coercedValue</var> be the result of coercing <var data-name="value">value</var> according to the input coercion rules of <var data-name="argumentType">argumentType</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L607-L608">Add an entry to <var data-name="coercedValues">coercedValues</var> named <var data-name="argumentName">argumentName</var> with the value <var data-name="coercedValue">coercedValue</var>.</li> </ol> </li> </ol> </li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L609">Return <var data-name="coercedValues">coercedValues</var>.</li> </ol> </div> <div id="note-65769" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L611-L613"> <a href="#note-65769">Note</a> Variable values are not coerced because they are expected to be coerced before executing the operation in <span class="spec-call"><a href="#CoerceVariableValues()" data-name="CoerceVariableValues">CoerceVariableValues</a>()</span>, and valid operations must only allow usage of variables of appropriate types.</div> </section> <section id="sec-Value-Resolution" secid="6.4.2"> <h3 data-source="spec/Section%206%20--%20Execution.md#L616"><span class="spec-secid" title="link to this section"><a href="#sec-Value-Resolution">6.4.2</a></span>Value Resolution</h3> <p data-source="spec/Section%206%20--%20Execution.md#L618-L621">While nearly all of GraphQL execution can be described generically, ultimately the internal system exposing the GraphQL interface must provide values. This is exposed via <span class="spec-nt"><span data-name="ResolveFieldValue">ResolveFieldValue</span></span>, which produces a value for a given field on a type for a real value.</p> <p data-source="spec/Section%206%20--%20Execution.md#L623-L625">As an example, this might accept the <var data-name="objectType">objectType</var> <code>Person</code>, the <var data-name="field">field</var> <span class="spec-string">"soulMate"</span>, and the <var data-name="objectValue">objectValue</var> representing John Lennon. It would be expected to yield the value representing Yoko Ono.</p> <div class="spec-algo" id="ResolveFieldValue()" data-source="spec/Section%206%20--%20Execution.md#L627-L630"> <span class="spec-call"><a href="#ResolveFieldValue()" data-name="ResolveFieldValue">ResolveFieldValue</a>(<var data-name="objectType">objectType</var>, <var data-name="objectValue">objectValue</var>, <var data-name="fieldName">fieldName</var>, <var data-name="argumentValues">argumentValues</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L628-L629">Let <var data-name="resolver">resolver</var> be the internal function provided by <var data-name="objectType">objectType</var> for determining the resolved value of a field named <var data-name="fieldName">fieldName</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L630">Return the result of calling <var data-name="resolver">resolver</var>, providing <var data-name="objectValue">objectValue</var> and <var data-name="argumentValues">argumentValues</var>.</li> </ol> </div> <div id="note-7bf5f" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L632-L635"> <a href="#note-7bf5f">Note</a> It is common for <var data-name="resolver">resolver</var> to be asynchronous due to relying on reading an underlying database or networked service to produce a value. This necessitates the rest of a GraphQL executor to handle an asynchronous execution flow.</div> </section> <section id="sec-Value-Completion" secid="6.4.3"> <h3 data-source="spec/Section%206%20--%20Execution.md#L638"><span class="spec-secid" title="link to this section"><a href="#sec-Value-Completion">6.4.3</a></span>Value Completion</h3> <p data-source="spec/Section%206%20--%20Execution.md#L640-L642">After resolving the value for a field, it is completed by ensuring it adheres to the expected return type. If the return type is another Object type, then the field execution process continues recursively.</p> <div class="spec-algo" id="CompleteValue()" data-source="spec/Section%206%20--%20Execution.md#L644-L667"> <span class="spec-call"><a href="#CompleteValue()" data-name="CompleteValue">CompleteValue</a>(<var data-name="fieldType">fieldType</var>, <var data-name="fields">fields</var>, <var data-name="result">result</var>, <var data-name="variableValues">variableValues</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L645-L650">If the <var data-name="fieldType">fieldType</var> is a Non-Null type:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L646">Let <var data-name="innerType">innerType</var> be the inner type of <var data-name="fieldType">fieldType</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L647-L648">Let <var data-name="completedResult">completedResult</var> be the result of calling <span class="spec-call"><a href="#CompleteValue()" data-name="CompleteValue">CompleteValue</a>(<var data-name="innerType">innerType</var>, <var data-name="fields">fields</var>, <var data-name="result">result</var>, <var data-name="variableValues">variableValues</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L649">If <var data-name="completedResult">completedResult</var> is <span class="spec-keyword">null</span>, raise a field error.</li> <li data-source="spec/Section%206%20--%20Execution.md#L650">Return <var data-name="completedResult">completedResult</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L651-L652">If <var data-name="result">result</var> is <span class="spec-keyword">null</span> (or another internal value similar to <span class="spec-keyword">null</span> such as <span class="spec-keyword">undefined</span>), return <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L653-L658">If <var data-name="fieldType">fieldType</var> is a List type:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L654">If <var data-name="result">result</var> is not a collection of values, raise a field error.</li> <li data-source="spec/Section%206%20--%20Execution.md#L655">Let <var data-name="innerType">innerType</var> be the inner type of <var data-name="fieldType">fieldType</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L656-L658">Return a list where each list item is the result of calling <span class="spec-call"><a href="#CompleteValue()" data-name="CompleteValue">CompleteValue</a>(<var data-name="innerType">innerType</var>, <var data-name="fields">fields</var>, <var data-name="resultItem">resultItem</var>, <var data-name="variableValues">variableValues</var>)</span>, where <var data-name="resultItem">resultItem</var> is each item in <var data-name="result">result</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L659-L660">If <var data-name="fieldType">fieldType</var> is a Scalar or Enum type:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L660">Return the result of <span class="spec-call"><a href="#CoerceResult()" data-name="CoerceResult">CoerceResult</a>(<var data-name="fieldType">fieldType</var>, <var data-name="result">result</var>)</span>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L661-L667">If <var data-name="fieldType">fieldType</var> is an Object, Interface, or Union type:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L662-L663">If <var data-name="fieldType">fieldType</var> is an Object type.<ol> <li data-source="spec/Section%206%20--%20Execution.md#L663">Let <var data-name="objectType">objectType</var> be <var data-name="fieldType">fieldType</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L664-L665">Otherwise if <var data-name="fieldType">fieldType</var> is an Interface or Union type.<ol> <li data-source="spec/Section%206%20--%20Execution.md#L665">Let <var data-name="objectType">objectType</var> be <span class="spec-call"><a href="#ResolveAbstractType()" data-name="ResolveAbstractType">ResolveAbstractType</a>(<var data-name="fieldType">fieldType</var>, <var data-name="result">result</var>)</span>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L666">Let <var data-name="subSelectionSet">subSelectionSet</var> be the result of calling <span class="spec-call"><a href="#MergeSelectionSets()" data-name="MergeSelectionSets">MergeSelectionSets</a>(<var data-name="fields">fields</var>)</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L667">Return the result of evaluating <span class="spec-call"><a href="#ExecuteSelectionSet()" data-name="ExecuteSelectionSet">ExecuteSelectionSet</a>(<var data-name="subSelectionSet">subSelectionSet</var>, <var data-name="objectType">objectType</var>, <var data-name="result">result</var>, <var data-name="variableValues">variableValues</var>)</span> <em>normally</em> (allowing for parallelization).</li> </ol> </li> </ol> </div> <section id="sec-Value-Completion.Coercing-Results" class="subsec"> <h6 data-source="spec/Section%206%20--%20Execution.md#L669"><a href="#sec-Value-Completion.Coercing-Results" title="link to this subsection">Coercing Results</a></h6> <p data-source="spec/Section%206%20--%20Execution.md#L671-L674">The primary purpose of value completion is to ensure that the values returned by field resolvers are valid according to the GraphQL type system and a service’s schema. This “dynamic type checking” allows GraphQL to provide consistent guarantees about returned types atop any service’s internal runtime.</p> <p data-source="spec/Section%206%20--%20Execution.md#L676-L678">See the Scalars <a href="#sec-Scalars.Result-Coercion-and-Serialization">Result Coercion and Serialization</a> sub-section for more detailed information about how GraphQL’s built-in scalars coerce result values.</p> <div class="spec-algo" id="CoerceResult()" data-source="spec/Section%206%20--%20Execution.md#L680-L685"> <span class="spec-call"><a href="#CoerceResult()" data-name="CoerceResult">CoerceResult</a>(<var data-name="leafType">leafType</var>, <var data-name="value">value</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L681">Assert <var data-name="value">value</var> is not <span class="spec-keyword">null</span>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L682-L685">Return the result of calling the internal method provided by the type system for determining the “result coercion” of <var data-name="leafType">leafType</var> given the value <var data-name="value">value</var>. This internal method must return a valid value for the type and not <span class="spec-keyword">null</span>. Otherwise throw a field error.</li> </ol> </div> <div id="note-5bde4" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L687-L689"> <a href="#note-5bde4">Note</a> If a field resolver returns <span class="spec-keyword">null</span> then it is handled within <span class="spec-call"><a href="#CompleteValue()" data-name="CompleteValue">CompleteValue</a>()</span> before <span class="spec-call"><a href="#CoerceResult()" data-name="CoerceResult">CoerceResult</a>()</span> is called. Therefore both the input and output of <span class="spec-call"><a href="#CoerceResult()" data-name="CoerceResult">CoerceResult</a>()</span> must not be <span class="spec-keyword">null</span>.</div> </section> <section id="sec-Value-Completion.Resolving-Abstract-Types" class="subsec"> <h6 data-source="spec/Section%206%20--%20Execution.md#L691"><a href="#sec-Value-Completion.Resolving-Abstract-Types" title="link to this subsection">Resolving Abstract Types</a></h6> <p data-source="spec/Section%206%20--%20Execution.md#L693-L696">When completing a field with an abstract return type, that is an Interface or Union return type, first the abstract type must be resolved to a relevant Object type. This determination is made by the internal system using whatever means appropriate.</p> <div id="note-5ee58" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L698-L700"> <a href="#note-5ee58">Note</a> A common method of determining the Object type for an <var data-name="objectValue">objectValue</var> in object-oriented environments, such as Java or C#, is to use the class name of the <var data-name="objectValue">objectValue</var>.</div> <div class="spec-algo" id="ResolveAbstractType()" data-source="spec/Section%206%20--%20Execution.md#L702-L705"> <span class="spec-call"><a href="#ResolveAbstractType()" data-name="ResolveAbstractType">ResolveAbstractType</a>(<var data-name="abstractType">abstractType</var>, <var data-name="objectValue">objectValue</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L703-L705">Return the result of calling the internal method provided by the type system for determining the Object type of <var data-name="abstractType">abstractType</var> given the value <var data-name="objectValue">objectValue</var>.</li> </ol> </div> </section> <section id="sec-Value-Completion.Merging-Selection-Sets" class="subsec"> <h6 data-source="spec/Section%206%20--%20Execution.md#L707"><a href="#sec-Value-Completion.Merging-Selection-Sets" title="link to this subsection">Merging Selection Sets</a></h6> <p data-source="spec/Section%206%20--%20Execution.md#L709-L711">When more than one field of the same name is executed in parallel, their selection sets are merged together when completing the value in order to continue execution of the sub-selection sets.</p> <p data-source="spec/Section%206%20--%20Execution.md#L713-L714">An example operation illustrating parallel fields with the same name with sub-selections.</p> <pre id="example-77852" class="spec-example" data-language="graphql" data-source="spec/Section%206%20--%20Execution.md#L716-L725"><a href="#example-77852">Example № 195</a><code><span class="token punctuation">{</span> <span class="token object">me</span> <span class="token punctuation">{</span> <span class="token property">firstName</span> <span class="token punctuation">}</span> <span class="token object">me</span> <span class="token punctuation">{</span> <span class="token property">lastName</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%206%20--%20Execution.md#L727-L728">After resolving the value for <code>me</code>, the selection sets are merged together so <code>firstName</code> and <code>lastName</code> can be resolved for one value.</p> <div class="spec-algo" id="MergeSelectionSets()" data-source="spec/Section%206%20--%20Execution.md#L730-L736"> <span class="spec-call"><a href="#MergeSelectionSets()" data-name="MergeSelectionSets">MergeSelectionSets</a>(<var data-name="fields">fields</var>)</span><ol> <li data-source="spec/Section%206%20--%20Execution.md#L731">Let <var data-name="selectionSet">selectionSet</var> be an empty list.</li> <li data-source="spec/Section%206%20--%20Execution.md#L732-L735">For each <var data-name="field">field</var> in <var data-name="fields">fields</var>:<ol> <li data-source="spec/Section%206%20--%20Execution.md#L733">Let <var data-name="fieldSelectionSet">fieldSelectionSet</var> be the selection set of <var data-name="field">field</var>.</li> <li data-source="spec/Section%206%20--%20Execution.md#L734">If <var data-name="fieldSelectionSet">fieldSelectionSet</var> is null or empty, continue to the next field.</li> <li data-source="spec/Section%206%20--%20Execution.md#L735">Append all selections in <var data-name="fieldSelectionSet">fieldSelectionSet</var> to <var data-name="selectionSet">selectionSet</var>.</li> </ol> </li> <li data-source="spec/Section%206%20--%20Execution.md#L736">Return <var data-name="selectionSet">selectionSet</var>.</li> </ol> </div> </section> </section> <section id="sec-Handling-Field-Errors" secid="6.4.4"> <h3 data-source="spec/Section%206%20--%20Execution.md#L739"><span class="spec-secid" title="link to this section"><a href="#sec-Handling-Field-Errors">6.4.4</a></span>Handling Field Errors</h3> <p data-source="spec/Section%206%20--%20Execution.md#L741-L743"><a href="#sec-Errors.Field-errors">“Field errors”</a> are raised from a particular field during value resolution or coercion. While these errors should be reported in the response, they are “handled” by producing a partial response.</p> <div id="note-c78be" class="spec-note" data-source="spec/Section%206%20--%20Execution.md#L745-L747"> <a href="#note-c78be">Note</a> This is distinct from <a href="#sec-Errors.Request-errors">“request errors”</a> which are raised before execution begins. If a request error is encountered, execution does not begin and no data is returned in the response.</div> <p data-source="spec/Section%206%20--%20Execution.md#L749-L751">If a field error is raised while resolving a field, it is handled as though the field returned <span class="spec-keyword">null</span>, and the error must be added to the <span class="spec-string">"errors"</span> list in the response.</p> <p data-source="spec/Section%206%20--%20Execution.md#L753-L756">If the result of resolving a field is <span class="spec-keyword">null</span> (either because the function to resolve the field returned <span class="spec-keyword">null</span> or because a field error was raised), and that field is of a <code>Non-Null</code> type, then a field error is raised. The error must be added to the <span class="spec-string">"errors"</span> list in the response.</p> <p data-source="spec/Section%206%20--%20Execution.md#L758-L761">If the field returns <span class="spec-keyword">null</span> because of a field error which has already been added to the <span class="spec-string">"errors"</span> list in the response, the <span class="spec-string">"errors"</span> list must not be further affected. That is, only one error should be added to the errors list per field.</p> <p data-source="spec/Section%206%20--%20Execution.md#L763-L766">Since <code>Non-Null</code> type fields cannot be <span class="spec-keyword">null</span>, field errors are propagated to be handled by the parent field. If the parent field may be <span class="spec-keyword">null</span> then it resolves to <span class="spec-keyword">null</span>, otherwise if it is a <code>Non-Null</code> type, the field error is further propagated to its parent field.</p> <p data-source="spec/Section%206%20--%20Execution.md#L768-L771">If a <code>List</code> type wraps a <code>Non-Null</code> type, and one of the elements of that list resolves to <span class="spec-keyword">null</span>, then the entire list must resolve to <span class="spec-keyword">null</span>. If the <code>List</code> type is also wrapped in a <code>Non-Null</code>, the field error continues to propagate upwards.</p> <p data-source="spec/Section%206%20--%20Execution.md#L773-L776">If all fields from the root of the request to the source of the field error return <code>Non-Null</code> types, then the <span class="spec-string">"data"</span> entry in the response should be <span class="spec-keyword">null</span>. </p> </section> </section> </section> <section id="sec-Response" secid="7"> <h1 data-source="spec/Section%207%20--%20Response.md#L1"><span class="spec-secid" title="link to this section"><a href="#sec-Response">7</a></span>Response</h1> <p data-source="spec/Section%207%20--%20Response.md#L3-L5">When a GraphQL service receives a request, it must return a well-formed response. The service’s response describes the result of executing the requested operation if successful, and describes any errors raised during the request.</p> <p data-source="spec/Section%207%20--%20Response.md#L7-L8">A response may contain both a partial response as well as any field errors in the case that a field error was raised on a field and was replaced with <span class="spec-keyword">null</span>.</p> <section id="sec-Response-Format" secid="7.1"> <h2 data-source="spec/Section%207%20--%20Response.md#L10"><span class="spec-secid" title="link to this section"><a href="#sec-Response-Format">7.1</a></span>Response Format</h2> <p data-source="spec/Section%207%20--%20Response.md#L12">A response to a GraphQL request must be a map.</p> <p data-source="spec/Section%207%20--%20Response.md#L14-L17">If the request raised any errors, the response map must contain an entry with key <code>errors</code>. The value of this entry is described in the “Errors” section. If the request completed without raising any errors, this entry must not be present.</p> <p data-source="spec/Section%207%20--%20Response.md#L19-L22">If the request included execution, the response map must contain an entry with key <code>data</code>. The value of this entry is described in the “Data” section. If the request failed before execution, due to a syntax error, missing information, or validation error, this entry must not be present.</p> <p data-source="spec/Section%207%20--%20Response.md#L24-L27">The response map may also contain an entry with key <code>extensions</code>. This entry, if set, must have a map as its value. This entry is reserved for implementors to extend the protocol however they see fit, and hence there are no additional restrictions on its contents.</p> <p data-source="spec/Section%207%20--%20Response.md#L29-L31">To ensure future changes to the protocol do not break existing services and clients, the top level response map must not contain any entries other than the three described above.</p> <div id="note-6f005" class="spec-note" data-source="spec/Section%207%20--%20Response.md#L33-L35"> <a href="#note-6f005">Note</a> When <code>errors</code> is present in the response, it may be helpful for it to appear first when serialized to make it more clear when errors are present in a response during debugging.</div> <section id="sec-Data" secid="7.1.1"> <h3 data-source="spec/Section%207%20--%20Response.md#L37"><span class="spec-secid" title="link to this section"><a href="#sec-Data">7.1.1</a></span>Data</h3> <p data-source="spec/Section%207%20--%20Response.md#L39-L42">The <code>data</code> entry in the response will be the result of the execution of the requested operation. If the operation was a query, this output will be an object of the query root operation type; if the operation was a mutation, this output will be an object of the mutation root operation type.</p> <p data-source="spec/Section%207%20--%20Response.md#L44-L45">If an error was raised before execution begins, the <code>data</code> entry should not be present in the result.</p> <p data-source="spec/Section%207%20--%20Response.md#L47-L48">If an error was raised during the execution that prevented a valid response, the <code>data</code> entry in the response should be <code>null</code>.</p> </section> <section id="sec-Errors" secid="7.1.2"> <h3 data-source="spec/Section%207%20--%20Response.md#L51"><span class="spec-secid" title="link to this section"><a href="#sec-Errors">7.1.2</a></span>Errors</h3> <p data-source="spec/Section%207%20--%20Response.md#L53-L54">The <code>errors</code> entry in the response is a non-empty list of errors, where each error is a map.</p> <p data-source="spec/Section%207%20--%20Response.md#L56-L57">If no errors were raised during the request, the <code>errors</code> entry should not be present in the result.</p> <p data-source="spec/Section%207%20--%20Response.md#L59-L61">If the <code>data</code> entry in the response is not present, the <code>errors</code> entry in the response must not be empty. It must contain at least one error. The errors it contains should indicate why no data was able to be returned.</p> <p data-source="spec/Section%207%20--%20Response.md#L63-L66">If the <code>data</code> entry in the response is present (including if it is the value <span class="spec-keyword">null</span>), the <code>errors</code> entry in the response may contain any field errors that were raised during execution. If field errors were raised during execution, it should contain those errors.</p> <section id="sec-Errors.Request-errors" class="subsec"> <h6 data-source="spec/Section%207%20--%20Response.md#L68"><a href="#sec-Errors.Request-errors" title="link to this subsection">Request errors</a></h6> <p data-source="spec/Section%207%20--%20Response.md#L70-L72">Request errors are raised before execution begins. This may occur due to a parse grammar or validation error in the requested document, an inability to determine which operation to execute, or invalid input values for variables.</p> <p data-source="spec/Section%207%20--%20Response.md#L74">Request errors are typically the fault of the requesting client.</p> <p data-source="spec/Section%207%20--%20Response.md#L76-L77">If a request error is raised, execution does not begin and the <code>data</code> entry in the response must not be present. The <code>errors</code> entry must include the error.</p> </section> <section id="sec-Errors.Field-errors" class="subsec"> <h6 data-source="spec/Section%207%20--%20Response.md#L79"><a href="#sec-Errors.Field-errors" title="link to this subsection">Field errors</a></h6> <p data-source="spec/Section%207%20--%20Response.md#L81-L83">Field errors are raised during execution from a particular field. This may occur due to an internal error during value resolution or failure to coerce the resulting value.</p> <p data-source="spec/Section%207%20--%20Response.md#L85">Field errors are typically the fault of GraphQL service.</p> <p data-source="spec/Section%207%20--%20Response.md#L87-L90">If a field error is raised, execution attempts to continue and a partial result is produced (see <a href="#sec-Handling-Field-Errors">Handling Field Errors</a>). The <code>data</code> entry in the response must be present. The <code>errors</code> entry should include all raised field errors.</p> </section> <section id="sec-Errors.Error-result-format" class="subsec"> <h6 data-source="spec/Section%207%20--%20Response.md#L92"><a href="#sec-Errors.Error-result-format" title="link to this subsection">Error result format</a></h6> <p data-source="spec/Section%207%20--%20Response.md#L94-L96">Every error must contain an entry with the key <code>message</code> with a string description of the error intended for the developer as a guide to understand and correct the error.</p> <p data-source="spec/Section%207%20--%20Response.md#L98-L102">If an error can be associated to a particular point in the requested GraphQL document, it should contain an entry with the key <code>locations</code> with a list of locations, where each location is a map with the keys <code>line</code> and <code>column</code>, both positive numbers starting from <code>1</code> which describe the beginning of an associated syntax element.</p> <p data-source="spec/Section%207%20--%20Response.md#L104-L107">If an error can be associated to a particular field in the GraphQL result, it must contain an entry with the key <code>path</code> that details the path of the response field which experienced the error. This allows clients to identify whether a <code>null</code> result is intentional or caused by a runtime error.</p> <p data-source="spec/Section%207%20--%20Response.md#L109-L114">This field should be a list of path segments starting at the root of the response and ending with the field associated with the error. Path segments that represent fields should be strings, and path segments that represent list indices should be 0-indexed integers. If the error happens in an aliased field, the path to the error should use the aliased name, since it represents a path in the response, not in the request.</p> <p data-source="spec/Section%207%20--%20Response.md#L116-L117">For example, if fetching one of the friends’ names fails in the following operation:</p> <pre id="example-bc485" class="spec-example" data-language="graphql" data-source="spec/Section%207%20--%20Response.md#L119-L129"><a href="#example-bc485">Example № 196</a><code><span class="token punctuation">{</span> <span class="token property-query">hero</span><span class="token punctuation">(</span><span class="token attr-name">episode</span><span class="token punctuation">:</span> <span class="token variable">$episode</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token property">name</span> <span class="token attr-name">heroFriends</span><span class="token punctuation">:</span> <span class="token object">friends</span> <span class="token punctuation">{</span> <span class="token property">id</span> <span class="token property">name</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%207%20--%20Response.md#L131">The response might look like:</p> <pre id="example-072c4" class="spec-example" data-language="json" data-source="spec/Section%207%20--%20Response.md#L133-L162"><a href="#example-072c4">Example № 197</a><code><span class="token punctuation">{</span> <span class="token property">"errors"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"message"</span><span class="token operator">:</span> <span class="token string">"Name for character with ID 1002 could not be fetched."</span><span class="token punctuation">,</span> <span class="token property">"locations"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span> <span class="token property">"line"</span><span class="token operator">:</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token property">"column"</span><span class="token operator">:</span> <span class="token number">7</span> <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"path"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">"hero"</span><span class="token punctuation">,</span> <span class="token string">"heroFriends"</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"name"</span><span class="token punctuation">]</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"data"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"hero"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"R2-D2"</span><span class="token punctuation">,</span> <span class="token property">"heroFriends"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"id"</span><span class="token operator">:</span> <span class="token string">"1000"</span><span class="token punctuation">,</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Luke Skywalker"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token property">"id"</span><span class="token operator">:</span> <span class="token string">"1002"</span><span class="token punctuation">,</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token null keyword">null</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token property">"id"</span><span class="token operator">:</span> <span class="token string">"1003"</span><span class="token punctuation">,</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Leia Organa"</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%207%20--%20Response.md#L164-L167">If the field which experienced an error was declared as <code>Non-Null</code>, the <code>null</code> result will bubble up to the next nullable field. In that case, the <code>path</code> for the error should include the full path to the result field where the error was raised, even if that field is not present in the response.</p> <p data-source="spec/Section%207%20--%20Response.md#L169-L171">For example, if the <code>name</code> field from above had declared a <code>Non-Null</code> return type in the schema, the result would look different but the error reported would be the same:</p> <pre id="example-c18ef" class="spec-example" data-language="json" data-source="spec/Section%207%20--%20Response.md#L173-L199"><a href="#example-c18ef">Example № 198</a><code><span class="token punctuation">{</span> <span class="token property">"errors"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"message"</span><span class="token operator">:</span> <span class="token string">"Name for character with ID 1002 could not be fetched."</span><span class="token punctuation">,</span> <span class="token property">"locations"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span> <span class="token property">"line"</span><span class="token operator">:</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token property">"column"</span><span class="token operator">:</span> <span class="token number">7</span> <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"path"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">"hero"</span><span class="token punctuation">,</span> <span class="token string">"heroFriends"</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"name"</span><span class="token punctuation">]</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"data"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"hero"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"R2-D2"</span><span class="token punctuation">,</span> <span class="token property">"heroFriends"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"id"</span><span class="token operator">:</span> <span class="token string">"1000"</span><span class="token punctuation">,</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Luke Skywalker"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token null keyword">null</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token property">"id"</span><span class="token operator">:</span> <span class="token string">"1003"</span><span class="token punctuation">,</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Leia Organa"</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%207%20--%20Response.md#L201-L204">GraphQL services may provide an additional entry to errors with key <code>extensions</code>. This entry, if set, must have a map as its value. This entry is reserved for implementors to add additional information to errors however they see fit, and there are no additional restrictions on its contents.</p> <pre id="example-8b658" class="spec-example" data-language="json" data-source="spec/Section%207%20--%20Response.md#L206-L220"><a href="#example-8b658">Example № 199</a><code><span class="token punctuation">{</span> <span class="token property">"errors"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"message"</span><span class="token operator">:</span> <span class="token string">"Name for character with ID 1002 could not be fetched."</span><span class="token punctuation">,</span> <span class="token property">"locations"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span> <span class="token property">"line"</span><span class="token operator">:</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token property">"column"</span><span class="token operator">:</span> <span class="token number">7</span> <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"path"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">"hero"</span><span class="token punctuation">,</span> <span class="token string">"heroFriends"</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"name"</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"extensions"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"code"</span><span class="token operator">:</span> <span class="token string">"CAN_NOT_FETCH_BY_ID"</span><span class="token punctuation">,</span> <span class="token property">"timestamp"</span><span class="token operator">:</span> <span class="token string">"Fri Feb 9 14:33:09 UTC 2018"</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> </code></pre> <p data-source="spec/Section%207%20--%20Response.md#L222-L224">GraphQL services should not provide any additional entries to the error format since they could conflict with additional entries that may be added in future versions of this specification.</p> <div id="note-5c13b" class="spec-note" data-source="spec/Section%207%20--%20Response.md#L226-L228"> <a href="#note-5c13b">Note</a> Previous versions of this spec did not describe the <code>extensions</code> entry for error formatting. While non-specified entries are not violations, they are still discouraged.</div> <pre id="example-78af4" class="spec-counter-example" data-language="json" data-source="spec/Section%207%20--%20Response.md#L230-L242"><a href="#example-78af4">Counter Example № 200</a><code><span class="token punctuation">{</span> <span class="token property">"errors"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"message"</span><span class="token operator">:</span> <span class="token string">"Name for character with ID 1002 could not be fetched."</span><span class="token punctuation">,</span> <span class="token property">"locations"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span> <span class="token property">"line"</span><span class="token operator">:</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token property">"column"</span><span class="token operator">:</span> <span class="token number">7</span> <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"path"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">"hero"</span><span class="token punctuation">,</span> <span class="token string">"heroFriends"</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"name"</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"code"</span><span class="token operator">:</span> <span class="token string">"CAN_NOT_FETCH_BY_ID"</span><span class="token punctuation">,</span> <span class="token property">"timestamp"</span><span class="token operator">:</span> <span class="token string">"Fri Feb 9 14:33:09 UTC 2018"</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> </code></pre> </section> </section> </section> <section id="sec-Serialization-Format" secid="7.2"> <h2 data-source="spec/Section%207%20--%20Response.md#L245"><span class="spec-secid" title="link to this section"><a href="#sec-Serialization-Format">7.2</a></span>Serialization Format</h2> <p data-source="spec/Section%207%20--%20Response.md#L247-L250">GraphQL does not require a specific serialization format. However, clients should use a serialization format that supports the major primitives in the GraphQL response. In particular, the serialization format must at least support representations of the following four primitives:</p> <ul> <li data-source="spec/Section%207%20--%20Response.md#L252">Map</li> <li data-source="spec/Section%207%20--%20Response.md#L253">List</li> <li data-source="spec/Section%207%20--%20Response.md#L254">String</li> <li data-source="spec/Section%207%20--%20Response.md#L255">Null</li> </ul> <p data-source="spec/Section%207%20--%20Response.md#L257-L259">A serialization format should also support the following primitives, each representing one of the common GraphQL scalar types, however a string or simpler primitive may be used as a substitute if any are not directly supported:</p> <ul> <li data-source="spec/Section%207%20--%20Response.md#L261">Boolean</li> <li data-source="spec/Section%207%20--%20Response.md#L262">Int</li> <li data-source="spec/Section%207%20--%20Response.md#L263">Float</li> <li data-source="spec/Section%207%20--%20Response.md#L264">Enum Value</li> </ul> <p data-source="spec/Section%207%20--%20Response.md#L266-L269">This is not meant to be an exhaustive list of what a serialization format may encode. For example custom scalars representing a Date, Time, URI, or number with a different precision may be represented in whichever relevant format a given serialization format may support.</p> <section id="sec-JSON-Serialization" secid="7.2.1"> <h3 data-source="spec/Section%207%20--%20Response.md#L272"><span class="spec-secid" title="link to this section"><a href="#sec-JSON-Serialization">7.2.1</a></span>JSON Serialization</h3> <p data-source="spec/Section%207%20--%20Response.md#L274-L275">JSON is the most common serialization format for GraphQL. Though as mentioned above, GraphQL does not require a specific serialization format.</p> <p data-source="spec/Section%207%20--%20Response.md#L277-L278">When using JSON as a serialization of GraphQL responses, the following JSON values should be used to encode the related GraphQL values:</p> <table> <thead> <tr data-source="spec/Section%207%20--%20Response.md#L280"> <th>GraphQL Value</th> <th>JSON Value</th> </tr> </thead> <tbody> <tr data-source="spec/Section%207%20--%20Response.md#L282"> <td>Map</td> <td>Object</td> </tr> <tr data-source="spec/Section%207%20--%20Response.md#L283"> <td>List</td> <td>Array</td> </tr> <tr data-source="spec/Section%207%20--%20Response.md#L284"> <td>Null</td> <td><span class="spec-keyword">null</span></td> </tr> <tr data-source="spec/Section%207%20--%20Response.md#L285"> <td>String</td> <td>String</td> </tr> <tr data-source="spec/Section%207%20--%20Response.md#L286"> <td>Boolean</td> <td><span class="spec-keyword">true</span> or <span class="spec-keyword">false</span></td> </tr> <tr data-source="spec/Section%207%20--%20Response.md#L287"> <td>Int</td> <td>Number</td> </tr> <tr data-source="spec/Section%207%20--%20Response.md#L288"> <td>Float</td> <td>Number</td> </tr> <tr data-source="spec/Section%207%20--%20Response.md#L289"> <td>Enum Value</td> <td>String</td> </tr> </tbody> </table> <div id="note-786e2" class="spec-note" data-source="spec/Section%207%20--%20Response.md#L291-L292"> <a href="#note-786e2">Note</a> For consistency and ease of notation, examples of responses are given in JSON format throughout this document.</div> </section> <section id="sec-Serialized-Map-Ordering" secid="7.2.2"> <h3 data-source="spec/Section%207%20--%20Response.md#L295"><span class="spec-secid" title="link to this section"><a href="#sec-Serialized-Map-Ordering">7.2.2</a></span>Serialized Map Ordering</h3> <p data-source="spec/Section%207%20--%20Response.md#L297-L303">Since the result of evaluating a selection set is ordered, the serialized Map of results should preserve this order by writing the map entries in the same order as those fields were requested as defined by selection set execution. Producing a serialized response where fields are represented in the same order in which they appear in the request improves human readability during debugging and enables more efficient parsing of responses if the order of properties can be anticipated.</p> <p data-source="spec/Section%207%20--%20Response.md#L305-L309">Serialization formats which represent an ordered map should preserve the order of requested fields as defined by <span class="spec-call"><a href="#CollectFields()" data-name="CollectFields">CollectFields</a>()</span> in the Execution section. Serialization formats which only represent unordered maps but where order is still implicit in the serialization’s textual order (such as JSON) should preserve the order of requested fields textually.</p> <p data-source="spec/Section%207%20--%20Response.md#L311-L313">For example, if the request was <code>{ name, age }</code>, a GraphQL service responding in JSON should respond with <code>{ "name": "Mark", "age": 30 }</code> and should not respond with <code>{ "age": 30, "name": "Mark" }</code>.</p> <p data-source="spec/Section%207%20--%20Response.md#L315-L319">While JSON Objects are specified as an <a href="https://tools.ietf.org/html/rfc7159#section-4">unordered collection of key-value pairs</a> the pairs are represented in an ordered manner. In other words, while the JSON strings <code>{ "name": "Mark", "age": 30 }</code> and <code>{ "age": 30, "name": "Mark" }</code> encode the same value, they also have observably different property orderings.</p> <div id="note-4bb20" class="spec-note" data-source="spec/Section%207%20--%20Response.md#L321-L323"> <a href="#note-4bb20">Note</a> This does not violate the JSON spec, as clients may still interpret objects in the response as unordered Maps and arrive at a valid value. </div> </section> </section> </section> <section id="sec-Appendix-Notation-Conventions" secid="A"> <h1 data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L1"><span class="spec-secid" title="link to this section"><a href="#sec-Appendix-Notation-Conventions">A</a></span>Appendix: Notation Conventions</h1> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L3-L5">This specification document contains a number of notation conventions used to describe technical concepts such as language grammar and semantics as well as runtime algorithms.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L7-L8">This appendix seeks to explain these notations in greater detail to avoid ambiguity.</p> <section id="sec-Context-Free-Grammar" secid="A.1"> <h2 data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L11"><span class="spec-secid" title="link to this section"><a href="#sec-Context-Free-Grammar">A.1</a></span>Context-Free Grammar</h2> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L13-L16">A context-free grammar consists of a number of productions. Each production has an abstract symbol called a “non-terminal” as its left-hand side, and zero or more possible sequences of non-terminal symbols and or terminal characters as its right-hand side.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L18-L22">Starting from a single goal non-terminal symbol, a context-free grammar describes a language: the set of possible sequences of characters that can be described by repeatedly replacing any non-terminal in the goal sequence with one of the sequences it is defined by, until all non-terminal symbols have been replaced by terminal characters.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L24-L28">Terminals are represented in this document in a monospace font in two forms: a specific Unicode character or sequence of Unicode characters (ie. <span class="spec-t">=</span> or <span class="spec-t">terminal</span>), and prose typically describing a specific Unicode code-point <span class="spec-string">"Space (U+0020)"</span>. Sequences of Unicode characters only appear in syntactic grammars and represent a <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span> token of that specific sequence.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L30-L31">Non-terminal production rules are represented in this document using the following notation for a non-terminal with a single definition:</p> <div class="spec-production" id="NonTerminalWithSingleDefinition" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L33"> <span class="spec-nt"><a href="#NonTerminalWithSingleDefinition" data-name="NonTerminalWithSingleDefinition">NonTerminalWithSingleDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><span data-name="NonTerminal">NonTerminal</span></span><span class="spec-t">terminal</span></div> </div> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L35">While using the following notation for a production with a list of definitions:</p> <div class="spec-production" id="NonTerminalWithManyDefinitions" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L37-L39"> <span class="spec-nt"><a href="#NonTerminalWithManyDefinitions" data-name="NonTerminalWithManyDefinitions">NonTerminalWithManyDefinitions</a></span><div class="spec-rhs"><span class="spec-nt"><span data-name="OtherNonTerminal">OtherNonTerminal</span></span><span class="spec-t">terminal</span></div> <div class="spec-rhs"><span class="spec-t">terminal</span></div> </div> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L41-L42">A definition may refer to itself, which describes repetitive sequences, for example:</p> <div class="spec-production" id="ListOfLetterA" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L44-L46"> <span class="spec-nt"><a href="#ListOfLetterA" data-name="ListOfLetterA">ListOfLetterA</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ListOfLetterA" data-name="ListOfLetterA">ListOfLetterA</a></span><span class="spec-t">a</span></div> <div class="spec-rhs"><span class="spec-t">a</span></div> </div> </section> <section id="sec-Lexical-and-Syntactical-Grammar" secid="A.2"> <h2 data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L49"><span class="spec-secid" title="link to this section"><a href="#sec-Lexical-and-Syntactical-Grammar">A.2</a></span>Lexical and Syntactical Grammar</h2> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L51-L56">The GraphQL language is defined in a syntactic grammar where terminal symbols are tokens. Tokens are defined in a lexical grammar which matches patterns of source characters. The result of parsing a source text sequence of Unicode characters first produces a sequence of lexical tokens according to the lexical grammar which then produces abstract syntax tree (AST) according to the syntactical grammar.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L58-L62">A lexical grammar production describes non-terminal “tokens” by patterns of terminal Unicode characters. No “whitespace” or other ignored characters may appear between any terminal Unicode characters in the lexical grammar production. A lexical grammar production is distinguished by a two colon <code>::</code> definition.</p> <div class="spec-production d2" id="Word" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L64"> <span class="spec-nt"><a href="#Word" data-name="Word">Word</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Letter" data-name="Letter">Letter</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L66-L69">A Syntactical grammar production describes non-terminal “rules” by patterns of terminal Tokens. <span class="spec-nt"><a href="#WhiteSpace" data-name="WhiteSpace">WhiteSpace</a></span> and other <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span> sequences may appear before or after any terminal <span class="spec-nt"><a href="#Token" data-name="Token">Token</a></span>. A syntactical grammar production is distinguished by a one colon <code>:</code> definition.</p> <div class="spec-production" id="Sentence" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L71"> <span class="spec-nt"><a href="#Sentence" data-name="Sentence">Sentence</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Word" data-name="Word">Word</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">.</span></div> </div> </section> <section id="sec-Grammar-Notation" secid="A.3"> <h2 data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L74"><span class="spec-secid" title="link to this section"><a href="#sec-Grammar-Notation">A.3</a></span>Grammar Notation</h2> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L76-L79">This specification uses some additional notation to describe common patterns, such as optional or repeated patterns, or parameterized alterations of the definition of a non-terminal. This section explains these short-hand notations and their expanded definitions in the context-free grammar.</p> <section id="sec-Grammar-Notation.Constraints" class="subsec"> <h6 data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L82"><a href="#sec-Grammar-Notation.Constraints" title="link to this subsection">Constraints</a></h6> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L84-L85">A grammar production may specify that certain expansions are not permitted by using the phrase “but not” and then indicating the expansions to be excluded.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L87-L89">For example, the following production means that the non-terminal <span class="spec-nt"><a href="#SafeWord" data-name="SafeWord">SafeWord</a></span> may be replaced by any sequence of characters that could replace <span class="spec-nt"><a href="#Word" data-name="Word">Word</a></span> provided that the same sequence of characters could not replace <span class="spec-nt"><span data-name="SevenCarlinWords">SevenCarlinWords</span></span>.</p> <div class="spec-production" id="SafeWord" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L91"> <span class="spec-nt"><a href="#SafeWord" data-name="SafeWord">SafeWord</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#Word" data-name="Word">Word</a></span><span class="spec-butnot"><span class="spec-nt"><span data-name="SevenCarlinWords">SevenCarlinWords</span></span></span></span></div> </div> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L93-L94">A grammar may also list a number of restrictions after “but not” separated by “or”.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L96">For example:</p> <div class="spec-production" id="NonBooleanName" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L98"> <span class="spec-nt"><a href="#NonBooleanName" data-name="NonBooleanName">NonBooleanName</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-butnot"><span class="spec-t">true</span><span class="spec-t">false</span></span></span></div> </div> </section> <section id="sec-Grammar-Notation.Lookahead-Restrictions" class="subsec"> <h6 data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L101"><a href="#sec-Grammar-Notation.Lookahead-Restrictions" title="link to this subsection">Lookahead Restrictions</a></h6> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L103-L105">A grammar production may specify that certain characters or tokens are not permitted to follow it by using the pattern <span class="spec-lookahead ntset not"><span class="spec-nt"><span data-name="NotAllowed">NotAllowed</span></span></span>. Lookahead restrictions are often used to remove ambiguity from the grammar.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L107-L108">The following example makes it clear that <span class="spec-quantified"><span class="spec-nt"><a href="#Letter" data-name="Letter">Letter</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span> must be greedy, since <span class="spec-nt"><a href="#Word" data-name="Word">Word</a></span> cannot be followed by yet another <span class="spec-nt"><a href="#Letter" data-name="Letter">Letter</a></span>.</p> <div class="spec-production d2" id="Word" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L110"> <span class="spec-nt"><a href="#Word" data-name="Word">Word</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Letter" data-name="Letter">Letter</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-lookahead ntset not"><span class="spec-nt"><a href="#Letter" data-name="Letter">Letter</a></span></span></div> </div> </section> <section id="sec-Grammar-Notation.Optionality-and-Lists" class="subsec"> <h6 data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L113"><a href="#sec-Grammar-Notation.Optionality-and-Lists" title="link to this subsection">Optionality and Lists</a></h6> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L115-L116">A subscript suffix “<span class="spec-quantified"><span class="spec-nt"><span data-name="Symbol">Symbol</span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span>” is shorthand for two possible sequences, one including that symbol and one excluding it.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L118">As an example:</p> <div class="spec-production" id="Sentence" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L120"> <span class="spec-nt"><a href="#Sentence" data-name="Sentence">Sentence</a></span><div class="spec-rhs"><span class="spec-nt"><span data-name="Noun">Noun</span></span><span class="spec-nt"><span data-name="Verb">Verb</span></span><span class="spec-quantified"><span class="spec-nt"><span data-name="Adverb">Adverb</span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L122">is shorthand for</p> <div class="spec-production" id="Sentence" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L124-L126"> <span class="spec-nt"><a href="#Sentence" data-name="Sentence">Sentence</a></span><div class="spec-rhs"><span class="spec-nt"><span data-name="Noun">Noun</span></span><span class="spec-nt"><span data-name="Verb">Verb</span></span><span class="spec-nt"><span data-name="Adverb">Adverb</span></span></div> <div class="spec-rhs"><span class="spec-nt"><span data-name="Noun">Noun</span></span><span class="spec-nt"><span data-name="Verb">Verb</span></span></div> </div> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L128-L129">A subscript suffix “<span class="spec-quantified"><span class="spec-nt"><span data-name="Symbol">Symbol</span></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span>” is shorthand for a list of one or more of that symbol, represented as an additional recursive production.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L131">As an example:</p> <div class="spec-production" id="Book" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L133"> <span class="spec-nt"><a href="#Book" data-name="Book">Book</a></span><div class="spec-rhs"><span class="spec-nt"><span data-name="Cover">Cover</span></span><span class="spec-quantified"><span class="spec-nt"><span data-name="Page">Page</span></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-nt"><span data-name="Cover">Cover</span></span></div> </div> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L135">is shorthand for</p> <div class="spec-production" id="Book" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L137"> <span class="spec-nt"><a href="#Book" data-name="Book">Book</a></span><div class="spec-rhs"><span class="spec-nt"><span data-name="Cover">Cover</span></span><span class="spec-nt"><a href="#Page_list" data-name="Page_list">Page_list</a></span><span class="spec-nt"><span data-name="Cover">Cover</span></span></div> </div> <div class="spec-production" id="Page_list" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L139-L141"> <span class="spec-nt"><a href="#Page_list" data-name="Page_list">Page_list</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Page_list" data-name="Page_list">Page_list</a></span><span class="spec-nt"><span data-name="Page">Page</span></span></div> <div class="spec-rhs"><span class="spec-nt"><span data-name="Page">Page</span></span></div> </div> </section> <section id="sec-Grammar-Notation.Parameterized-Grammar-Productions" class="subsec"> <h6 data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L144"><a href="#sec-Grammar-Notation.Parameterized-Grammar-Productions" title="link to this subsection">Parameterized Grammar Productions</a></h6> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L146-L152">A symbol definition subscript suffix parameter in braces “<span class="spec-nt"><span data-name="Symbol">Symbol</span><span class="spec-params"><span class="spec-param">Param</span></span></span>” is shorthand for two symbol definitions, one appended with that parameter name, the other without. The same subscript suffix on a symbol is shorthand for that variant of the definition. If the parameter starts with “?”, that form of the symbol is used if in a symbol definition with the same parameter. Some possible sequences can be included or excluded conditionally when respectively prefixed with “[+Param]” and “[~Param]”.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L154">As an example:</p> <div class="spec-production" id="Example" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L156-L161"> <span class="spec-nt"><a href="#Example" data-name="Example">Example</a><span class="spec-params"><span class="spec-param">Param</span></span></span><div class="spec-rhs"><span class="spec-nt"><span data-name="A">A</span></span></div> <div class="spec-rhs"><span class="spec-nt"><span data-name="B">B</span><span class="spec-params"><span class="spec-param">Param</span></span></span></div> <div class="spec-rhs"><span class="spec-nt"><span data-name="C">C</span><span class="spec-params"><span class="spec-param conditional">Param</span></span></span></div> <div class="spec-rhs"><span class="spec-condition">Param</span><span class="spec-nt"><span data-name="D">D</span></span></div> <div class="spec-rhs"><span class="spec-condition not">Param</span><span class="spec-nt"><span data-name="E">E</span></span></div> </div> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L163">is shorthand for</p> <div class="spec-production" id="Example" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L165-L169"> <span class="spec-nt"><a href="#Example" data-name="Example">Example</a></span><div class="spec-rhs"><span class="spec-nt"><span data-name="A">A</span></span></div> <div class="spec-rhs"><span class="spec-nt"><span data-name="B_param">B_param</span></span></div> <div class="spec-rhs"><span class="spec-nt"><span data-name="C">C</span></span></div> <div class="spec-rhs"><span class="spec-nt"><span data-name="E">E</span></span></div> </div> <div class="spec-production" id="Example_param" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L171-L175"> <span class="spec-nt"><a href="#Example_param" data-name="Example_param">Example_param</a></span><div class="spec-rhs"><span class="spec-nt"><span data-name="A">A</span></span></div> <div class="spec-rhs"><span class="spec-nt"><span data-name="B_param">B_param</span></span></div> <div class="spec-rhs"><span class="spec-nt"><span data-name="C_param">C_param</span></span></div> <div class="spec-rhs"><span class="spec-nt"><span data-name="D">D</span></span></div> </div> </section> </section> <section id="sec-Grammar-Semantics" secid="A.4"> <h2 data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L178"><span class="spec-secid" title="link to this section"><a href="#sec-Grammar-Semantics">A.4</a></span>Grammar Semantics</h2> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L180-L181">This specification describes the semantic value of many grammar productions in the form of a list of algorithmic steps.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L183">For example, this describes how a parser should interpret a string literal:</p> <div class="spec-semantic d2" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L185-L187"> <span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span><div class="spec-rhs"><span class="spec-t">""</span></div> <ol> <li data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L187">Return an empty Unicode character sequence.</li> </ol> </div> <div class="spec-semantic d2" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L189-L192"> <span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span><div class="spec-rhs"><span class="spec-t">"</span><span class="spec-quantified"><span class="spec-nt"><a href="#StringCharacter" data-name="StringCharacter">StringCharacter</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">"</span></div> <ol> <li data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L191-L192">Return the Unicode character sequence of all <span class="spec-nt"><a href="#StringCharacter" data-name="StringCharacter">StringCharacter</a></span> Unicode character values.</li> </ol> </div> </section> <section id="sec-Algorithms" secid="A.5"> <h2 data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L195"><span class="spec-secid" title="link to this section"><a href="#sec-Algorithms">A.5</a></span>Algorithms</h2> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L197-L202">This specification describes some algorithms used by the static and runtime semantics, they’re defined in the form of a function-like syntax with the algorithm’s name and the arguments it accepts along with a list of algorithmic steps to take in the order listed. Each step may establish references to other values, check various conditions, call other algorithms, and eventually return a value representing the outcome of the algorithm for the provided arguments.</p> <p data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L204-L206">For example, the following example describes an algorithm named <span class="spec-nt"><span data-name="Fibonacci">Fibonacci</span></span> which accepts a single argument <var data-name="number">number</var>. The algorithm’s steps produce the next number in the Fibonacci sequence:</p> <div class="spec-algo" id="Fibonacci()" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L208-L215"> <span class="spec-call"><a href="#Fibonacci()" data-name="Fibonacci">Fibonacci</a>(<var data-name="number">number</var>)</span><ol> <li data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L209-L210">If <var data-name="number">number</var> is <span class="spec-t">0</span>:<ol> <li data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L210">Return <span class="spec-t">1</span>.</li> </ol> </li> <li data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L211-L212">If <var data-name="number">number</var> is <span class="spec-t">1</span>:<ol> <li data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L212">Return <span class="spec-t">2</span>.</li> </ol> </li> <li data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L213">Let <var data-name="previousNumber">previousNumber</var> be <var data-name="number">number</var> - <span class="spec-t">1</span>.</li> <li data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L214">Let <var data-name="previousPreviousNumber">previousPreviousNumber</var> be <var data-name="number">number</var> - <span class="spec-t">2</span>.</li> <li data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L215">Return <span class="spec-call"><a href="#Fibonacci()" data-name="Fibonacci">Fibonacci</a>(<var data-name="previousNumber">previousNumber</var>)</span> + <span class="spec-call"><a href="#Fibonacci()" data-name="Fibonacci">Fibonacci</a>(<var data-name="previousPreviousNumber">previousPreviousNumber</var>)</span>.</li> </ol> </div> <div id="note-edb29" class="spec-note" data-source="spec/Appendix%20A%20--%20Notation%20Conventions.md#L217-L219"> <a href="#note-edb29">Note</a> Algorithms described in this document are written to be easy to understand. Implementers are encouraged to include equivalent but optimized implementations. </div> </section> </section> <section id="sec-Appendix-Grammar-Summary" secid="B"> <h1 data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L1"><span class="spec-secid" title="link to this section"><a href="#sec-Appendix-Grammar-Summary">B</a></span>Appendix: Grammar Summary</h1> <section id="sec-Appendix-Grammar-Summary.Source-Text" secid="B.1"> <h2 data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L3"><span class="spec-secid" title="link to this section"><a href="#sec-Appendix-Grammar-Summary.Source-Text">B.1</a></span>Source Text</h2> <div class="spec-production d2" id="SourceCharacter" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L5-L9"> <span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span><div class="spec-rhs"><span class="spec-prose">U+0009</span></div> <div class="spec-rhs"><span class="spec-prose">U+000A</span></div> <div class="spec-rhs"><span class="spec-prose">U+000D</span></div> <div class="spec-rhs"><span class="spec-prose">U+0020–U+FFFF</span></div> </div> </section> <section id="sec-Appendix-Grammar-Summary.Ignored-Tokens" secid="B.2"> <h2 data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L12"><span class="spec-secid" title="link to this section"><a href="#sec-Appendix-Grammar-Summary.Ignored-Tokens">B.2</a></span>Ignored Tokens</h2> <div class="spec-production d2" id="Ignored" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L14-L19"> <span class="spec-nt"><a href="#Ignored" data-name="Ignored">Ignored</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#UnicodeBOM" data-name="UnicodeBOM">UnicodeBOM</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#WhiteSpace" data-name="WhiteSpace">WhiteSpace</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#Comment" data-name="Comment">Comment</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#Comma" data-name="Comma">Comma</a></span></div> </div> <div class="spec-production d2" id="UnicodeBOM" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L21"> <span class="spec-nt"><a href="#UnicodeBOM" data-name="UnicodeBOM">UnicodeBOM</a></span><div class="spec-rhs"><span class="spec-prose">Byte Order Mark (U+FEFF)</span></div> </div> <div class="spec-production d2" id="WhiteSpace" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L23-L25"> <span class="spec-nt"><a href="#WhiteSpace" data-name="WhiteSpace">WhiteSpace</a></span><div class="spec-rhs"><span class="spec-prose">Horizontal Tab (U+0009)</span></div> <div class="spec-rhs"><span class="spec-prose">Space (U+0020)</span></div> </div> <div class="spec-production d2" id="LineTerminator" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L27-L30"> <span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span><div class="spec-rhs"><span class="spec-prose">New Line (U+000A)</span></div> <div class="spec-rhs"><span class="spec-prose">Carriage Return (U+000D)</span><span class="spec-lookahead not"><span class="spec-prose">New Line (U+000A)</span></span></div> <div class="spec-rhs"><span class="spec-prose">Carriage Return (U+000D)</span><span class="spec-prose">New Line (U+000A)</span></div> </div> <div class="spec-production d2" id="Comment" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L32"> <span class="spec-nt"><a href="#Comment" data-name="Comment">Comment</a></span><div class="spec-rhs"><span class="spec-t">#</span><span class="spec-quantified"><span class="spec-nt"><a href="#CommentChar" data-name="CommentChar">CommentChar</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead ntset not"><span class="spec-nt"><a href="#CommentChar" data-name="CommentChar">CommentChar</a></span></span></div> </div> <div class="spec-production d2" id="CommentChar" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L34"> <span class="spec-nt"><a href="#CommentChar" data-name="CommentChar">CommentChar</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span><span class="spec-butnot"><span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span></span></span></div> </div> <div class="spec-production d2" id="Comma" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L36"> <span class="spec-nt"><a href="#Comma" data-name="Comma">Comma</a></span><div class="spec-rhs"><span class="spec-t">,</span></div> </div> </section> <section id="sec-Appendix-Grammar-Summary.Lexical-Tokens" secid="B.3"> <h2 data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L39"><span class="spec-secid" title="link to this section"><a href="#sec-Appendix-Grammar-Summary.Lexical-Tokens">B.3</a></span>Lexical Tokens</h2> <div class="spec-production d2" id="Token" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L41-L46"> <span class="spec-nt"><a href="#Token" data-name="Token">Token</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Punctuator" data-name="Punctuator">Punctuator</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span></div> </div> <div class="spec-production d2" id="Punctuator" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L48"> <span class="spec-nt"><a href="#Punctuator" data-name="Punctuator">Punctuator</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">!</span></td><td class="spec-rhs"><span class="spec-t">$</span></td><td class="spec-rhs"><span class="spec-t">&</span></td><td class="spec-rhs"><span class="spec-t">(</span></td><td class="spec-rhs"><span class="spec-t">)</span></td><td class="spec-rhs"><span class="spec-t">...</span></td><td class="spec-rhs"><span class="spec-t">:</span></td><td class="spec-rhs"><span class="spec-t">=</span></td><td class="spec-rhs"><span class="spec-t">@</span></td><td class="spec-rhs"><span class="spec-t">[</span></td><td class="spec-rhs"><span class="spec-t">]</span></td><td class="spec-rhs"><span class="spec-t">{</span></td><td class="spec-rhs"><span class="spec-t">|</span></td><td class="spec-rhs"><span class="spec-t">}</span></td></tr> </table></div></div> </div> <div class="spec-production d2" id="Name" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L50-L51"> <span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#NameContinue" data-name="NameContinue">NameContinue</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead ntset not"><span class="spec-nt"><a href="#NameContinue" data-name="NameContinue">NameContinue</a></span></span></div> </div> <div class="spec-production d2" id="NameStart" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L53-L55"> <span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Letter" data-name="Letter">Letter</a></span></div> <div class="spec-rhs"><span class="spec-t">_</span></div> </div> <div class="spec-production d2" id="NameContinue" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L57-L60"> <span class="spec-nt"><a href="#NameContinue" data-name="NameContinue">NameContinue</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Letter" data-name="Letter">Letter</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span></div> <div class="spec-rhs"><span class="spec-t">_</span></div> </div> <div class="spec-production d2" id="Letter" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L62-L66"> <span class="spec-nt"><a href="#Letter" data-name="Letter">Letter</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">A</span></td><td class="spec-rhs"><span class="spec-t">B</span></td><td class="spec-rhs"><span class="spec-t">C</span></td><td class="spec-rhs"><span class="spec-t">D</span></td><td class="spec-rhs"><span class="spec-t">E</span></td><td class="spec-rhs"><span class="spec-t">F</span></td><td class="spec-rhs"><span class="spec-t">G</span></td><td class="spec-rhs"><span class="spec-t">H</span></td><td class="spec-rhs"><span class="spec-t">I</span></td><td class="spec-rhs"><span class="spec-t">J</span></td><td class="spec-rhs"><span class="spec-t">K</span></td><td class="spec-rhs"><span class="spec-t">L</span></td><td class="spec-rhs"><span class="spec-t">M</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">N</span></td><td class="spec-rhs"><span class="spec-t">O</span></td><td class="spec-rhs"><span class="spec-t">P</span></td><td class="spec-rhs"><span class="spec-t">Q</span></td><td class="spec-rhs"><span class="spec-t">R</span></td><td class="spec-rhs"><span class="spec-t">S</span></td><td class="spec-rhs"><span class="spec-t">T</span></td><td class="spec-rhs"><span class="spec-t">U</span></td><td class="spec-rhs"><span class="spec-t">V</span></td><td class="spec-rhs"><span class="spec-t">W</span></td><td class="spec-rhs"><span class="spec-t">X</span></td><td class="spec-rhs"><span class="spec-t">Y</span></td><td class="spec-rhs"><span class="spec-t">Z</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">a</span></td><td class="spec-rhs"><span class="spec-t">b</span></td><td class="spec-rhs"><span class="spec-t">c</span></td><td class="spec-rhs"><span class="spec-t">d</span></td><td class="spec-rhs"><span class="spec-t">e</span></td><td class="spec-rhs"><span class="spec-t">f</span></td><td class="spec-rhs"><span class="spec-t">g</span></td><td class="spec-rhs"><span class="spec-t">h</span></td><td class="spec-rhs"><span class="spec-t">i</span></td><td class="spec-rhs"><span class="spec-t">j</span></td><td class="spec-rhs"><span class="spec-t">k</span></td><td class="spec-rhs"><span class="spec-t">l</span></td><td class="spec-rhs"><span class="spec-t">m</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">n</span></td><td class="spec-rhs"><span class="spec-t">o</span></td><td class="spec-rhs"><span class="spec-t">p</span></td><td class="spec-rhs"><span class="spec-t">q</span></td><td class="spec-rhs"><span class="spec-t">r</span></td><td class="spec-rhs"><span class="spec-t">s</span></td><td class="spec-rhs"><span class="spec-t">t</span></td><td class="spec-rhs"><span class="spec-t">u</span></td><td class="spec-rhs"><span class="spec-t">v</span></td><td class="spec-rhs"><span class="spec-t">w</span></td><td class="spec-rhs"><span class="spec-t">x</span></td><td class="spec-rhs"><span class="spec-t">y</span></td><td class="spec-rhs"><span class="spec-t">z</span></td></tr> </table></div></div> </div> <div class="spec-production d2" id="Digit" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L68-L69"> <span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">0</span></td><td class="spec-rhs"><span class="spec-t">1</span></td><td class="spec-rhs"><span class="spec-t">2</span></td><td class="spec-rhs"><span class="spec-t">3</span></td><td class="spec-rhs"><span class="spec-t">4</span></td><td class="spec-rhs"><span class="spec-t">5</span></td><td class="spec-rhs"><span class="spec-t">6</span></td><td class="spec-rhs"><span class="spec-t">7</span></td><td class="spec-rhs"><span class="spec-t">8</span></td><td class="spec-rhs"><span class="spec-t">9</span></td></tr> </table></div></div> </div> <div class="spec-production d2" id="IntValue" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L71"> <span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#IntegerPart" data-name="IntegerPart">IntegerPart</a></span><span class="spec-lookahead set not"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-t">.</span><span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span></span></div> </div> <div class="spec-production d2" id="IntegerPart" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L73-L75"> <span class="spec-nt"><a href="#IntegerPart" data-name="IntegerPart">IntegerPart</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#NegativeSign" data-name="NegativeSign">NegativeSign</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">0</span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#NegativeSign" data-name="NegativeSign">NegativeSign</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#NonZeroDigit" data-name="NonZeroDigit">NonZeroDigit</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production d2" id="NegativeSign" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L77"> <span class="spec-nt"><a href="#NegativeSign" data-name="NegativeSign">NegativeSign</a></span><div class="spec-rhs"><span class="spec-t">-</span></div> </div> <div class="spec-production d2" id="NonZeroDigit" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L79"> <span class="spec-nt"><a href="#NonZeroDigit" data-name="NonZeroDigit">NonZeroDigit</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-butnot"><span class="spec-t">0</span></span></span></div> </div> <div class="spec-production d2" id="FloatValue" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L81-L84"> <span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#IntegerPart" data-name="IntegerPart">IntegerPart</a></span><span class="spec-nt"><a href="#FractionalPart" data-name="FractionalPart">FractionalPart</a></span><span class="spec-nt"><a href="#ExponentPart" data-name="ExponentPart">ExponentPart</a></span><span class="spec-lookahead set not"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-t">.</span><span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#IntegerPart" data-name="IntegerPart">IntegerPart</a></span><span class="spec-nt"><a href="#FractionalPart" data-name="FractionalPart">FractionalPart</a></span><span class="spec-lookahead set not"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-t">.</span><span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#IntegerPart" data-name="IntegerPart">IntegerPart</a></span><span class="spec-nt"><a href="#ExponentPart" data-name="ExponentPart">ExponentPart</a></span><span class="spec-lookahead set not"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-t">.</span><span class="spec-nt"><a href="#NameStart" data-name="NameStart">NameStart</a></span></span></div> </div> <div class="spec-production d2" id="FractionalPart" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L86"> <span class="spec-nt"><a href="#FractionalPart" data-name="FractionalPart">FractionalPart</a></span><div class="spec-rhs"><span class="spec-t">.</span><span class="spec-quantified"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production d2" id="ExponentPart" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L88"> <span class="spec-nt"><a href="#ExponentPart" data-name="ExponentPart">ExponentPart</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ExponentIndicator" data-name="ExponentIndicator">ExponentIndicator</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Sign" data-name="Sign">Sign</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Digit" data-name="Digit">Digit</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production d2" id="ExponentIndicator" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L90"> <span class="spec-nt"><a href="#ExponentIndicator" data-name="ExponentIndicator">ExponentIndicator</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">e</span></td><td class="spec-rhs"><span class="spec-t">E</span></td></tr> </table></div></div> </div> <div class="spec-production d2" id="Sign" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L92"> <span class="spec-nt"><a href="#Sign" data-name="Sign">Sign</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">+</span></td><td class="spec-rhs"><span class="spec-t">-</span></td></tr> </table></div></div> </div> <div class="spec-production d2" id="StringValue" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L94-L97"> <span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span><div class="spec-rhs"><span class="spec-t">""</span><span class="spec-lookahead not"><span class="spec-t">"</span></span></div> <div class="spec-rhs"><span class="spec-t">"</span><span class="spec-quantified"><span class="spec-nt"><a href="#StringCharacter" data-name="StringCharacter">StringCharacter</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">"</span></div> <div class="spec-rhs"><span class="spec-t">"""</span><span class="spec-quantified"><span class="spec-nt"><a href="#BlockStringCharacter" data-name="BlockStringCharacter">BlockStringCharacter</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">"""</span></div> </div> <div class="spec-production d2" id="StringCharacter" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L99-L102"> <span class="spec-nt"><a href="#StringCharacter" data-name="StringCharacter">StringCharacter</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span><span class="spec-butnot"><span class="spec-t">"</span><span class="spec-t">\</span><span class="spec-nt"><a href="#LineTerminator" data-name="LineTerminator">LineTerminator</a></span></span></span></div> <div class="spec-rhs"><span class="spec-t">\u</span><span class="spec-nt"><a href="#EscapedUnicode" data-name="EscapedUnicode">EscapedUnicode</a></span></div> <div class="spec-rhs"><span class="spec-t">\</span><span class="spec-nt"><a href="#EscapedCharacter" data-name="EscapedCharacter">EscapedCharacter</a></span></div> </div> <div class="spec-production d2" id="EscapedUnicode" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L104"> <span class="spec-nt"><a href="#EscapedUnicode" data-name="EscapedUnicode">EscapedUnicode</a></span><div class="spec-rhs"><span class="spec-rx">/[0-9A-Fa-f]{4}/</span></div> </div> <div class="spec-production d2" id="EscapedCharacter" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L106"> <span class="spec-nt"><a href="#EscapedCharacter" data-name="EscapedCharacter">EscapedCharacter</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">"</span></td><td class="spec-rhs"><span class="spec-t">\</span></td><td class="spec-rhs"><span class="spec-t">/</span></td><td class="spec-rhs"><span class="spec-t">b</span></td><td class="spec-rhs"><span class="spec-t">f</span></td><td class="spec-rhs"><span class="spec-t">n</span></td><td class="spec-rhs"><span class="spec-t">r</span></td><td class="spec-rhs"><span class="spec-t">t</span></td></tr> </table></div></div> </div> <div class="spec-production d2" id="BlockStringCharacter" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L108-L110"> <span class="spec-nt"><a href="#BlockStringCharacter" data-name="BlockStringCharacter">BlockStringCharacter</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#SourceCharacter" data-name="SourceCharacter">SourceCharacter</a></span><span class="spec-butnot"><span class="spec-t">"""</span><span class="spec-t">\"""</span></span></span></div> <div class="spec-rhs"><span class="spec-t">\"""</span></div> </div> <div id="note-5ad29" class="spec-note" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L112-L113"> <a href="#note-5ad29">Note</a> Block string values are interpreted to exclude blank initial and trailing lines and uniform indentation with <span class="spec-call"><a href="#BlockStringValue()" data-name="BlockStringValue">BlockStringValue</a>()</span>.</div> </section> <section id="sec-Document-Syntax" secid="B.4"> <h2 data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L116"><span class="spec-secid" title="link to this section"><a href="#sec-Document-Syntax">B.4</a></span>Document Syntax</h2> <div class="spec-production" id="Document" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L118"> <span class="spec-nt"><a href="#Document" data-name="Document">Document</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Definition" data-name="Definition">Definition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production" id="Definition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L120-L122"> <span class="spec-nt"><a href="#Definition" data-name="Definition">Definition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ExecutableDefinition" data-name="ExecutableDefinition">ExecutableDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#TypeSystemDefinitionOrExtension" data-name="TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></span></div> </div> <div class="spec-production" id="ExecutableDocument" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L124"> <span class="spec-nt"><a href="#ExecutableDocument" data-name="ExecutableDocument">ExecutableDocument</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#ExecutableDefinition" data-name="ExecutableDefinition">ExecutableDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production" id="ExecutableDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L126-L128"> <span class="spec-nt"><a href="#ExecutableDefinition" data-name="ExecutableDefinition">ExecutableDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#OperationDefinition" data-name="OperationDefinition">OperationDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#FragmentDefinition" data-name="FragmentDefinition">FragmentDefinition</a></span></div> </div> <div class="spec-production" id="OperationDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L130-L132"> <span class="spec-nt"><a href="#OperationDefinition" data-name="OperationDefinition">OperationDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#OperationType" data-name="OperationType">OperationType</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#VariableDefinitions" data-name="VariableDefinitions">VariableDefinitions</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span></div> </div> <div class="spec-production" id="OperationType" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L134"> <span class="spec-nt"><a href="#OperationType" data-name="OperationType">OperationType</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">query</span></td><td class="spec-rhs"><span class="spec-t">mutation</span></td><td class="spec-rhs"><span class="spec-t">subscription</span></td></tr> </table></div></div> </div> <div class="spec-production" id="SelectionSet" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L136"> <span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#Selection" data-name="Selection">Selection</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <div class="spec-production" id="Selection" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L138-L141"> <span class="spec-nt"><a href="#Selection" data-name="Selection">Selection</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Field" data-name="Field">Field</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#FragmentSpread" data-name="FragmentSpread">FragmentSpread</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#InlineFragment" data-name="InlineFragment">InlineFragment</a></span></div> </div> <div class="spec-production" id="Field" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L143"> <span class="spec-nt"><a href="#Field" data-name="Field">Field</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Alias" data-name="Alias">Alias</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Arguments" data-name="Arguments">Arguments</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="Alias" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L145"> <span class="spec-nt"><a href="#Alias" data-name="Alias">Alias</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-t">:</span></div> </div> <div class="spec-production" id="Arguments" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L147"> <span class="spec-nt"><a href="#Arguments" data-name="Arguments">Arguments</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-t">(</span><span class="spec-quantified"><span class="spec-nt"><a href="#Argument" data-name="Argument">Argument</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">)</span></div> </div> <div class="spec-production" id="Argument" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L149"> <span class="spec-nt"><a href="#Argument" data-name="Argument">Argument</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Value" data-name="Value">Value</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span></div> </div> <div class="spec-production" id="FragmentSpread" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L151"> <span class="spec-nt"><a href="#FragmentSpread" data-name="FragmentSpread">FragmentSpread</a></span><div class="spec-rhs"><span class="spec-t">...</span><span class="spec-nt"><a href="#FragmentName" data-name="FragmentName">FragmentName</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="InlineFragment" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L153"> <span class="spec-nt"><a href="#InlineFragment" data-name="InlineFragment">InlineFragment</a></span><div class="spec-rhs"><span class="spec-t">...</span><span class="spec-quantified"><span class="spec-nt"><a href="#TypeCondition" data-name="TypeCondition">TypeCondition</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span></div> </div> <div class="spec-production" id="FragmentDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L155"> <span class="spec-nt"><a href="#FragmentDefinition" data-name="FragmentDefinition">FragmentDefinition</a></span><div class="spec-rhs"><span class="spec-t">fragment</span><span class="spec-nt"><a href="#FragmentName" data-name="FragmentName">FragmentName</a></span><span class="spec-nt"><a href="#TypeCondition" data-name="TypeCondition">TypeCondition</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#SelectionSet" data-name="SelectionSet">SelectionSet</a></span></div> </div> <div class="spec-production" id="FragmentName" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L157"> <span class="spec-nt"><a href="#FragmentName" data-name="FragmentName">FragmentName</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-butnot"><span class="spec-t">on</span></span></span></div> </div> <div class="spec-production" id="TypeCondition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L159"> <span class="spec-nt"><a href="#TypeCondition" data-name="TypeCondition">TypeCondition</a></span><div class="spec-rhs"><span class="spec-t">on</span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> </div> <div class="spec-production" id="Value" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L161-L170"> <span class="spec-nt"><a href="#Value" data-name="Value">Value</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-condition not">Const</span><span class="spec-nt"><a href="#Variable" data-name="Variable">Variable</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#IntValue" data-name="IntValue">IntValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#FloatValue" data-name="FloatValue">FloatValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#BooleanValue" data-name="BooleanValue">BooleanValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#NullValue" data-name="NullValue">NullValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#EnumValue" data-name="EnumValue">EnumValue</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ListValue" data-name="ListValue">ListValue</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ObjectValue" data-name="ObjectValue">ObjectValue</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span></div> </div> <div class="spec-production" id="BooleanValue" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L172"> <span class="spec-nt"><a href="#BooleanValue" data-name="BooleanValue">BooleanValue</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">true</span></td><td class="spec-rhs"><span class="spec-t">false</span></td></tr> </table></div></div> </div> <div class="spec-production" id="NullValue" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L174"> <span class="spec-nt"><a href="#NullValue" data-name="NullValue">NullValue</a></span><div class="spec-rhs"><span class="spec-t">null</span></div> </div> <div class="spec-production" id="EnumValue" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L176"> <span class="spec-nt"><a href="#EnumValue" data-name="EnumValue">EnumValue</a></span><div class="spec-rhs"><span class="spec-constrained"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-butnot"><span class="spec-t">true</span><span class="spec-t">false</span><span class="spec-t">null</span></span></span></div> </div> <div class="spec-production" id="ListValue" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L178-L180"> <span class="spec-nt"><a href="#ListValue" data-name="ListValue">ListValue</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-t">[</span><span class="spec-t">]</span></div> <div class="spec-rhs"><span class="spec-t">[</span><span class="spec-quantified"><span class="spec-nt"><a href="#Value" data-name="Value">Value</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">]</span></div> </div> <div class="spec-production" id="ObjectValue" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L182-L184"> <span class="spec-nt"><a href="#ObjectValue" data-name="ObjectValue">ObjectValue</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-t">}</span></div> <div class="spec-rhs"><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#ObjectField" data-name="ObjectField">ObjectField</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <div class="spec-production" id="ObjectField" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L186"> <span class="spec-nt"><a href="#ObjectField" data-name="ObjectField">ObjectField</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Value" data-name="Value">Value</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span></div> </div> <div class="spec-production" id="VariableDefinitions" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L188"> <span class="spec-nt"><a href="#VariableDefinitions" data-name="VariableDefinitions">VariableDefinitions</a></span><div class="spec-rhs"><span class="spec-t">(</span><span class="spec-quantified"><span class="spec-nt"><a href="#VariableDefinition" data-name="VariableDefinition">VariableDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">)</span></div> </div> <div class="spec-production" id="VariableDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L190"> <span class="spec-nt"><a href="#VariableDefinition" data-name="VariableDefinition">VariableDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Variable" data-name="Variable">Variable</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#DefaultValue" data-name="DefaultValue">DefaultValue</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="Variable" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L192"> <span class="spec-nt"><a href="#Variable" data-name="Variable">Variable</a></span><div class="spec-rhs"><span class="spec-t">$</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span></div> </div> <div class="spec-production" id="DefaultValue" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L194"> <span class="spec-nt"><a href="#DefaultValue" data-name="DefaultValue">DefaultValue</a></span><div class="spec-rhs"><span class="spec-t">=</span><span class="spec-nt"><a href="#Value" data-name="Value">Value</a><span class="spec-params"><span class="spec-param">Const</span></span></span></div> </div> <div class="spec-production" id="Type" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L196-L199"> <span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ListType" data-name="ListType">ListType</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#NonNullType" data-name="NonNullType">NonNullType</a></span></div> </div> <div class="spec-production" id="NamedType" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L201"> <span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span></div> </div> <div class="spec-production" id="ListType" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L203"> <span class="spec-nt"><a href="#ListType" data-name="ListType">ListType</a></span><div class="spec-rhs"><span class="spec-t">[</span><span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><span class="spec-t">]</span></div> </div> <div class="spec-production" id="NonNullType" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L205-L207"> <span class="spec-nt"><a href="#NonNullType" data-name="NonNullType">NonNullType</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span><span class="spec-t">!</span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ListType" data-name="ListType">ListType</a></span><span class="spec-t">!</span></div> </div> <div class="spec-production" id="Directives" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L209"> <span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Directive" data-name="Directive">Directive</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production" id="Directive" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L211"> <span class="spec-nt"><a href="#Directive" data-name="Directive">Directive</a><span class="spec-params"><span class="spec-param">Const</span></span></span><div class="spec-rhs"><span class="spec-t">@</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Arguments" data-name="Arguments">Arguments</a><span class="spec-params"><span class="spec-param conditional">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="TypeSystemDocument" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L213"> <span class="spec-nt"><a href="#TypeSystemDocument" data-name="TypeSystemDocument">TypeSystemDocument</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#TypeSystemDefinition" data-name="TypeSystemDefinition">TypeSystemDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production" id="TypeSystemDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L215-L218"> <span class="spec-nt"><a href="#TypeSystemDefinition" data-name="TypeSystemDefinition">TypeSystemDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#SchemaDefinition" data-name="SchemaDefinition">SchemaDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#TypeDefinition" data-name="TypeDefinition">TypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#DirectiveDefinition" data-name="DirectiveDefinition">DirectiveDefinition</a></span></div> </div> <div class="spec-production" id="TypeSystemExtensionDocument" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L220"> <span class="spec-nt"><a href="#TypeSystemExtensionDocument" data-name="TypeSystemExtensionDocument">TypeSystemExtensionDocument</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#TypeSystemDefinitionOrExtension" data-name="TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span></div> </div> <div class="spec-production" id="TypeSystemDefinitionOrExtension" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L222-L224"> <span class="spec-nt"><a href="#TypeSystemDefinitionOrExtension" data-name="TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#TypeSystemDefinition" data-name="TypeSystemDefinition">TypeSystemDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#TypeSystemExtension" data-name="TypeSystemExtension">TypeSystemExtension</a></span></div> </div> <div class="spec-production" id="TypeSystemExtension" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L226-L228"> <span class="spec-nt"><a href="#TypeSystemExtension" data-name="TypeSystemExtension">TypeSystemExtension</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#SchemaExtension" data-name="SchemaExtension">SchemaExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#TypeExtension" data-name="TypeExtension">TypeExtension</a></span></div> </div> <div class="spec-production" id="SchemaDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L230"> <span class="spec-nt"><a href="#SchemaDefinition" data-name="SchemaDefinition">SchemaDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">schema</span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#RootOperationTypeDefinition" data-name="RootOperationTypeDefinition">RootOperationTypeDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <div class="spec-production" id="SchemaExtension" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L232-L234"> <span class="spec-nt"><a href="#SchemaExtension" data-name="SchemaExtension">SchemaExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">schema</span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#RootOperationTypeDefinition" data-name="RootOperationTypeDefinition">RootOperationTypeDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">schema</span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="RootOperationTypeDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L236"> <span class="spec-nt"><a href="#RootOperationTypeDefinition" data-name="RootOperationTypeDefinition">RootOperationTypeDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#OperationType" data-name="OperationType">OperationType</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> </div> <div class="spec-production" id="Description" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L238"> <span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#StringValue" data-name="StringValue">StringValue</a></span></div> </div> <div class="spec-production" id="TypeDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L240-L246"> <span class="spec-nt"><a href="#TypeDefinition" data-name="TypeDefinition">TypeDefinition</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ScalarTypeDefinition" data-name="ScalarTypeDefinition">ScalarTypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ObjectTypeDefinition" data-name="ObjectTypeDefinition">ObjectTypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#InterfaceTypeDefinition" data-name="InterfaceTypeDefinition">InterfaceTypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#UnionTypeDefinition" data-name="UnionTypeDefinition">UnionTypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#EnumTypeDefinition" data-name="EnumTypeDefinition">EnumTypeDefinition</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#InputObjectTypeDefinition" data-name="InputObjectTypeDefinition">InputObjectTypeDefinition</a></span></div> </div> <div class="spec-production" id="TypeExtension" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L248-L254"> <span class="spec-nt"><a href="#TypeExtension" data-name="TypeExtension">TypeExtension</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ScalarTypeExtension" data-name="ScalarTypeExtension">ScalarTypeExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#ObjectTypeExtension" data-name="ObjectTypeExtension">ObjectTypeExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#InterfaceTypeExtension" data-name="InterfaceTypeExtension">InterfaceTypeExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#UnionTypeExtension" data-name="UnionTypeExtension">UnionTypeExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#EnumTypeExtension" data-name="EnumTypeExtension">EnumTypeExtension</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#InputObjectTypeExtension" data-name="InputObjectTypeExtension">InputObjectTypeExtension</a></span></div> </div> <div class="spec-production" id="ScalarTypeDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L256"> <span class="spec-nt"><a href="#ScalarTypeDefinition" data-name="ScalarTypeDefinition">ScalarTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">scalar</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="ScalarTypeExtension" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L258-L259"> <span class="spec-nt"><a href="#ScalarTypeExtension" data-name="ScalarTypeExtension">ScalarTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">scalar</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span></div> </div> <div class="spec-production" id="ObjectTypeDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L261-L263"> <span class="spec-nt"><a href="#ObjectTypeDefinition" data-name="ObjectTypeDefinition">ObjectTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">type</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#FieldsDefinition" data-name="FieldsDefinition">FieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">type</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="ObjectTypeExtension" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L265-L268"> <span class="spec-nt"><a href="#ObjectTypeExtension" data-name="ObjectTypeExtension">ObjectTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">type</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#FieldsDefinition" data-name="FieldsDefinition">FieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">type</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">type</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="ImplementsInterfaces" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L270-L272"> <span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-t">&</span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> <div class="spec-rhs"><span class="spec-t">implements</span><span class="spec-quantified"><span class="spec-t">&</span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> </div> <div class="spec-production" id="FieldsDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L274"> <span class="spec-nt"><a href="#FieldsDefinition" data-name="FieldsDefinition">FieldsDefinition</a></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#FieldDefinition" data-name="FieldDefinition">FieldDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <div class="spec-production" id="FieldDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L276"> <span class="spec-nt"><a href="#FieldDefinition" data-name="FieldDefinition">FieldDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ArgumentsDefinition" data-name="ArgumentsDefinition">ArgumentsDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="ArgumentsDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L278"> <span class="spec-nt"><a href="#ArgumentsDefinition" data-name="ArgumentsDefinition">ArgumentsDefinition</a></span><div class="spec-rhs"><span class="spec-t">(</span><span class="spec-quantified"><span class="spec-nt"><a href="#InputValueDefinition" data-name="InputValueDefinition">InputValueDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">)</span></div> </div> <div class="spec-production" id="InputValueDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L280"> <span class="spec-nt"><a href="#InputValueDefinition" data-name="InputValueDefinition">InputValueDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Type" data-name="Type">Type</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#DefaultValue" data-name="DefaultValue">DefaultValue</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="InterfaceTypeDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L282-L284"> <span class="spec-nt"><a href="#InterfaceTypeDefinition" data-name="InterfaceTypeDefinition">InterfaceTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">interface</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#FieldsDefinition" data-name="FieldsDefinition">FieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">interface</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="InterfaceTypeExtension" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L286-L289"> <span class="spec-nt"><a href="#InterfaceTypeExtension" data-name="InterfaceTypeExtension">InterfaceTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">interface</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#FieldsDefinition" data-name="FieldsDefinition">FieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">interface</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">interface</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#ImplementsInterfaces" data-name="ImplementsInterfaces">ImplementsInterfaces</a></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="UnionTypeDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L291"> <span class="spec-nt"><a href="#UnionTypeDefinition" data-name="UnionTypeDefinition">UnionTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">union</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-nt"><a href="#UnionMemberTypes" data-name="UnionMemberTypes">UnionMemberTypes</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="UnionMemberTypes" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L293-L295"> <span class="spec-nt"><a href="#UnionMemberTypes" data-name="UnionMemberTypes">UnionMemberTypes</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#UnionMemberTypes" data-name="UnionMemberTypes">UnionMemberTypes</a></span><span class="spec-t">|</span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> <div class="spec-rhs"><span class="spec-t">=</span><span class="spec-quantified"><span class="spec-t">|</span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#NamedType" data-name="NamedType">NamedType</a></span></div> </div> <div class="spec-production" id="UnionTypeExtension" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L297-L299"> <span class="spec-nt"><a href="#UnionTypeExtension" data-name="UnionTypeExtension">UnionTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">union</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#UnionMemberTypes" data-name="UnionMemberTypes">UnionMemberTypes</a></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">union</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span></div> </div> <div class="spec-production" id="EnumTypeDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L301-L303"> <span class="spec-nt"><a href="#EnumTypeDefinition" data-name="EnumTypeDefinition">EnumTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">enum</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#EnumValuesDefinition" data-name="EnumValuesDefinition">EnumValuesDefinition</a></span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">enum</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="EnumValuesDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L305"> <span class="spec-nt"><a href="#EnumValuesDefinition" data-name="EnumValuesDefinition">EnumValuesDefinition</a></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#EnumValueDefinition" data-name="EnumValueDefinition">EnumValueDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <div class="spec-production" id="EnumValueDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L307"> <span class="spec-nt"><a href="#EnumValueDefinition" data-name="EnumValueDefinition">EnumValueDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#EnumValue" data-name="EnumValue">EnumValue</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span></div> </div> <div class="spec-production" id="EnumTypeExtension" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L309-L311"> <span class="spec-nt"><a href="#EnumTypeExtension" data-name="EnumTypeExtension">EnumTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">enum</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#EnumValuesDefinition" data-name="EnumValuesDefinition">EnumValuesDefinition</a></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">enum</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="InputObjectTypeDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L313-L315"> <span class="spec-nt"><a href="#InputObjectTypeDefinition" data-name="InputObjectTypeDefinition">InputObjectTypeDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">input</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#InputFieldsDefinition" data-name="InputFieldsDefinition">InputFieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">input</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="InputFieldsDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L317"> <span class="spec-nt"><a href="#InputFieldsDefinition" data-name="InputFieldsDefinition">InputFieldsDefinition</a></span><div class="spec-rhs"><span class="spec-t">{</span><span class="spec-quantified"><span class="spec-nt"><a href="#InputValueDefinition" data-name="InputValueDefinition">InputValueDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier list">list</span></span></span><span class="spec-t">}</span></div> </div> <div class="spec-production" id="InputObjectTypeExtension" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L319-L321"> <span class="spec-nt"><a href="#InputObjectTypeExtension" data-name="InputObjectTypeExtension">InputObjectTypeExtension</a></span><div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">input</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#InputFieldsDefinition" data-name="InputFieldsDefinition">InputFieldsDefinition</a></span></div> <div class="spec-rhs"><span class="spec-t">extend</span><span class="spec-t">input</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-nt"><a href="#Directives" data-name="Directives">Directives</a><span class="spec-params"><span class="spec-param">Const</span></span></span><span class="spec-lookahead not"><span class="spec-t">{</span></span></div> </div> <div class="spec-production" id="DirectiveDefinition" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L323"> <span class="spec-nt"><a href="#DirectiveDefinition" data-name="DirectiveDefinition">DirectiveDefinition</a></span><div class="spec-rhs"><span class="spec-quantified"><span class="spec-nt"><a href="#Description" data-name="Description">Description</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">directive</span><span class="spec-t">@</span><span class="spec-nt"><a href="#Name" data-name="Name">Name</a></span><span class="spec-quantified"><span class="spec-nt"><a href="#ArgumentsDefinition" data-name="ArgumentsDefinition">ArgumentsDefinition</a></span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-quantified"><span class="spec-t">repeatable</span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-t">on</span><span class="spec-nt"><a href="#DirectiveLocations" data-name="DirectiveLocations">DirectiveLocations</a></span></div> </div> <div class="spec-production" id="DirectiveLocations" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L325-L327"> <span class="spec-nt"><a href="#DirectiveLocations" data-name="DirectiveLocations">DirectiveLocations</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#DirectiveLocations" data-name="DirectiveLocations">DirectiveLocations</a></span><span class="spec-t">|</span><span class="spec-nt"><a href="#DirectiveLocation" data-name="DirectiveLocation">DirectiveLocation</a></span></div> <div class="spec-rhs"><span class="spec-quantified"><span class="spec-t">|</span><span class="spec-quantifiers"><span class="spec-quantifier optional">opt</span></span></span><span class="spec-nt"><a href="#DirectiveLocation" data-name="DirectiveLocation">DirectiveLocation</a></span></div> </div> <div class="spec-production" id="DirectiveLocation" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L329-L331"> <span class="spec-nt"><a href="#DirectiveLocation" data-name="DirectiveLocation">DirectiveLocation</a></span><div class="spec-rhs"><span class="spec-nt"><a href="#ExecutableDirectiveLocation" data-name="ExecutableDirectiveLocation">ExecutableDirectiveLocation</a></span></div> <div class="spec-rhs"><span class="spec-nt"><a href="#TypeSystemDirectiveLocation" data-name="TypeSystemDirectiveLocation">TypeSystemDirectiveLocation</a></span></div> </div> <div class="spec-production" id="ExecutableDirectiveLocation" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L333-L341"> <span class="spec-nt"><a href="#ExecutableDirectiveLocation" data-name="ExecutableDirectiveLocation">ExecutableDirectiveLocation</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">QUERY</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">MUTATION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">SUBSCRIPTION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">FIELD</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">FRAGMENT_DEFINITION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">FRAGMENT_SPREAD</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">INLINE_FRAGMENT</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">VARIABLE_DEFINITION</span></td></tr> </table></div></div> </div> <div class="spec-production" id="TypeSystemDirectiveLocation" data-source="spec/Appendix%20B%20--%20Grammar%20Summary.md#L343-L354"> <span class="spec-nt"><a href="#TypeSystemDirectiveLocation" data-name="TypeSystemDirectiveLocation">TypeSystemDirectiveLocation</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table> <tr> <td class="spec-rhs"><span class="spec-t">SCHEMA</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">SCALAR</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">OBJECT</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">FIELD_DEFINITION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">ARGUMENT_DEFINITION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">INTERFACE</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">UNION</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">ENUM</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">ENUM_VALUE</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">INPUT_OBJECT</span></td></tr> <tr> <td class="spec-rhs"><span class="spec-t">INPUT_FIELD_DEFINITION</span></td></tr> </table></div></div> </div> </section> </section> <section id="index" secid="index" class="spec-index"> <h1> <span class="spec-secid" title="link to the index"><a href="#index">§</a></span>Index</h1> <ol> <li><a href="#Alias">Alias</a></li> <li><a href="#AreTypesCompatible()">AreTypesCompatible</a></li> <li><a href="#Argument">Argument</a></li> <li><a href="#Arguments">Arguments</a></li> <li><a href="#ArgumentsDefinition">ArgumentsDefinition</a></li> <li><a href="#BlockStringCharacter">BlockStringCharacter</a></li> <li><a href="#BlockStringValue()">BlockStringValue</a></li> <li><a href="#BooleanValue">BooleanValue</a></li> <li><a href="#built-in-directive">built-in directive</a></li> <li><a href="#CoerceArgumentValues()">CoerceArgumentValues</a></li> <li><a href="#CoerceResult()">CoerceResult</a></li> <li><a href="#CoerceVariableValues()">CoerceVariableValues</a></li> <li><a href="#CollectFields()">CollectFields</a></li> <li><a href="#Comma">Comma</a></li> <li><a href="#Comment">Comment</a></li> <li><a href="#CommentChar">CommentChar</a></li> <li><a href="#CompleteValue()">CompleteValue</a></li> <li><a href="#CreateSourceEventStream()">CreateSourceEventStream</a></li> <li><a href="#custom-directive">custom directive</a></li> <li><a href="#DefaultValue">DefaultValue</a></li> <li><a href="#Definition">Definition</a></li> <li><a href="#Description">Description</a></li> <li><a href="#DetectFragmentCycles()">DetectFragmentCycles</a></li> <li><a href="#Digit">Digit</a></li> <li><a href="#Directive">Directive</a></li> <li><a href="#DirectiveDefinition">DirectiveDefinition</a></li> <li><a href="#DirectiveLocation">DirectiveLocation</a></li> <li><a href="#DirectiveLocations">DirectiveLocations</a></li> <li><a href="#Directives">Directives</a></li> <li><a href="#Document">Document</a></li> <li><a href="#DoesFragmentTypeApply()">DoesFragmentTypeApply</a></li> <li><a href="#EnumTypeDefinition">EnumTypeDefinition</a></li> <li><a href="#EnumTypeExtension">EnumTypeExtension</a></li> <li><a href="#EnumValue">EnumValue</a></li> <li><a href="#EnumValueDefinition">EnumValueDefinition</a></li> <li><a href="#EnumValuesDefinition">EnumValuesDefinition</a></li> <li><a href="#EscapedCharacter">EscapedCharacter</a></li> <li><a href="#EscapedUnicode">EscapedUnicode</a></li> <li><a href="#ExecutableDefinition">ExecutableDefinition</a></li> <li><a href="#ExecutableDirectiveLocation">ExecutableDirectiveLocation</a></li> <li><a href="#ExecutableDocument">ExecutableDocument</a></li> <li><a href="#ExecuteField()">ExecuteField</a></li> <li><a href="#ExecuteMutation()">ExecuteMutation</a></li> <li><a href="#ExecuteQuery()">ExecuteQuery</a></li> <li><a href="#ExecuteRequest()">ExecuteRequest</a></li> <li><a href="#ExecuteSelectionSet()">ExecuteSelectionSet</a></li> <li><a href="#ExecuteSubscriptionEvent()">ExecuteSubscriptionEvent</a></li> <li><a href="#ExponentIndicator">ExponentIndicator</a></li> <li><a href="#ExponentPart">ExponentPart</a></li> <li><a href="#Field">Field</a></li> <li><a href="#FieldDefinition">FieldDefinition</a></li> <li><a href="#FieldsDefinition">FieldsDefinition</a></li> <li><a href="#FieldsInSetCanMerge()">FieldsInSetCanMerge</a></li> <li><a href="#FloatValue">FloatValue</a></li> <li><a href="#FractionalPart">FractionalPart</a></li> <li><a href="#FragmentDefinition">FragmentDefinition</a></li> <li><a href="#FragmentName">FragmentName</a></li> <li><a href="#FragmentSpread">FragmentSpread</a></li> <li><a href="#GetOperation()">GetOperation</a></li> <li><a href="#GetPossibleTypes()">GetPossibleTypes</a></li> <li><a href="#Ignored">Ignored</a></li> <li><a href="#ImplementsInterfaces">ImplementsInterfaces</a></li> <li><a href="#InlineFragment">InlineFragment</a></li> <li><a href="#InputFieldsDefinition">InputFieldsDefinition</a></li> <li><a href="#InputObjectTypeDefinition">InputObjectTypeDefinition</a></li> <li><a href="#InputObjectTypeExtension">InputObjectTypeExtension</a></li> <li><a href="#InputValueDefinition">InputValueDefinition</a></li> <li><a href="#IntegerPart">IntegerPart</a></li> <li><a href="#InterfaceTypeDefinition">InterfaceTypeDefinition</a></li> <li><a href="#InterfaceTypeExtension">InterfaceTypeExtension</a></li> <li><a href="#IntValue">IntValue</a></li> <li><a href="#IsInputType()">IsInputType</a></li> <li><a href="#IsOutputType()">IsOutputType</a></li> <li><a href="#IsValidImplementation()">IsValidImplementation</a></li> <li><a href="#IsValidImplementationFieldType()">IsValidImplementationFieldType</a></li> <li><a href="#IsVariableUsageAllowed()">IsVariableUsageAllowed</a></li> <li><a href="#Letter">Letter</a></li> <li><a href="#LineTerminator">LineTerminator</a></li> <li><a href="#ListType">ListType</a></li> <li><a href="#ListValue">ListValue</a></li> <li><a href="#MapSourceToResponseEvent()">MapSourceToResponseEvent</a></li> <li><a href="#MergeSelectionSets()">MergeSelectionSets</a></li> <li><a href="#Name">Name</a></li> <li><a href="#NameContinue">NameContinue</a></li> <li><a href="#NamedType">NamedType</a></li> <li><a href="#NameStart">NameStart</a></li> <li><a href="#NegativeSign">NegativeSign</a></li> <li><a href="#NonNullType">NonNullType</a></li> <li><a href="#NonZeroDigit">NonZeroDigit</a></li> <li><a href="#NullValue">NullValue</a></li> <li><a href="#ObjectField">ObjectField</a></li> <li><a href="#ObjectTypeDefinition">ObjectTypeDefinition</a></li> <li><a href="#ObjectTypeExtension">ObjectTypeExtension</a></li> <li><a href="#ObjectValue">ObjectValue</a></li> <li><a href="#OperationDefinition">OperationDefinition</a></li> <li><a href="#OperationType">OperationType</a></li> <li><a href="#Punctuator">Punctuator</a></li> <li><a href="#ResolveAbstractType()">ResolveAbstractType</a></li> <li><a href="#ResolveFieldEventStream()">ResolveFieldEventStream</a></li> <li><a href="#ResolveFieldValue()">ResolveFieldValue</a></li> <li><a href="#RootOperationTypeDefinition">RootOperationTypeDefinition</a></li> <li><a href="#SameResponseShape()">SameResponseShape</a></li> <li><a href="#scalar-specification-url">scalar specification URL</a></li> <li><a href="#ScalarTypeDefinition">ScalarTypeDefinition</a></li> <li><a href="#ScalarTypeExtension">ScalarTypeExtension</a></li> <li><a href="#SchemaDefinition">SchemaDefinition</a></li> <li><a href="#SchemaExtension">SchemaExtension</a></li> <li><a href="#Selection">Selection</a></li> <li><a href="#SelectionSet">SelectionSet</a></li> <li><a href="#Sign">Sign</a></li> <li><a href="#SourceCharacter">SourceCharacter</a></li> <li><a href="#StringCharacter">StringCharacter</a></li> <li><a href="#StringValue">StringValue</a></li> <li><a href="#Subscribe()">Subscribe</a></li> <li><a href="#Token">Token</a></li> <li><a href="#Type">Type</a></li> <li><a href="#TypeCondition">TypeCondition</a></li> <li><a href="#TypeDefinition">TypeDefinition</a></li> <li><a href="#TypeExtension">TypeExtension</a></li> <li><a href="#TypeSystemDefinition">TypeSystemDefinition</a></li> <li><a href="#TypeSystemDefinitionOrExtension">TypeSystemDefinitionOrExtension</a></li> <li><a href="#TypeSystemDirectiveLocation">TypeSystemDirectiveLocation</a></li> <li><a href="#TypeSystemDocument">TypeSystemDocument</a></li> <li><a href="#TypeSystemExtension">TypeSystemExtension</a></li> <li><a href="#TypeSystemExtensionDocument">TypeSystemExtensionDocument</a></li> <li><a href="#UnicodeBOM">UnicodeBOM</a></li> <li><a href="#UnionMemberTypes">UnionMemberTypes</a></li> <li><a href="#UnionTypeDefinition">UnionTypeDefinition</a></li> <li><a href="#UnionTypeExtension">UnionTypeExtension</a></li> <li><a href="#Unsubscribe()">Unsubscribe</a></li> <li><a href="#Value">Value</a></li> <li><a href="#Variable">Variable</a></li> <li><a href="#VariableDefinition">VariableDefinition</a></li> <li><a href="#VariableDefinitions">VariableDefinitions</a></li> <li><a href="#WhiteSpace">WhiteSpace</a></li> </ol> </section> </article> <footer> Written in <a href="https://spec-md.com" target="_blank">Spec Markdown</a>.</footer> <input hidden class="spec-sidebar-toggle" type="checkbox" id="spec-sidebar-toggle" aria-hidden /><label for="spec-sidebar-toggle" aria-hidden><div class="spec-sidebar-button">☰</div></label> <div class="spec-sidebar" aria-hidden> <div class="spec-toc"> <div class="title"><a href="#">GraphQL</a></div> <ol><li id="_sidebar_1"><a href="#sec-Overview"><span class="spec-secid">1</span>Overview</a></li> <li id="_sidebar_2"><a href="#sec-Language"><span class="spec-secid">2</span>Language</a> <input hidden class="toggle" type="checkbox" id="_toggle_2" /><label for="_toggle_2"></label> <ol> <li id="_sidebar_2.1"><a href="#sec-Language.Source-Text"><span class="spec-secid">2.1</span>Source Text</a> <input hidden class="toggle" type="checkbox" id="_toggle_2.1" /><label for="_toggle_2.1"></label> <ol> <li id="_sidebar_2.1.1"><a href="#sec-Unicode"><span class="spec-secid">2.1.1</span>Unicode</a></li> <li id="_sidebar_2.1.2"><a href="#sec-White-Space"><span class="spec-secid">2.1.2</span>White Space</a></li> <li id="_sidebar_2.1.3"><a href="#sec-Line-Terminators"><span class="spec-secid">2.1.3</span>Line Terminators</a></li> <li id="_sidebar_2.1.4"><a href="#sec-Comments"><span class="spec-secid">2.1.4</span>Comments</a></li> <li id="_sidebar_2.1.5"><a href="#sec-Insignificant-Commas"><span class="spec-secid">2.1.5</span>Insignificant Commas</a></li> <li id="_sidebar_2.1.6"><a href="#sec-Language.Source-Text.Lexical-Tokens"><span class="spec-secid">2.1.6</span>Lexical Tokens</a></li> <li id="_sidebar_2.1.7"><a href="#sec-Language.Source-Text.Ignored-Tokens"><span class="spec-secid">2.1.7</span>Ignored Tokens</a></li> <li id="_sidebar_2.1.8"><a href="#sec-Punctuators"><span class="spec-secid">2.1.8</span>Punctuators</a></li> <li id="_sidebar_2.1.9"><a href="#sec-Names"><span class="spec-secid">2.1.9</span>Names</a></li> </ol> </li> <li id="_sidebar_2.2"><a href="#sec-Document"><span class="spec-secid">2.2</span>Document</a></li> <li id="_sidebar_2.3"><a href="#sec-Language.Operations"><span class="spec-secid">2.3</span>Operations</a></li> <li id="_sidebar_2.4"><a href="#sec-Selection-Sets"><span class="spec-secid">2.4</span>Selection Sets</a></li> <li id="_sidebar_2.5"><a href="#sec-Language.Fields"><span class="spec-secid">2.5</span>Fields</a></li> <li id="_sidebar_2.6"><a href="#sec-Language.Arguments"><span class="spec-secid">2.6</span>Arguments</a></li> <li id="_sidebar_2.7"><a href="#sec-Field-Alias"><span class="spec-secid">2.7</span>Field Alias</a></li> <li id="_sidebar_2.8"><a href="#sec-Language.Fragments"><span class="spec-secid">2.8</span>Fragments</a> <input hidden class="toggle" type="checkbox" id="_toggle_2.8" /><label for="_toggle_2.8"></label> <ol> <li id="_sidebar_2.8.1"><a href="#sec-Type-Conditions"><span class="spec-secid">2.8.1</span>Type Conditions</a></li> <li id="_sidebar_2.8.2"><a href="#sec-Inline-Fragments"><span class="spec-secid">2.8.2</span>Inline Fragments</a></li> </ol> </li> <li id="_sidebar_2.9"><a href="#sec-Input-Values"><span class="spec-secid">2.9</span>Input Values</a> <input hidden class="toggle" type="checkbox" id="_toggle_2.9" /><label for="_toggle_2.9"></label> <ol> <li id="_sidebar_2.9.1"><a href="#sec-Int-Value"><span class="spec-secid">2.9.1</span>Int Value</a></li> <li id="_sidebar_2.9.2"><a href="#sec-Float-Value"><span class="spec-secid">2.9.2</span>Float Value</a></li> <li id="_sidebar_2.9.3"><a href="#sec-Boolean-Value"><span class="spec-secid">2.9.3</span>Boolean Value</a></li> <li id="_sidebar_2.9.4"><a href="#sec-String-Value"><span class="spec-secid">2.9.4</span>String Value</a></li> <li id="_sidebar_2.9.5"><a href="#sec-Null-Value"><span class="spec-secid">2.9.5</span>Null Value</a></li> <li id="_sidebar_2.9.6"><a href="#sec-Enum-Value"><span class="spec-secid">2.9.6</span>Enum Value</a></li> <li id="_sidebar_2.9.7"><a href="#sec-List-Value"><span class="spec-secid">2.9.7</span>List Value</a></li> <li id="_sidebar_2.9.8"><a href="#sec-Input-Object-Values"><span class="spec-secid">2.9.8</span>Input Object Values</a></li> </ol> </li> <li id="_sidebar_2.10"><a href="#sec-Language.Variables"><span class="spec-secid">2.10</span>Variables</a></li> <li id="_sidebar_2.11"><a href="#sec-Type-References"><span class="spec-secid">2.11</span>Type References</a></li> <li id="_sidebar_2.12"><a href="#sec-Language.Directives"><span class="spec-secid">2.12</span>Directives</a></li> </ol> </li> <li id="_sidebar_3"><a href="#sec-Type-System"><span class="spec-secid">3</span>Type System</a> <input hidden class="toggle" type="checkbox" id="_toggle_3" /><label for="_toggle_3"></label> <ol> <li id="_sidebar_3.1"><a href="#sec-Type-System-Extensions"><span class="spec-secid">3.1</span>Type System Extensions</a></li> <li id="_sidebar_3.2"><a href="#sec-Descriptions"><span class="spec-secid">3.2</span>Descriptions</a></li> <li id="_sidebar_3.3"><a href="#sec-Schema"><span class="spec-secid">3.3</span>Schema</a> <input hidden class="toggle" type="checkbox" id="_toggle_3.3" /><label for="_toggle_3.3"></label> <ol> <li id="_sidebar_3.3.1"><a href="#sec-Root-Operation-Types"><span class="spec-secid">3.3.1</span>Root Operation Types</a></li> <li id="_sidebar_3.3.2"><a href="#sec-Schema-Extension"><span class="spec-secid">3.3.2</span>Schema Extension</a></li> </ol> </li> <li id="_sidebar_3.4"><a href="#sec-Types"><span class="spec-secid">3.4</span>Types</a> <input hidden class="toggle" type="checkbox" id="_toggle_3.4" /><label for="_toggle_3.4"></label> <ol> <li id="_sidebar_3.4.1"><a href="#sec-Wrapping-Types"><span class="spec-secid">3.4.1</span>Wrapping Types</a></li> <li id="_sidebar_3.4.2"><a href="#sec-Input-and-Output-Types"><span class="spec-secid">3.4.2</span>Input and Output Types</a></li> <li id="_sidebar_3.4.3"><a href="#sec-Type-Extensions"><span class="spec-secid">3.4.3</span>Type Extensions</a></li> </ol> </li> <li id="_sidebar_3.5"><a href="#sec-Scalars"><span class="spec-secid">3.5</span>Scalars</a> <input hidden class="toggle" type="checkbox" id="_toggle_3.5" /><label for="_toggle_3.5"></label> <ol> <li id="_sidebar_3.5.1"><a href="#sec-Int"><span class="spec-secid">3.5.1</span>Int</a></li> <li id="_sidebar_3.5.2"><a href="#sec-Float"><span class="spec-secid">3.5.2</span>Float</a></li> <li id="_sidebar_3.5.3"><a href="#sec-String"><span class="spec-secid">3.5.3</span>String</a></li> <li id="_sidebar_3.5.4"><a href="#sec-Boolean"><span class="spec-secid">3.5.4</span>Boolean</a></li> <li id="_sidebar_3.5.5"><a href="#sec-ID"><span class="spec-secid">3.5.5</span>ID</a></li> <li id="_sidebar_3.5.6"><a href="#sec-Scalar-Extensions"><span class="spec-secid">3.5.6</span>Scalar Extensions</a></li> </ol> </li> <li id="_sidebar_3.6"><a href="#sec-Objects"><span class="spec-secid">3.6</span>Objects</a> <input hidden class="toggle" type="checkbox" id="_toggle_3.6" /><label for="_toggle_3.6"></label> <ol> <li id="_sidebar_3.6.1"><a href="#sec-Field-Arguments"><span class="spec-secid">3.6.1</span>Field Arguments</a></li> <li id="_sidebar_3.6.2"><a href="#sec-Field-Deprecation"><span class="spec-secid">3.6.2</span>Field Deprecation</a></li> <li id="_sidebar_3.6.3"><a href="#sec-Object-Extensions"><span class="spec-secid">3.6.3</span>Object Extensions</a></li> </ol> </li> <li id="_sidebar_3.7"><a href="#sec-Interfaces"><span class="spec-secid">3.7</span>Interfaces</a> <input hidden class="toggle" type="checkbox" id="_toggle_3.7" /><label for="_toggle_3.7"></label> <ol> <li id="_sidebar_3.7.1"><a href="#sec-Interface-Extensions"><span class="spec-secid">3.7.1</span>Interface Extensions</a></li> </ol> </li> <li id="_sidebar_3.8"><a href="#sec-Unions"><span class="spec-secid">3.8</span>Unions</a> <input hidden class="toggle" type="checkbox" id="_toggle_3.8" /><label for="_toggle_3.8"></label> <ol> <li id="_sidebar_3.8.1"><a href="#sec-Union-Extensions"><span class="spec-secid">3.8.1</span>Union Extensions</a></li> </ol> </li> <li id="_sidebar_3.9"><a href="#sec-Enums"><span class="spec-secid">3.9</span>Enums</a> <input hidden class="toggle" type="checkbox" id="_toggle_3.9" /><label for="_toggle_3.9"></label> <ol> <li id="_sidebar_3.9.1"><a href="#sec-Enum-Extensions"><span class="spec-secid">3.9.1</span>Enum Extensions</a></li> </ol> </li> <li id="_sidebar_3.10"><a href="#sec-Input-Objects"><span class="spec-secid">3.10</span>Input Objects</a> <input hidden class="toggle" type="checkbox" id="_toggle_3.10" /><label for="_toggle_3.10"></label> <ol> <li id="_sidebar_3.10.1"><a href="#sec-Input-Object-Extensions"><span class="spec-secid">3.10.1</span>Input Object Extensions</a></li> </ol> </li> <li id="_sidebar_3.11"><a href="#sec-List"><span class="spec-secid">3.11</span>List</a></li> <li id="_sidebar_3.12"><a href="#sec-Non-Null"><span class="spec-secid">3.12</span>Non-Null</a> <input hidden class="toggle" type="checkbox" id="_toggle_3.12" /><label for="_toggle_3.12"></label> <ol> <li id="_sidebar_3.12.1"><a href="#sec-Combining-List-and-Non-Null"><span class="spec-secid">3.12.1</span>Combining List and Non-Null</a></li> </ol> </li> <li id="_sidebar_3.13"><a href="#sec-Type-System.Directives"><span class="spec-secid">3.13</span>Directives</a> <input hidden class="toggle" type="checkbox" id="_toggle_3.13" /><label for="_toggle_3.13"></label> <ol> <li id="_sidebar_3.13.1"><a href="#sec--skip"><span class="spec-secid">3.13.1</span>@skip</a></li> <li id="_sidebar_3.13.2"><a href="#sec--include"><span class="spec-secid">3.13.2</span>@include</a></li> <li id="_sidebar_3.13.3"><a href="#sec--deprecated"><span class="spec-secid">3.13.3</span>@deprecated</a></li> <li id="_sidebar_3.13.4"><a href="#sec--specifiedBy"><span class="spec-secid">3.13.4</span>@specifiedBy</a></li> </ol> </li> </ol> </li> <li id="_sidebar_4"><a href="#sec-Introspection"><span class="spec-secid">4</span>Introspection</a> <input hidden class="toggle" type="checkbox" id="_toggle_4" /><label for="_toggle_4"></label> <ol> <li id="_sidebar_4.1"><a href="#sec-Type-Name-Introspection"><span class="spec-secid">4.1</span>Type Name Introspection</a></li> <li id="_sidebar_4.2"><a href="#sec-Schema-Introspection"><span class="spec-secid">4.2</span>Schema Introspection</a> <input hidden class="toggle" type="checkbox" id="_toggle_4.2" /><label for="_toggle_4.2"></label> <ol> <li id="_sidebar_4.2.1"><a href="#sec-The-__Schema-Type"><span class="spec-secid">4.2.1</span>The __Schema Type</a></li> <li id="_sidebar_4.2.2"><a href="#sec-The-__Type-Type"><span class="spec-secid">4.2.2</span>The __Type Type</a></li> <li id="_sidebar_4.2.3"><a href="#sec-The-__Field-Type"><span class="spec-secid">4.2.3</span>The __Field Type</a></li> <li id="_sidebar_4.2.4"><a href="#sec-The-__InputValue-Type"><span class="spec-secid">4.2.4</span>The __InputValue Type</a></li> <li id="_sidebar_4.2.5"><a href="#sec-The-__EnumValue-Type"><span class="spec-secid">4.2.5</span>The __EnumValue Type</a></li> <li id="_sidebar_4.2.6"><a href="#sec-The-__Directive-Type"><span class="spec-secid">4.2.6</span>The __Directive Type</a></li> </ol> </li> </ol> </li> <li id="_sidebar_5"><a href="#sec-Validation"><span class="spec-secid">5</span>Validation</a> <input hidden class="toggle" type="checkbox" id="_toggle_5" /><label for="_toggle_5"></label> <ol> <li id="_sidebar_5.1"><a href="#sec-Documents"><span class="spec-secid">5.1</span>Documents</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.1" /><label for="_toggle_5.1"></label> <ol> <li id="_sidebar_5.1.1"><a href="#sec-Executable-Definitions"><span class="spec-secid">5.1.1</span>Executable Definitions</a></li> </ol> </li> <li id="_sidebar_5.2"><a href="#sec-Validation.Operations"><span class="spec-secid">5.2</span>Operations</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.2" /><label for="_toggle_5.2"></label> <ol> <li id="_sidebar_5.2.1"><a href="#sec-Named-Operation-Definitions"><span class="spec-secid">5.2.1</span>Named Operation Definitions</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.2.1" /><label for="_toggle_5.2.1"></label> <ol> <li id="_sidebar_5.2.1.1"><a href="#sec-Operation-Name-Uniqueness"><span class="spec-secid">5.2.1.1</span>Operation Name Uniqueness</a></li> </ol> </li> <li id="_sidebar_5.2.2"><a href="#sec-Anonymous-Operation-Definitions"><span class="spec-secid">5.2.2</span>Anonymous Operation Definitions</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.2.2" /><label for="_toggle_5.2.2"></label> <ol> <li id="_sidebar_5.2.2.1"><a href="#sec-Lone-Anonymous-Operation"><span class="spec-secid">5.2.2.1</span>Lone Anonymous Operation</a></li> </ol> </li> <li id="_sidebar_5.2.3"><a href="#sec-Subscription-Operation-Definitions"><span class="spec-secid">5.2.3</span>Subscription Operation Definitions</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.2.3" /><label for="_toggle_5.2.3"></label> <ol> <li id="_sidebar_5.2.3.1"><a href="#sec-Single-root-field"><span class="spec-secid">5.2.3.1</span>Single root field</a></li> </ol> </li> </ol> </li> <li id="_sidebar_5.3"><a href="#sec-Validation.Fields"><span class="spec-secid">5.3</span>Fields</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.3" /><label for="_toggle_5.3"></label> <ol> <li id="_sidebar_5.3.1"><a href="#sec-Field-Selections"><span class="spec-secid">5.3.1</span>Field Selections</a></li> <li id="_sidebar_5.3.2"><a href="#sec-Field-Selection-Merging"><span class="spec-secid">5.3.2</span>Field Selection Merging</a></li> <li id="_sidebar_5.3.3"><a href="#sec-Leaf-Field-Selections"><span class="spec-secid">5.3.3</span>Leaf Field Selections</a></li> </ol> </li> <li id="_sidebar_5.4"><a href="#sec-Validation.Arguments"><span class="spec-secid">5.4</span>Arguments</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.4" /><label for="_toggle_5.4"></label> <ol> <li id="_sidebar_5.4.1"><a href="#sec-Argument-Names"><span class="spec-secid">5.4.1</span>Argument Names</a></li> <li id="_sidebar_5.4.2"><a href="#sec-Argument-Uniqueness"><span class="spec-secid">5.4.2</span>Argument Uniqueness</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.4.2" /><label for="_toggle_5.4.2"></label> <ol> <li id="_sidebar_5.4.2.1"><a href="#sec-Required-Arguments"><span class="spec-secid">5.4.2.1</span>Required Arguments</a></li> </ol> </li> </ol> </li> <li id="_sidebar_5.5"><a href="#sec-Validation.Fragments"><span class="spec-secid">5.5</span>Fragments</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.5" /><label for="_toggle_5.5"></label> <ol> <li id="_sidebar_5.5.1"><a href="#sec-Fragment-Declarations"><span class="spec-secid">5.5.1</span>Fragment Declarations</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.5.1" /><label for="_toggle_5.5.1"></label> <ol> <li id="_sidebar_5.5.1.1"><a href="#sec-Fragment-Name-Uniqueness"><span class="spec-secid">5.5.1.1</span>Fragment Name Uniqueness</a></li> <li id="_sidebar_5.5.1.2"><a href="#sec-Fragment-Spread-Type-Existence"><span class="spec-secid">5.5.1.2</span>Fragment Spread Type Existence</a></li> <li id="_sidebar_5.5.1.3"><a href="#sec-Fragments-On-Composite-Types"><span class="spec-secid">5.5.1.3</span>Fragments On Composite Types</a></li> <li id="_sidebar_5.5.1.4"><a href="#sec-Fragments-Must-Be-Used"><span class="spec-secid">5.5.1.4</span>Fragments Must Be Used</a></li> </ol> </li> <li id="_sidebar_5.5.2"><a href="#sec-Fragment-Spreads"><span class="spec-secid">5.5.2</span>Fragment Spreads</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.5.2" /><label for="_toggle_5.5.2"></label> <ol> <li id="_sidebar_5.5.2.1"><a href="#sec-Fragment-spread-target-defined"><span class="spec-secid">5.5.2.1</span>Fragment spread target defined</a></li> <li id="_sidebar_5.5.2.2"><a href="#sec-Fragment-spreads-must-not-form-cycles"><span class="spec-secid">5.5.2.2</span>Fragment spreads must not form cycles</a></li> <li id="_sidebar_5.5.2.3"><a href="#sec-Fragment-spread-is-possible"><span class="spec-secid">5.5.2.3</span>Fragment spread is possible</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.5.2.3" /><label for="_toggle_5.5.2.3"></label> <ol> <li id="_sidebar_5.5.2.3.1"><a href="#sec-Object-Spreads-In-Object-Scope"><span class="spec-secid">5.5.2.3.1</span>Object Spreads In Object Scope</a></li> <li id="_sidebar_5.5.2.3.2"><a href="#sec-Abstract-Spreads-in-Object-Scope"><span class="spec-secid">5.5.2.3.2</span>Abstract Spreads in Object Scope</a></li> <li id="_sidebar_5.5.2.3.3"><a href="#sec-Object-Spreads-In-Abstract-Scope"><span class="spec-secid">5.5.2.3.3</span>Object Spreads In Abstract Scope</a></li> <li id="_sidebar_5.5.2.3.4"><a href="#sec-Abstract-Spreads-in-Abstract-Scope"><span class="spec-secid">5.5.2.3.4</span>Abstract Spreads in Abstract Scope</a></li> </ol> </li> </ol> </li> </ol> </li> <li id="_sidebar_5.6"><a href="#sec-Values"><span class="spec-secid">5.6</span>Values</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.6" /><label for="_toggle_5.6"></label> <ol> <li id="_sidebar_5.6.1"><a href="#sec-Values-of-Correct-Type"><span class="spec-secid">5.6.1</span>Values of Correct Type</a></li> <li id="_sidebar_5.6.2"><a href="#sec-Input-Object-Field-Names"><span class="spec-secid">5.6.2</span>Input Object Field Names</a></li> <li id="_sidebar_5.6.3"><a href="#sec-Input-Object-Field-Uniqueness"><span class="spec-secid">5.6.3</span>Input Object Field Uniqueness</a></li> <li id="_sidebar_5.6.4"><a href="#sec-Input-Object-Required-Fields"><span class="spec-secid">5.6.4</span>Input Object Required Fields</a></li> </ol> </li> <li id="_sidebar_5.7"><a href="#sec-Validation.Directives"><span class="spec-secid">5.7</span>Directives</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.7" /><label for="_toggle_5.7"></label> <ol> <li id="_sidebar_5.7.1"><a href="#sec-Directives-Are-Defined"><span class="spec-secid">5.7.1</span>Directives Are Defined</a></li> <li id="_sidebar_5.7.2"><a href="#sec-Directives-Are-In-Valid-Locations"><span class="spec-secid">5.7.2</span>Directives Are In Valid Locations</a></li> <li id="_sidebar_5.7.3"><a href="#sec-Directives-Are-Unique-Per-Location"><span class="spec-secid">5.7.3</span>Directives Are Unique Per Location</a></li> </ol> </li> <li id="_sidebar_5.8"><a href="#sec-Validation.Variables"><span class="spec-secid">5.8</span>Variables</a> <input hidden class="toggle" type="checkbox" id="_toggle_5.8" /><label for="_toggle_5.8"></label> <ol> <li id="_sidebar_5.8.1"><a href="#sec-Variable-Uniqueness"><span class="spec-secid">5.8.1</span>Variable Uniqueness</a></li> <li id="_sidebar_5.8.2"><a href="#sec-Variables-Are-Input-Types"><span class="spec-secid">5.8.2</span>Variables Are Input Types</a></li> <li id="_sidebar_5.8.3"><a href="#sec-All-Variable-Uses-Defined"><span class="spec-secid">5.8.3</span>All Variable Uses Defined</a></li> <li id="_sidebar_5.8.4"><a href="#sec-All-Variables-Used"><span class="spec-secid">5.8.4</span>All Variables Used</a></li> <li id="_sidebar_5.8.5"><a href="#sec-All-Variable-Usages-are-Allowed"><span class="spec-secid">5.8.5</span>All Variable Usages are Allowed</a></li> </ol> </li> </ol> </li> <li id="_sidebar_6"><a href="#sec-Execution"><span class="spec-secid">6</span>Execution</a> <input hidden class="toggle" type="checkbox" id="_toggle_6" /><label for="_toggle_6"></label> <ol> <li id="_sidebar_6.1"><a href="#sec-Executing-Requests"><span class="spec-secid">6.1</span>Executing Requests</a> <input hidden class="toggle" type="checkbox" id="_toggle_6.1" /><label for="_toggle_6.1"></label> <ol> <li id="_sidebar_6.1.1"><a href="#sec-Validating-Requests"><span class="spec-secid">6.1.1</span>Validating Requests</a></li> <li id="_sidebar_6.1.2"><a href="#sec-Coercing-Variable-Values"><span class="spec-secid">6.1.2</span>Coercing Variable Values</a></li> </ol> </li> <li id="_sidebar_6.2"><a href="#sec-Executing-Operations"><span class="spec-secid">6.2</span>Executing Operations</a> <input hidden class="toggle" type="checkbox" id="_toggle_6.2" /><label for="_toggle_6.2"></label> <ol> <li id="_sidebar_6.2.1"><a href="#sec-Query"><span class="spec-secid">6.2.1</span>Query</a></li> <li id="_sidebar_6.2.2"><a href="#sec-Mutation"><span class="spec-secid">6.2.2</span>Mutation</a></li> <li id="_sidebar_6.2.3"><a href="#sec-Subscription"><span class="spec-secid">6.2.3</span>Subscription</a> <input hidden class="toggle" type="checkbox" id="_toggle_6.2.3" /><label for="_toggle_6.2.3"></label> <ol> <li id="_sidebar_6.2.3.1"><a href="#sec-Source-Stream"><span class="spec-secid">6.2.3.1</span>Source Stream</a></li> <li id="_sidebar_6.2.3.2"><a href="#sec-Response-Stream"><span class="spec-secid">6.2.3.2</span>Response Stream</a></li> <li id="_sidebar_6.2.3.3"><a href="#sec-Unsubscribe"><span class="spec-secid">6.2.3.3</span>Unsubscribe</a></li> </ol> </li> </ol> </li> <li id="_sidebar_6.3"><a href="#sec-Executing-Selection-Sets"><span class="spec-secid">6.3</span>Executing Selection Sets</a> <input hidden class="toggle" type="checkbox" id="_toggle_6.3" /><label for="_toggle_6.3"></label> <ol> <li id="_sidebar_6.3.1"><a href="#sec-Normal-and-Serial-Execution"><span class="spec-secid">6.3.1</span>Normal and Serial Execution</a></li> <li id="_sidebar_6.3.2"><a href="#sec-Field-Collection"><span class="spec-secid">6.3.2</span>Field Collection</a></li> </ol> </li> <li id="_sidebar_6.4"><a href="#sec-Executing-Fields"><span class="spec-secid">6.4</span>Executing Fields</a> <input hidden class="toggle" type="checkbox" id="_toggle_6.4" /><label for="_toggle_6.4"></label> <ol> <li id="_sidebar_6.4.1"><a href="#sec-Coercing-Field-Arguments"><span class="spec-secid">6.4.1</span>Coercing Field Arguments</a></li> <li id="_sidebar_6.4.2"><a href="#sec-Value-Resolution"><span class="spec-secid">6.4.2</span>Value Resolution</a></li> <li id="_sidebar_6.4.3"><a href="#sec-Value-Completion"><span class="spec-secid">6.4.3</span>Value Completion</a></li> <li id="_sidebar_6.4.4"><a href="#sec-Handling-Field-Errors"><span class="spec-secid">6.4.4</span>Handling Field Errors</a></li> </ol> </li> </ol> </li> <li id="_sidebar_7"><a href="#sec-Response"><span class="spec-secid">7</span>Response</a> <input hidden class="toggle" type="checkbox" id="_toggle_7" /><label for="_toggle_7"></label> <ol> <li id="_sidebar_7.1"><a href="#sec-Response-Format"><span class="spec-secid">7.1</span>Response Format</a> <input hidden class="toggle" type="checkbox" id="_toggle_7.1" /><label for="_toggle_7.1"></label> <ol> <li id="_sidebar_7.1.1"><a href="#sec-Data"><span class="spec-secid">7.1.1</span>Data</a></li> <li id="_sidebar_7.1.2"><a href="#sec-Errors"><span class="spec-secid">7.1.2</span>Errors</a></li> </ol> </li> <li id="_sidebar_7.2"><a href="#sec-Serialization-Format"><span class="spec-secid">7.2</span>Serialization Format</a> <input hidden class="toggle" type="checkbox" id="_toggle_7.2" /><label for="_toggle_7.2"></label> <ol> <li id="_sidebar_7.2.1"><a href="#sec-JSON-Serialization"><span class="spec-secid">7.2.1</span>JSON Serialization</a></li> <li id="_sidebar_7.2.2"><a href="#sec-Serialized-Map-Ordering"><span class="spec-secid">7.2.2</span>Serialized Map Ordering</a></li> </ol> </li> </ol> </li> <li id="_sidebar_A"><a href="#sec-Appendix-Notation-Conventions"><span class="spec-secid">A</span>Appendix: Notation Conventions</a> <input hidden class="toggle" type="checkbox" id="_toggle_A" /><label for="_toggle_A"></label> <ol> <li id="_sidebar_A.1"><a href="#sec-Context-Free-Grammar"><span class="spec-secid">A.1</span>Context-Free Grammar</a></li> <li id="_sidebar_A.2"><a href="#sec-Lexical-and-Syntactical-Grammar"><span class="spec-secid">A.2</span>Lexical and Syntactical Grammar</a></li> <li id="_sidebar_A.3"><a href="#sec-Grammar-Notation"><span class="spec-secid">A.3</span>Grammar Notation</a></li> <li id="_sidebar_A.4"><a href="#sec-Grammar-Semantics"><span class="spec-secid">A.4</span>Grammar Semantics</a></li> <li id="_sidebar_A.5"><a href="#sec-Algorithms"><span class="spec-secid">A.5</span>Algorithms</a></li> </ol> </li> <li id="_sidebar_B"><a href="#sec-Appendix-Grammar-Summary"><span class="spec-secid">B</span>Appendix: Grammar Summary</a> <input hidden class="toggle" type="checkbox" id="_toggle_B" /><label for="_toggle_B"></label> <ol> <li id="_sidebar_B.1"><a href="#sec-Appendix-Grammar-Summary.Source-Text"><span class="spec-secid">B.1</span>Source Text</a></li> <li id="_sidebar_B.2"><a href="#sec-Appendix-Grammar-Summary.Ignored-Tokens"><span class="spec-secid">B.2</span>Ignored Tokens</a></li> <li id="_sidebar_B.3"><a href="#sec-Appendix-Grammar-Summary.Lexical-Tokens"><span class="spec-secid">B.3</span>Lexical Tokens</a></li> <li id="_sidebar_B.4"><a href="#sec-Document-Syntax"><span class="spec-secid">B.4</span>Document Syntax</a></li> </ol> </li> <li id="_sidebar_index"><a href="#index"><span class="spec-secid">§</span>Index</a></li> </ol> </div> </div> </body> </html>