A place to cache linked articles (think custom and personal wayback machine)
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

index.html 211KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565
  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang=fr>
  4. <!-- Has to be within the first 1024 bytes, hence before the <title>
  5. See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
  6. <meta charset=utf-8>
  7. <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
  8. <!-- The viewport meta is quite crowded and we are responsible for that.
  9. See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
  10. <meta name=viewport content="width=device-width,minimum-scale=1,initial-scale=1,shrink-to-fit=no">
  11. <!-- Required to make a valid HTML5 document. -->
  12. <title>GraphQL (archive) — David Larlet</title>
  13. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  14. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons/apple-touch-icon.png">
  15. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons/favicon-32x32.png">
  16. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons/favicon-16x16.png">
  17. <link rel="manifest" href="/manifest.json">
  18. <link rel="mask-icon" href="/static/david/icons/safari-pinned-tab.svg" color="#5bbad5">
  19. <link rel="shortcut icon" href="/static/david/icons/favicon.ico">
  20. <meta name="apple-mobile-web-app-title" content="David Larlet">
  21. <meta name="application-name" content="David Larlet">
  22. <meta name="msapplication-TileColor" content="#da532c">
  23. <meta name="msapplication-config" content="/static/david/icons/browserconfig.xml">
  24. <meta name="theme-color" content="#f0f0ea">
  25. <!-- That good ol' feed, subscribe :p. -->
  26. <link rel=alternate type="application/atom+xml" title=Feed href="/david/log/">
  27. <meta name="robots" content="noindex, nofollow">
  28. <meta content="origin-when-cross-origin" name="referrer">
  29. <!-- Canonical URL for SEO purposes -->
  30. <link rel="canonical" href="http://facebook.github.io/graphql/">
  31. <style>
  32. /* http://meyerweb.com/eric/tools/css/reset/ */
  33. html, body, div, span,
  34. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  35. a, abbr, address, big, cite, code,
  36. del, dfn, em, img, ins,
  37. small, strike, strong, tt, var,
  38. dl, dt, dd, ol, ul, li,
  39. fieldset, form, label, legend,
  40. table, caption, tbody, tfoot, thead, tr, th, td,
  41. article, aside, canvas, details, embed,
  42. figure, figcaption, footer, header, hgroup,
  43. menu, nav, output, ruby, section, summary,
  44. time, mark, audio, video {
  45. margin: 0;
  46. padding: 0;
  47. border: 0;
  48. font-size: 100%;
  49. font: inherit;
  50. vertical-align: baseline;
  51. }
  52. /* HTML5 display-role reset for older browsers */
  53. article, aside, details, figcaption, figure,
  54. footer, header, hgroup, menu, nav, section { display: block; }
  55. body { line-height: 1; }
  56. blockquote, q { quotes: none; }
  57. blockquote:before, blockquote:after,
  58. q:before, q:after {
  59. content: '';
  60. content: none;
  61. }
  62. table {
  63. border-collapse: collapse;
  64. border-spacing: 0;
  65. }
  66. /* http://practicaltypography.com/equity.html */
  67. /* https://calendar.perfplanet.com/2016/no-font-face-bulletproof-syntax/ */
  68. /* https://www.filamentgroup.com/lab/js-web-fonts.html */
  69. @font-face {
  70. font-family: 'EquityTextB';
  71. src: url('/static/david/css/fonts/Equity-Text-B-Regular-webfont.woff2') format('woff2'),
  72. url('/static/david/css/fonts/Equity-Text-B-Regular-webfont.woff') format('woff');
  73. font-weight: 300;
  74. font-style: normal;
  75. font-display: swap;
  76. }
  77. @font-face {
  78. font-family: 'EquityTextB';
  79. src: url('/static/david/css/fonts/Equity-Text-B-Italic-webfont.woff2') format('woff2'),
  80. url('/static/david/css/fonts/Equity-Text-B-Italic-webfont.woff') format('woff');
  81. font-weight: 300;
  82. font-style: italic;
  83. font-display: swap;
  84. }
  85. @font-face {
  86. font-family: 'EquityTextB';
  87. src: url('/static/david/css/fonts/Equity-Text-B-Bold-webfont.woff2') format('woff2'),
  88. url('/static/david/css/fonts/Equity-Text-B-Bold-webfont.woff') format('woff');
  89. font-weight: 700;
  90. font-style: normal;
  91. font-display: swap;
  92. }
  93. @font-face {
  94. font-family: 'ConcourseT3';
  95. src: url('/static/david/css/fonts/concourse_t3_regular-webfont-20190806.woff2') format('woff2'),
  96. url('/static/david/css/fonts/concourse_t3_regular-webfont-20190806.woff') format('woff');
  97. font-weight: 300;
  98. font-style: normal;
  99. font-display: swap;
  100. }
  101. /* http://practice.typekit.com/lesson/caring-about-opentype-features/ */
  102. body {
  103. /* http://www.cssfontstack.com/ Palatino 99% Win 86% Mac */
  104. font-family: "EquityTextB", Palatino, serif;
  105. background-color: #f0f0ea;
  106. color: #07486c;
  107. font-kerning: normal;
  108. -moz-osx-font-smoothing: grayscale;
  109. -webkit-font-smoothing: subpixel-antialiased;
  110. text-rendering: optimizeLegibility;
  111. font-variant-ligatures: common-ligatures contextual;
  112. font-feature-settings: "kern", "liga", "clig", "calt";
  113. }
  114. pre, code, kbd, samp, var, tt {
  115. font-family: 'TriplicateT4c', monospace;
  116. }
  117. em {
  118. font-style: italic;
  119. color: #323a45;
  120. }
  121. strong {
  122. font-weight: bold;
  123. color: black;
  124. }
  125. nav {
  126. background-color: #323a45;
  127. color: #f0f0ea;
  128. display: flex;
  129. justify-content: space-around;
  130. padding: 1rem .5rem;
  131. }
  132. nav:last-child {
  133. border-bottom: 1vh solid #2d7474;
  134. }
  135. nav a {
  136. color: #f0f0ea;
  137. }
  138. nav abbr {
  139. border-bottom: 1px dotted white;
  140. }
  141. h1 {
  142. border-top: 1vh solid #2d7474;
  143. border-bottom: .2vh dotted #2d7474;
  144. background-color: #e3e1e1;
  145. color: #323a45;
  146. text-align: center;
  147. padding: 5rem 0 4rem 0;
  148. width: 100%;
  149. font-family: 'ConcourseT3';
  150. display: flex;
  151. flex-direction: column;
  152. }
  153. h1.single {
  154. padding-bottom: 10rem;
  155. }
  156. h1 span {
  157. position: absolute;
  158. top: 1vh;
  159. left: 20%;
  160. line-height: 0;
  161. }
  162. h1 span a {
  163. line-height: 1.7;
  164. padding: 1rem 1.2rem .6rem 1.2rem;
  165. border-radius: 0 0 6% 6%;
  166. background: #2d7474;
  167. font-size: 1.3rem;
  168. color: white;
  169. text-decoration: none;
  170. }
  171. h2 {
  172. margin: 4rem 0 1rem;
  173. border-top: .2vh solid #2d7474;
  174. padding-top: 1vh;
  175. }
  176. h3 {
  177. text-align: center;
  178. margin: 3rem 0 .75em;
  179. }
  180. hr {
  181. height: .4rem;
  182. width: .4rem;
  183. border-radius: .4rem;
  184. background: #07486c;
  185. margin: 2.5rem auto;
  186. }
  187. time {
  188. display: bloc;
  189. margin-left: 0 !important;
  190. }
  191. ul, ol {
  192. margin: 2rem;
  193. }
  194. ul {
  195. list-style-type: square;
  196. }
  197. a {
  198. text-decoration-skip-ink: auto;
  199. text-decoration-thickness: 0.05em;
  200. text-underline-offset: 0.09em;
  201. }
  202. article {
  203. max-width: 50rem;
  204. display: flex;
  205. flex-direction: column;
  206. margin: 2rem auto;
  207. }
  208. article.single {
  209. border-top: .2vh dotted #2d7474;
  210. margin: -6rem auto 1rem auto;
  211. background: #f0f0ea;
  212. padding: 2rem;
  213. }
  214. article p:last-child {
  215. margin-bottom: 1rem;
  216. }
  217. p {
  218. padding: 0 .5rem;
  219. margin-left: 3rem;
  220. }
  221. p + p,
  222. figure + p {
  223. margin-top: 2rem;
  224. }
  225. blockquote {
  226. background-color: #e3e1e1;
  227. border-left: .5vw solid #2d7474;
  228. display: flex;
  229. flex-direction: column;
  230. align-items: center;
  231. padding: 1rem;
  232. margin: 1.5rem;
  233. }
  234. blockquote cite {
  235. font-style: italic;
  236. }
  237. blockquote p {
  238. margin-left: 0;
  239. }
  240. figure {
  241. border-top: .2vh solid #2d7474;
  242. background-color: #e3e1e1;
  243. text-align: center;
  244. padding: 1.5rem 0;
  245. margin: 1rem 0 0;
  246. font-size: 1.5rem;
  247. width: 100%;
  248. }
  249. figure img {
  250. max-width: 250px;
  251. max-height: 250px;
  252. border: .5vw solid #323a45;
  253. padding: 1px;
  254. }
  255. figcaption {
  256. padding: 1rem;
  257. line-height: 1.4;
  258. }
  259. aside {
  260. display: flex;
  261. flex-direction: column;
  262. background-color: #e3e1e1;
  263. padding: 1rem 0;
  264. border-bottom: .2vh solid #07486c;
  265. }
  266. aside p {
  267. max-width: 50rem;
  268. margin: 0 auto;
  269. }
  270. /* https://fvsch.com/code/css-locks/ */
  271. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  272. font-size: 1rem;
  273. line-height: calc( 1.5em + 0.2 * 1rem );
  274. }
  275. h1 {
  276. font-size: 1.9rem;
  277. line-height: calc( 1.2em + 0.2 * 1rem );
  278. }
  279. h2 {
  280. font-size: 1.6rem;
  281. line-height: calc( 1.3em + 0.2 * 1rem );
  282. }
  283. h3 {
  284. font-size: 1.35rem;
  285. line-height: calc( 1.4em + 0.2 * 1rem );
  286. }
  287. @media (min-width: 20em) {
  288. /* The (100vw - 20rem) / (50 - 20) part
  289. resolves to 0-1rem, depending on the
  290. viewport width (between 20em and 50em). */
  291. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  292. font-size: calc( 1rem + .6 * (100vw - 20rem) / (50 - 20) );
  293. line-height: calc( 1.5em + 0.2 * (100vw - 50rem) / (20 - 50) );
  294. margin-left: 0;
  295. }
  296. h1 {
  297. font-size: calc( 1.9rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  298. line-height: calc( 1.2em + 0.2 * (100vw - 50rem) / (20 - 50) );
  299. }
  300. h2 {
  301. font-size: calc( 1.5rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  302. line-height: calc( 1.3em + 0.2 * (100vw - 50rem) / (20 - 50) );
  303. }
  304. h3 {
  305. font-size: calc( 1.35rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  306. line-height: calc( 1.4em + 0.2 * (100vw - 50rem) / (20 - 50) );
  307. }
  308. }
  309. @media (min-width: 50em) {
  310. /* The right part of the addition *must* be a
  311. rem value. In this example we *could* change
  312. the whole declaration to font-size:2.5rem,
  313. but if our baseline value was not expressed
  314. in rem we would have to use calc. */
  315. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  316. font-size: calc( 1rem + .6 * 1rem );
  317. line-height: 1.5em;
  318. }
  319. p, li, pre, details {
  320. margin-left: 3rem;
  321. }
  322. h1 {
  323. font-size: calc( 1.9rem + 1.5 * 1rem );
  324. line-height: 1.2em;
  325. }
  326. h2 {
  327. font-size: calc( 1.5rem + 1.5 * 1rem );
  328. line-height: 1.3em;
  329. }
  330. h3 {
  331. font-size: calc( 1.35rem + 1.5 * 1rem );
  332. line-height: 1.4em;
  333. }
  334. figure img {
  335. max-width: 500px;
  336. max-height: 500px;
  337. }
  338. }
  339. figure.unsquared {
  340. margin-bottom: 1.5rem;
  341. }
  342. figure.unsquared img {
  343. height: inherit;
  344. }
  345. @media print {
  346. body { font-size: 100%; }
  347. a:after { content: " (" attr(href) ")"; }
  348. a, a:link, a:visited, a:after {
  349. text-decoration: underline;
  350. text-shadow: none !important;
  351. background-image: none !important;
  352. background: white;
  353. color: black;
  354. }
  355. abbr[title] { border-bottom: 0; }
  356. abbr[title]:after { content: " (" attr(title) ")"; }
  357. img { page-break-inside: avoid; }
  358. @page { margin: 2cm .5cm; }
  359. h1, h2, h3 { page-break-after: avoid; }
  360. p3 { orphans: 3; widows: 3; }
  361. img {
  362. max-width: 250px !important;
  363. max-height: 250px !important;
  364. }
  365. nav, aside { display: none; }
  366. }
  367. ul.with_columns {
  368. column-count: 1;
  369. }
  370. @media (min-width: 20em) {
  371. ul.with_columns {
  372. column-count: 2;
  373. }
  374. }
  375. @media (min-width: 50em) {
  376. ul.with_columns {
  377. column-count: 3;
  378. }
  379. }
  380. ul.with_two_columns {
  381. column-count: 1;
  382. }
  383. @media (min-width: 20em) {
  384. ul.with_two_columns {
  385. column-count: 1;
  386. }
  387. }
  388. @media (min-width: 50em) {
  389. ul.with_two_columns {
  390. column-count: 2;
  391. }
  392. }
  393. .gallery {
  394. display: flex;
  395. flex-wrap: wrap;
  396. justify-content: space-around;
  397. }
  398. .gallery figure img {
  399. margin-left: 1rem;
  400. margin-right: 1rem;
  401. }
  402. .gallery figure figcaption {
  403. font-family: 'ConcourseT3'
  404. }
  405. footer {
  406. font-family: 'ConcourseT3';
  407. display: flex;
  408. flex-direction: column;
  409. border-top: 3px solid white;
  410. padding: 4rem 0;
  411. background-color: #07486c;
  412. color: white;
  413. }
  414. footer > * {
  415. max-width: 50rem;
  416. margin: 0 auto;
  417. }
  418. footer a {
  419. color: #f1c40f;
  420. }
  421. footer .avatar {
  422. width: 200px;
  423. height: 200px;
  424. border-radius: 50%;
  425. float: left;
  426. -webkit-shape-outside: circle();
  427. shape-outside: circle();
  428. margin-right: 2rem;
  429. padding: 2px 5px 5px 2px;
  430. background: white;
  431. border-left: 1px solid #f1c40f;
  432. border-top: 1px solid #f1c40f;
  433. border-right: 5px solid #f1c40f;
  434. border-bottom: 5px solid #f1c40f;
  435. }
  436. </style>
  437. <h1>
  438. <span><a id="jumper" href="#jumpto" title="Un peu perdu ?">?</a></span>
  439. GraphQL (archive)
  440. <time>Pour la pérennité des contenus liés. Non-indexé, retrait sur simple email.</time>
  441. </h1>
  442. <section>
  443. <article>
  444. <h3><a href="http://facebook.github.io/graphql/">Source originale du contenu</a></h3>
  445. <section id="intro">
  446. <p><em>Working Draft &ndash; July 2015</em></p>
  447. <p><strong>Introduction</strong></p>
  448. <p>This is a Draft RFC Specification for GraphQL, a query language created by Facebook in 2012 for describing the capabilities and requirements of data models for client&#8208;server applications. The development of this standard started in 2015. GraphQL
  449. is a new and evolving language and is not complete. Significant enhancement will continue in future editions of this specification.</p>
  450. <p><strong>Copyright notice</strong></p>
  451. <p>Copyright (c) 2015, Facebook, Inc. All rights reserved.</p>
  452. <p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:</p>
  453. <ul>
  454. <li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</li>
  455. <li>Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.</li>
  456. <li>Neither the name Facebook nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.</li>
  457. </ul>
  458. <p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &ldquo;AS IS&rdquo; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  459. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  460. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  461. POSSIBILITY OF SUCH DAMAGE.</p>
  462. </section>
  463. <div class="spec-toc">
  464. <ol>
  465. <li><a href="#sec-Overview"><span class="spec-secnum">1</span>Overview</a></li>
  466. <li><a href="#sec-Language"><span class="spec-secnum">2</span>Language</a>
  467. <ol>
  468. <li><a href="#sec-Names"><span class="spec-secnum">2.1</span>Names</a></li>
  469. <li><a href="#sec-Language.Document"><span class="spec-secnum">2.2</span>Document</a></li>
  470. <li><a href="#sec-Language.Operations"><span class="spec-secnum">2.3</span>Operations</a></li>
  471. <li><a href="#sec-Language.Fields"><span class="spec-secnum">2.4</span>Fields</a></li>
  472. <li><a href="#sec-Field-Selections"><span class="spec-secnum">2.5</span>Field Selections</a></li>
  473. <li><a href="#sec-Language.Arguments"><span class="spec-secnum">2.6</span>Arguments</a></li>
  474. <li><a href="#sec-Field-Alias"><span class="spec-secnum">2.7</span>Field Alias</a></li>
  475. <li><a href="#sec-Input-Values"><span class="spec-secnum">2.8</span>Input Values</a></li>
  476. <li><a href="#sec-Language.Variables"><span class="spec-secnum">2.9</span>Variables</a></li>
  477. <li><a href="#sec-Language.Fragments"><span class="spec-secnum">2.10</span>Fragments</a>
  478. <ol>
  479. <li><a href="#sec-Types-on-fragments"><span class="spec-secnum">2.10.1</span>Types on fragments</a></li>
  480. <li><a href="#sec-Query-variables-in-fragments"><span class="spec-secnum">2.10.2</span>Query variables in fragments</a></li>
  481. <li><a href="#sec-Inline-fragments"><span class="spec-secnum">2.10.3</span>Inline fragments</a></li>
  482. </ol>
  483. </li>
  484. <li><a href="#sec-Language.Directives"><span class="spec-secnum">2.11</span>Directives</a>
  485. <ol>
  486. <li><a href="#sec-Fragment-Directives"><span class="spec-secnum">2.11.1</span>Fragment Directives</a></li>
  487. </ol>
  488. </li>
  489. </ol>
  490. </li>
  491. <li><a href="#sec-Type-System"><span class="spec-secnum">3</span>Type System</a>
  492. <ol>
  493. <li><a href="#sec-Type-System.Types"><span class="spec-secnum">3.1</span>Types</a>
  494. <ol>
  495. <li><a href="#sec-Scalars"><span class="spec-secnum">3.1.1</span>Scalars</a>
  496. <ol>
  497. <li><a href="#sec-Built-in-Scalars"><span class="spec-secnum">3.1.1.1</span>Built-in Scalars</a>
  498. <ol>
  499. <li><a href="#sec-Int"><span class="spec-secnum">3.1.1.1.1</span>Int</a></li>
  500. <li><a href="#sec-Float"><span class="spec-secnum">3.1.1.1.2</span>Float</a></li>
  501. <li><a href="#sec-String"><span class="spec-secnum">3.1.1.1.3</span>String</a></li>
  502. <li><a href="#sec-Boolean"><span class="spec-secnum">3.1.1.1.4</span>Boolean</a></li>
  503. <li><a href="#sec-ID"><span class="spec-secnum">3.1.1.1.5</span>ID</a></li>
  504. </ol>
  505. </li>
  506. </ol>
  507. </li>
  508. <li><a href="#sec-Objects"><span class="spec-secnum">3.1.2</span>Objects</a>
  509. <ol>
  510. <li><a href="#sec-Object-Field-Arguments"><span class="spec-secnum">3.1.2.1</span>Object Field Arguments</a></li>
  511. <li><a href="#sec-Object-Field-deprecation"><span class="spec-secnum">3.1.2.2</span>Object Field deprecation</a></li>
  512. <li><a href="#sec-Object-type-validation"><span class="spec-secnum">3.1.2.3</span>Object type validation</a></li>
  513. </ol>
  514. </li>
  515. <li><a href="#sec-Interfaces"><span class="spec-secnum">3.1.3</span>Interfaces</a>
  516. <ol>
  517. <li><a href="#sec-Interface-type-validation"><span class="spec-secnum">3.1.3.1</span>Interface type validation</a></li>
  518. </ol>
  519. </li>
  520. <li><a href="#sec-Unions"><span class="spec-secnum">3.1.4</span>Unions</a>
  521. <ol>
  522. <li><a href="#sec-Union-type-validation"><span class="spec-secnum">3.1.4.1</span>Union type validation</a></li>
  523. </ol>
  524. </li>
  525. <li><a href="#sec-Enums"><span class="spec-secnum">3.1.5</span>Enums</a></li>
  526. <li><a href="#sec-Input-Objects"><span class="spec-secnum">3.1.6</span>Input Objects</a></li>
  527. <li><a href="#sec-Lists"><span class="spec-secnum">3.1.7</span>Lists</a></li>
  528. <li><a href="#sec-Non-Null"><span class="spec-secnum">3.1.8</span>Non-Null</a></li>
  529. </ol>
  530. </li>
  531. <li><a href="#sec-Type-System.Directives"><span class="spec-secnum">3.2</span>Directives</a>
  532. <ol>
  533. <li><a href="#sec--skip"><span class="spec-secnum">3.2.1</span>@skip</a></li>
  534. <li><a href="#sec--include"><span class="spec-secnum">3.2.2</span>@include</a></li>
  535. </ol>
  536. </li>
  537. <li><a href="#sec-Starting-types"><span class="spec-secnum">3.3</span>Starting types</a></li>
  538. </ol>
  539. </li>
  540. <li><a href="#sec-Introspection"><span class="spec-secnum">4</span>Introspection</a>
  541. <ol>
  542. <li><a href="#sec-General-Principles"><span class="spec-secnum">4.1</span>General Principles</a>
  543. <ol>
  544. <li><a href="#sec-Naming-conventions"><span class="spec-secnum">4.1.1</span>Naming conventions</a></li>
  545. <li><a href="#sec-Documentation"><span class="spec-secnum">4.1.2</span>Documentation</a></li>
  546. <li><a href="#sec-Deprecation"><span class="spec-secnum">4.1.3</span>Deprecation</a></li>
  547. <li><a href="#sec-Type-Name-Introspection"><span class="spec-secnum">4.1.4</span>Type Name Introspection</a></li>
  548. </ol>
  549. </li>
  550. <li><a href="#sec-Schema-Introspection"><span class="spec-secnum">4.2</span>Schema Introspection</a>
  551. <ol>
  552. <li><a href="#sec-The-__Type-Type"><span class="spec-secnum">4.2.1</span>The &quot;__Type&quot; Type</a></li>
  553. <li><a href="#sec-Type-Kinds"><span class="spec-secnum">4.2.2</span>Type Kinds</a>
  554. <ol>
  555. <li><a href="#sec-Scalar"><span class="spec-secnum">4.2.2.1</span>Scalar</a></li>
  556. <li><a href="#sec-Object"><span class="spec-secnum">4.2.2.2</span>Object</a></li>
  557. <li><a href="#sec-Union"><span class="spec-secnum">4.2.2.3</span>Union</a></li>
  558. <li><a href="#sec-Interface"><span class="spec-secnum">4.2.2.4</span>Interface</a></li>
  559. <li><a href="#sec-Enum"><span class="spec-secnum">4.2.2.5</span>Enum</a></li>
  560. <li><a href="#sec-Input-Object"><span class="spec-secnum">4.2.2.6</span>Input Object</a></li>
  561. <li><a href="#sec-List"><span class="spec-secnum">4.2.2.7</span>List</a></li>
  562. <li><a href="#sec-Non-null"><span class="spec-secnum">4.2.2.8</span>Non-null</a></li>
  563. <li><a href="#sec-Combining-List-and-Non-Null"><span class="spec-secnum">4.2.2.9</span>Combining List and Non-Null</a></li>
  564. </ol>
  565. </li>
  566. </ol>
  567. </li>
  568. </ol>
  569. </li>
  570. <li><a href="#sec-Validation"><span class="spec-secnum">5</span>Validation</a>
  571. <ol>
  572. <li><a href="#sec-Validation.Fields"><span class="spec-secnum">5.1</span>Fields</a>
  573. <ol>
  574. <li><a href="#sec-Field-Selections-on-Objects-Interfaces-and-Unions-Types"><span class="spec-secnum">5.1.1</span>Field Selections on Objects, Interfaces, and Unions Types</a></li>
  575. <li><a href="#sec-Field-Selection-Merging"><span class="spec-secnum">5.1.2</span>Field Selection Merging</a></li>
  576. <li><a href="#sec-Leaf-Field-Selections"><span class="spec-secnum">5.1.3</span>Leaf Field Selections</a></li>
  577. </ol>
  578. </li>
  579. <li><a href="#sec-Validation.Arguments"><span class="spec-secnum">5.2</span>Arguments</a>
  580. <ol>
  581. <li><a href="#sec-Argument-Names"><span class="spec-secnum">5.2.1</span>Argument Names</a></li>
  582. <li><a href="#sec-Argument-Values-Type-Correctness"><span class="spec-secnum">5.2.2</span>Argument Values Type Correctness</a>
  583. <ol>
  584. <li><a href="#sec-Compatible-Values"><span class="spec-secnum">5.2.2.1</span>Compatible Values</a></li>
  585. <li><a href="#sec-Required-Arguments"><span class="spec-secnum">5.2.2.2</span>Required Arguments</a></li>
  586. </ol>
  587. </li>
  588. </ol>
  589. </li>
  590. <li><a href="#sec-Validation.Fragments"><span class="spec-secnum">5.3</span>Fragments</a>
  591. <ol>
  592. <li><a href="#sec-Fragment-Declarations"><span class="spec-secnum">5.3.1</span>Fragment Declarations</a>
  593. <ol>
  594. <li><a href="#sec-Fragment-Spread-Type-Existence"><span class="spec-secnum">5.3.1.1</span>Fragment Spread Type Existence</a></li>
  595. <li><a href="#sec-Fragments-On-Composite-Types"><span class="spec-secnum">5.3.1.2</span>Fragments On Composite Types</a></li>
  596. <li><a href="#sec-Fragments-Must-Be-Used"><span class="spec-secnum">5.3.1.3</span>Fragments Must Be Used</a></li>
  597. </ol>
  598. </li>
  599. <li><a href="#sec-Fragment-Spreads"><span class="spec-secnum">5.3.2</span>Fragment Spreads</a>
  600. <ol>
  601. <li><a href="#sec-Fragment-spread-target-defined"><span class="spec-secnum">5.3.2.1</span>Fragment spread target defined</a></li>
  602. <li><a href="#sec-Fragment-spreads-must-not-form-cycles"><span class="spec-secnum">5.3.2.2</span>Fragment spreads must not form cycles</a></li>
  603. <li><a href="#sec-Fragment-spread-is-possible"><span class="spec-secnum">5.3.2.3</span>Fragment spread is possible</a>
  604. <ol>
  605. <li><a href="#sec-Object-Spreads-In-Object-Scope"><span class="spec-secnum">5.3.2.3.1</span>Object Spreads In Object Scope</a></li>
  606. <li><a href="#sec-Abstract-Spreads-in-Object-Scope"><span class="spec-secnum">5.3.2.3.2</span>Abstract Spreads in Object Scope</a></li>
  607. <li><a href="#sec-Object-Spreads-In-Abstract-Scope"><span class="spec-secnum">5.3.2.3.3</span>Object Spreads In Abstract Scope</a></li>
  608. <li><a href="#sec-Abstract-Spreads-in-Abstract-Scope"><span class="spec-secnum">5.3.2.3.4</span>Abstract Spreads in Abstract Scope</a></li>
  609. </ol>
  610. </li>
  611. </ol>
  612. </li>
  613. </ol>
  614. </li>
  615. <li><a href="#sec-Validation.Directives"><span class="spec-secnum">5.4</span>Directives</a>
  616. <ol>
  617. <li><a href="#sec-Directives-Are-Defined"><span class="spec-secnum">5.4.1</span>Directives Are Defined</a></li>
  618. </ol>
  619. </li>
  620. <li><a href="#sec-Validation.Operations"><span class="spec-secnum">5.5</span>Operations</a>
  621. <ol>
  622. <li><a href="#sec-Validation.Operations.Variables"><span class="spec-secnum">5.5.1</span>Variables</a>
  623. <ol>
  624. <li><a href="#sec-Variable-Default-Values-Are-Correctly-Typed"><span class="spec-secnum">5.5.1.1</span>Variable Default Values Are Correctly Typed</a></li>
  625. <li><a href="#sec-Variables-Are-Input-Types"><span class="spec-secnum">5.5.1.2</span>Variables Are Input Types</a></li>
  626. <li><a href="#sec-All-Variable-Uses-Defined"><span class="spec-secnum">5.5.1.3</span>All Variable Uses Defined</a></li>
  627. <li><a href="#sec-All-Variables-Used"><span class="spec-secnum">5.5.1.4</span>All Variables Used</a></li>
  628. <li><a href="#sec-All-Variable-Usages-are-Allowed"><span class="spec-secnum">5.5.1.5</span>All Variable Usages are Allowed</a></li>
  629. </ol>
  630. </li>
  631. </ol>
  632. </li>
  633. </ol>
  634. </li>
  635. <li><a href="#sec-Execution"><span class="spec-secnum">6</span>Execution</a>
  636. <ol>
  637. <li><a href="#sec-Evaluating-requests"><span class="spec-secnum">6.1</span>Evaluating requests</a></li>
  638. <li><a href="#sec-Evaluating-operations"><span class="spec-secnum">6.2</span>Evaluating operations</a></li>
  639. <li><a href="#sec-Evaluating-selection-sets"><span class="spec-secnum">6.3</span>Evaluating selection sets</a></li>
  640. <li><a href="#sec-Evaluating-a-grouped-field-set"><span class="spec-secnum">6.4</span>Evaluating a grouped field set</a>
  641. <ol>
  642. <li><a href="#sec-Field-entries"><span class="spec-secnum">6.4.1</span>Field entries</a></li>
  643. <li><a href="#sec-Normal-evaluation"><span class="spec-secnum">6.4.2</span>Normal evaluation</a></li>
  644. <li><a href="#sec-Serial-execution"><span class="spec-secnum">6.4.3</span>Serial execution</a></li>
  645. <li><a href="#sec-Error-handling"><span class="spec-secnum">6.4.4</span>Error handling</a></li>
  646. <li><a href="#sec-Nullability"><span class="spec-secnum">6.4.5</span>Nullability</a></li>
  647. </ol>
  648. </li>
  649. </ol>
  650. </li>
  651. <li><a href="#sec-Response"><span class="spec-secnum">7</span>Response</a>
  652. <ol>
  653. <li><a href="#sec-Serialization-Format"><span class="spec-secnum">7.1</span>Serialization Format</a>
  654. <ol>
  655. <li><a href="#sec-JSON-Serialization"><span class="spec-secnum">7.1.1</span>JSON Serialization</a></li>
  656. </ol>
  657. </li>
  658. <li><a href="#sec-Response-Format"><span class="spec-secnum">7.2</span>Response Format</a>
  659. <ol>
  660. <li><a href="#sec-Data"><span class="spec-secnum">7.2.1</span>Data</a></li>
  661. <li><a href="#sec-Errors"><span class="spec-secnum">7.2.2</span>Errors</a></li>
  662. </ol>
  663. </li>
  664. </ol>
  665. </li>
  666. <li><a href="#sec-Grammar"><span class="spec-secnum">8</span>Grammar</a>
  667. <ol>
  668. <li><a href="#sec-Ignored-Source"><span class="spec-secnum">8.1</span>Ignored Source</a></li>
  669. <li><a href="#sec-Tokens"><span class="spec-secnum">8.2</span>Tokens</a></li>
  670. <li><a href="#sec-Syntax"><span class="spec-secnum">8.3</span>Syntax</a>
  671. <ol>
  672. <li><a href="#sec-Syntax.Document"><span class="spec-secnum">8.3.1</span>Document</a></li>
  673. <li><a href="#sec-Syntax.Operations"><span class="spec-secnum">8.3.2</span>Operations</a></li>
  674. <li><a href="#sec-Syntax.Fragments"><span class="spec-secnum">8.3.3</span>Fragments</a></li>
  675. <li><a href="#sec-Values"><span class="spec-secnum">8.3.4</span>Values</a>
  676. <ol>
  677. <li><a href="#sec-Array-Value"><span class="spec-secnum">8.3.4.1</span>Array Value</a></li>
  678. <li><a href="#sec-Object-Value"><span class="spec-secnum">8.3.4.2</span>Object Value</a></li>
  679. </ol>
  680. </li>
  681. <li><a href="#sec-Syntax.Directives"><span class="spec-secnum">8.3.5</span>Directives</a></li>
  682. <li><a href="#sec-Syntax.Types"><span class="spec-secnum">8.3.6</span>Types</a></li>
  683. </ol>
  684. </li>
  685. </ol>
  686. </li>
  687. </ol>
  688. </div>
  689. <p></header>
  690. <section id="sec-Overview">
  691. <h2><span class="spec-secnum" title="link to this section"><a href="#sec-Overview">1</a></span>Overview</h2>
  692. <p>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>
  693. <p>For example, this GraphQL request will receive the name of the user with id 4 from the Facebook implementation of GraphQL.</p><pre><code>{
  694. user(id: 4) {
  695. name
  696. }
  697. }
  698. </code></pre>
  699. <p>Which produces the resulting data (in JSON):</p><pre><code>{
  700. <span class="hljs-string">"user"</span>: {
  701. <span class="hljs-string">"name"</span>: <span class="hljs-string">"Mark Zuckerberg"</span>
  702. }
  703. }
  704. </code></pre>
  705. <p>GraphQL is not a programming language capable of arbitrary computation, but is instead a language used to query application servers that have capabilities defined in this specification. GraphQL does not mandate a particular programming language or
  706. storage system for application servers that implement it. Instead, application servers 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
  707. development and a powerful platform for tool&#8208;building.</p>
  708. <p>GraphQL has a number of design principles:</p>
  709. <ul>
  710. <li><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 query itself is structured hierarchically. The query
  711. is shaped just like the data it returns. It is a natural way for clients to describe data requirements.</li>
  712. <li><strong>Product&#8208;centric</strong>: GraphQL is unapologetically driven by the requirements of views and the front&#8208;end engineers that write them. GraphQL starts with their way of thinking and requirements and build the language and runtime
  713. necessary to enable that.</li>
  714. <li><strong>Strong&#8208;typing</strong>: Every GraphQL server defines an application&#8208;specific type system. Queries are executed within the context of that type system. Given a query, tools can ensure that the query is both syntactically correct
  715. and valid within the GraphQL type system before execution, i.e. at development time, and the server can make certain guarantees about the shape and nature of the response.</li>
  716. <li><strong>Client&#8208;specified queries</strong>: Through its type system, a GraphQL server 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
  717. published capabilities. These queries are specified at field&#8208;level granularity. In the majority of client&#8208;server applications written without GraphQL, the server determines the data returned in its various scripted endpoints. A GraphQL
  718. query, on the other hand, returns exactly what a client asks for and no more.</li>
  719. <li><strong>Introspective</strong>: GraphQL is introspective. A GraphQL server&rsquo;s type system must be queryable by the GraphQL language itself, as will be described in this specification. GraphQL introspection serves as a powerful platform for
  720. building common tools and client software libraries.</li>
  721. </ul>
  722. <p>Because of these principles, GraphQL is a powerful and productive environment for building client applications. Product developers and designers building applications against working GraphQL servers -- supported with quality tools -- can quickly become
  723. productive without reading extensive documentation and with little or no formal training. To enable that experience, there must be those that build those servers and tools.</p>
  724. <p>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
  725. power them. The goal of this specification is to provide a foundation and framework for an ecosystem of GraphQL tools, client libraries, and server implementations -- spanning both organizations and platforms -- that has yet to be built. We look
  726. forward to working with the community in order to do that. </p>
  727. </section>
  728. <section id="sec-Language">
  729. <h2><span class="spec-secnum" title="link to this section"><a href="#sec-Language">2</a></span>Language</h2>
  730. <p>Clients use the GraphQL language to make requests to a GraphQL server. We refer to these requests as documents. A document may contain operations (queries and mutations are both operations) and fragments, a common unit of composition allowing for
  731. query reuse.</p>
  732. <section id="sec-Names">
  733. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Names">2.1</a></span>Names</h3>
  734. <p>GraphQL documents are full of named things: operations, fields, arguments, directives, fragments, and variables. All names follow the same grammatical form:</p>
  735. <div class="spec-production" id="Name"><span class="spec-nt"><a href="#Name">Name</a></span>
  736. <div class="spec-rhs"><span class="spec-rx">/[_A-Za-z][_0-9A-Za-z]*/</span></div>
  737. </div>
  738. <p>Names in GraphQL are case&#8208;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
  739. different names.</p>
  740. <p>Names in GraphQL are limited to this <acronym>ASCII</acronym> subset of possible characters to support interoperation with as many other systems as possible.</p>
  741. </section>
  742. <section id="sec-Language.Document">
  743. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Language.Document">2.2</a></span>Document</h3>
  744. <p>GraphQL documents are only executable by a server if they contain an operation. However documents which do not contain operations may still be parsed and validated to allow client to represent a single request across many documents.</p>
  745. <p>GraphQL documents may contain multiple operations, as long as they are named. When submitting a document with multiple operations to a GraphQL server, the name of the desired operation must also be provided.</p>
  746. <p>If a document contains only one query operation, that operation may be represented in the shorthand form, which omits the query keyword and query name.</p>
  747. </section>
  748. <section id="sec-Language.Operations">
  749. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Language.Operations">2.3</a></span>Operations</h3>
  750. <p>There are two types of operations that GraphQL models:</p>
  751. <ul>
  752. <li>query &ndash; a read&#8208;only fetch.</li>
  753. <li>mutation &ndash; a write followed by a fetch.</li>
  754. </ul>
  755. <p>Each operation is represented by a custom name and a selection of fields.</p>
  756. <p><strong>Query shorthand</strong></p>
  757. <p>If a query has no variables or directives or name, the <code>query</code> keyword can be omitted. This means it must be the only query in the document.</p>
  758. <div class="spec-note">many examples below will use the query shorthand syntax.</div>
  759. </section>
  760. <section id="sec-Language.Fields">
  761. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Language.Fields">2.4</a></span>Fields</h3>
  762. <p>A field in the top&#8208;level selection set often represents some kind of information that is globally accessible to your application and the current viewer. Some typical examples of global fields:</p><pre><code># <code>me</code> could represent the currently logged in user.
  763. query getMe {
  764. me {</p>
  765. <h1>...</h1>
  766. <p>}
  767. }</p>
  768. <h1><code>user</code> represents one of many users in a graph of data.</h1>
  769. <p>query getZuck {
  770. user(id: 4) {</p>
  771. <h1>...</h1>
  772. <p>}
  773. }
  774. </code></pre></section>
  775. <section id="sec-Field-Selections">
  776. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Field-Selections">2.5</a></span>Field Selections</h3>
  777. <p>Each field is of a specific type, and the sub&#8208;fields must always be explicitly declared via a field selection, unless it is a scalar. For example, when fetching data from some user object:</p><pre><code>query getZuck {
  778. user(id: 4) {
  779. id
  780. firstName
  781. lastName
  782. }
  783. }
  784. </code></pre>
  785. <p>Field selections can be further composed to explicitly state all subfields of nested types. All queries must specify down to scalar fields.</p><pre><code>query getZuck {
  786. user(id: 4) {
  787. id
  788. firstName
  789. lastName
  790. birthday {
  791. month
  792. day
  793. }
  794. }
  795. }
  796. </code></pre></section>
  797. <section id="sec-Language.Arguments">
  798. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Language.Arguments">2.6</a></span>Arguments</h3>
  799. <p>Fields and directives may take arguments.</p>
  800. <p>These often map directly to function arguments within the GraphQL server implementation. We already saw arguments used in the global field above.</p>
  801. <p>In this example, we want to query a user&rsquo;s profile picture of a specific size:</p><pre><code>{
  802. user(id: 4) {
  803. id
  804. name
  805. profilePic(size: 100)
  806. }
  807. }
  808. </code></pre>
  809. <p>Many arguments can exist for a given field:</p><pre><code>{
  810. user(id: 4) {
  811. id
  812. name
  813. profilePic(width: 100, height: 50)
  814. }
  815. }
  816. </code></pre>
  817. <p><strong>Arguments are unordered</strong></p>
  818. <p>Arguments may be provided in any syntactic order and maintain identical semantic meaning.</p>
  819. <p>These two queries are semantically identical:</p><pre><code>{
  820. picture(width: 200, height: 100)
  821. }
  822. </code></pre><pre><code>{
  823. picture(height: 100, width: 200)
  824. }
  825. </code></pre></section>
  826. <section id="sec-Field-Alias">
  827. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Field-Alias">2.7</a></span>Field Alias</h3>
  828. <p>By default, the key in the response object will use the field name queried. However, you can define a different name by specifying an alias.</p>
  829. <p>In this example, we can fetch two profile pictures of different sizes and ensure the resulting object will not have duplicate keys:</p><pre><code>{
  830. user(id: 4) {
  831. id
  832. name
  833. smallPic: profilePic(size: 64)
  834. bigPic: profilePic(size: 1024)
  835. }
  836. }
  837. </code></pre>
  838. <p>Which returns the result:</p><pre><code>{
  839. <span class="hljs-string">"user"</span>: {
  840. <span class="hljs-string">"id"</span>: <span class="hljs-number">4</span>,
  841. <span class="hljs-string">"name"</span>: <span class="hljs-string">"Mark"</span>,
  842. <span class="hljs-string">"smallPic"</span>: <span class="hljs-string">"https://cdn.site.io/pic-4-64.jpg"</span>,
  843. <span class="hljs-string">"bigPic"</span>: <span class="hljs-string">"https://cdn.site.io/pic-4-1024.jpg"</span>
  844. }
  845. }
  846. </code></pre>
  847. <p>Since the top level of a query is a field, it also can be given an alias:</p><pre><code>{
  848. zuck: user(id: 4) {
  849. id
  850. name
  851. }
  852. }
  853. </code></pre>
  854. <p>Returns the result:</p><pre><code>{
  855. <span class="hljs-string">"zuck"</span>: {
  856. <span class="hljs-string">"id"</span>: <span class="hljs-number">4</span>,
  857. <span class="hljs-string">"name"</span>: <span class="hljs-string">"Mark Zuckerberg"</span>
  858. }
  859. }
  860. </code></pre>
  861. <p>A field&rsquo;s response key is its alias if an alias is provided, and it is the field&rsquo;s name otherwise.</p>
  862. </section>
  863. <section id="sec-Input-Values">
  864. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Input-Values">2.8</a></span>Input Values</h3>
  865. <p>Field and directive arguments accept input values. Input values can be specified as a variable or represented inline as literals. Input values can be scalars, enumerations, or input objects. List and inputs objects may also contain variables.</p>
  866. <p><strong>Int</strong></p>
  867. <p>Int is a number specified without a decimal point (ex. <code>1</code>).</p>
  868. <p><strong>Float</strong></p>
  869. <p>A Float numbers always includes a decimal point (ex. <code>1.0</code>) and may optionally also include an exponent (ex. <code>6.0221413e23</code>).</p>
  870. <p><strong>Boolean</strong></p>
  871. <p>The two keywords <code>true</code> and <code>false</code> represent the two boolean values.</p>
  872. <p><strong>String</strong></p>
  873. <p>Strings are lists of characters wrapped in double&#8208;quotes <code>&quot;</code>. (ex. <code>&quot;Hello World&quot;</code>). Whitespace is significant within a string.</p>
  874. <p><strong>Enum Value</strong></p>
  875. <p>Enum values are represented as unquoted names (ex. <code>MOBILE_WEB</code>). It is recommended that Enum values be &ldquo;all caps&rdquo;. Enum values are only used in contexts where the precise enumeration type is known. Therefore it&rsquo;s not
  876. necessary to use the enumeration type name in the literal.</p>
  877. <p><strong>List</strong></p>
  878. <p>Lists are ordered sequences of values wrapped in square&#8208;brackets <code>[ ]</code>. The values of a List literal may be any value literal or variable (ex. <code>[1, 2, 3]</code>).</p>
  879. <p>Commas are optional throughout GraphQL so trailing commas are allowed and repeated commas do not represent missing values.</p>
  880. <p><strong>Input Object</strong></p>
  881. <p>Input object literals are unordered lists of keyed input values wrapped in curly&#8208;braces <code>{ }</code>. The values of an object literal may be any input value literal or variable (ex. <code>{ name: &quot;Hello world&quot;, score: 1.0 }</code>).
  882. We refer to literal representation of input objects as &ldquo;object literals.&rdquo;</p>
  883. </section>
  884. <section id="sec-Language.Variables">
  885. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Language.Variables">2.9</a></span>Variables</h3>
  886. <p>A GraphQL query can be parameterized with variables, maximizing query reuse, and avoiding costly string building in clients at runtime.</p>
  887. <p>Variables must be defined at the top of an operation and have global scope.</p>
  888. <p>In this example, we want to fetch a profile picture size based on the size of a particular device:</p><pre><code>query getZuckProfile($devicePicSize: Int) {
  889. user(id: 4) {
  890. id
  891. name
  892. profilePic(size: $devicePicSize)
  893. }
  894. }
  895. </code></pre>
  896. <p>Values for those variables are provided along with a GraphQL query, so they may be substituted during execution. If providing JSON for the variables values, we could run this query and request profilePic of size 60 width:</p><pre><code>{
  897. <span class="hljs-string">"devicePicSize"</span>: <span class="hljs-number">60</span>
  898. }
  899. </code></pre></section>
  900. <section id="sec-Language.Fragments">
  901. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Language.Fragments">2.10</a></span>Fragments</h3>
  902. <p>Fragments allow for reuse of repeated portions of a query. It is the unit of composition in GraphQL.</p>
  903. <p>For example, if we wanted to fetch some common information about mutual friends as well as friends of some user:</p><pre><code>query noFragments {
  904. user(id: 4) {
  905. friends(first: 10) {
  906. id
  907. name
  908. profilePic(size: 50)
  909. }
  910. mutualFriends(first: 10) {
  911. id
  912. name
  913. profilePic(size: 50)
  914. }
  915. }
  916. }
  917. </code></pre>
  918. <p>The repeated fields could be extracted into a fragment and composed by a parent fragment or query.</p><pre><code>query withFragments {
  919. user(id: 4) {
  920. friends(first: 10) {
  921. ...friendFields
  922. }
  923. mutualFriends(first: 10) {
  924. ...friendFields
  925. }
  926. }
  927. }</p>
  928. <p>fragment friendFields on User {
  929. id
  930. name
  931. profilePic(size: 50)
  932. }
  933. </code></pre>
  934. <p>Fragments are consumed by using the spread operator (<code>...</code>). All fields selected by the fragment will be added to the query field selection at the same level as the fragment invocation. This happens through multiple levels of fragment
  935. spreads.</p>
  936. <p>For example:</p><pre><code>query withNestedFragments {
  937. user(id: 4) {
  938. friends(first: 10) {
  939. ...friendFields
  940. }
  941. mutualFriends(first: 10) {
  942. ...friendFields
  943. }
  944. }
  945. }</p>
  946. <p>fragment friendFields on User {
  947. id
  948. name
  949. ...standardProfilePic
  950. }</p>
  951. <p>fragment standardProfilePic on User {
  952. profilePic(size: 50)
  953. }
  954. </code></pre>
  955. <p>The queries <code>noFragments</code>, <code>withFragments</code>, and <code>withNestedFragments</code> all produce the same response object.</p>
  956. <section id="sec-Types-on-fragments">
  957. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Types-on-fragments">2.10.1</a></span>Types on fragments</h4>
  958. <p>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>
  959. <p>Fragments cannot be specified on any input value (scalar, enumeration, or input object).</p>
  960. <p>Fragments can be specified on object types, interfaces, and unions.</p>
  961. <p>Selections within fragments only return values when concrete type of the object it is operating on matches the type of the fragment.</p>
  962. <p>For example in this query on the Facebook data model:</p><pre><code>query FragmentTyping {
  963. profiles(handles: [&quot;zuck&quot;, &quot;cocacola&quot;]) {
  964. handle
  965. ...userFragment
  966. ...pageFragment
  967. }
  968. }</p>
  969. <p>fragment userFragment on User {
  970. friends {
  971. count
  972. }
  973. }</p>
  974. <p>fragment pageFragment on Page {
  975. likers {
  976. count
  977. }
  978. }
  979. </code></pre>
  980. <p>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><code>{
  981. <span class="hljs-string">"profiles"</span> : [
  982. {
  983. <span class="hljs-string">"handle"</span> : <span class="hljs-string">"zuck"</span>,
  984. <span class="hljs-string">"friends"</span> : { <span class="hljs-string">"count"</span> : <span class="hljs-number">1234</span> }
  985. },
  986. {
  987. <span class="hljs-string">"handle"</span> : <span class="hljs-string">"cocacola"</span>,
  988. <span class="hljs-string">"likers"</span> : { <span class="hljs-string">"count"</span> : <span class="hljs-number">90234512</span> }
  989. }
  990. ]
  991. }
  992. </code></pre></section>
  993. <section id="sec-Query-variables-in-fragments">
  994. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Query-variables-in-fragments">2.10.2</a></span>Query variables in fragments</h4>
  995. <p>Query variables can be used within fragments. Query variables have global scope with a given operation, so a variable used within a fragment must be declared in any top&#8208;level operation that transitively consumes that fragment. If a variable
  996. is referenced in a fragment and is included by an operation that does not define that variable, the operation cannot be executed.</p>
  997. </section>
  998. <section id="sec-Inline-fragments">
  999. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Inline-fragments">2.10.3</a></span>Inline fragments</h4>
  1000. <p>Fragments can be defined inline to query. This is done to conditionally execute fields based on their runtime type. This feature of standard fragment inclusion was demonstrated in the <code>query FragmentTyping</code> example. We could accomplish
  1001. the same thing using inline fragments.</p><pre><code>query inlineFragmentTyping {
  1002. profiles(handles: [&quot;zuck&quot;, &quot;cocacola&quot;]) {
  1003. handle
  1004. ... on User {
  1005. friends {
  1006. count
  1007. }
  1008. }
  1009. ... on Page {
  1010. likers {
  1011. count
  1012. }
  1013. }
  1014. }
  1015. }
  1016. </code></pre></section>
  1017. </section>
  1018. <section id="sec-Language.Directives">
  1019. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Language.Directives">2.11</a></span>Directives</h3>
  1020. <p>In some cases, you need to provide options to alter GraphQL&rsquo;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
  1021. the executor.</p>
  1022. <p>Directives have a name along with a list of arguments which may accept values of any input type.</p>
  1023. <p>Directives can be used to describe additional information for fields, fragments, and operations.</p>
  1024. <p>As future versions of GraphQL adopts new configurable execution capabilities, they may be exposed via directives.</p>
  1025. <section id="sec-Fragment-Directives">
  1026. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Fragment-Directives">2.11.1</a></span>Fragment Directives</h4>
  1027. <p>Fragments may include directives to alter their behavior. At runtime, the directives provided on a fragment spread override those described on the definition.</p>
  1028. <p>For example, the following query:</p><pre><code>query hasConditionalFragment($condition: Boolean) {
  1029. ...maybeFragment @include(if: $condition)
  1030. }</p>
  1031. <p>fragment maybeFragment on Query {
  1032. me {
  1033. name
  1034. }
  1035. }
  1036. </code></pre>
  1037. <p>Will have identical runtime behavior as</p><pre><code>query hasConditionalFragment($condition: Boolean) {
  1038. ...maybeFragment
  1039. }</p>
  1040. <p>fragment maybeFragment on Query @include(if: $condition) {
  1041. me {
  1042. name
  1043. }
  1044. }
  1045. </code></pre>
  1046. <div class="spec-algo" id="FragmentSpreadDirectives()"><span class="spec-call"><a href="#FragmentSpreadDirectives()">FragmentSpreadDirectives</a>(<var>fragmentSpread</var>)</span>
  1047. <ol>
  1048. <li>Let <var>directives</var> be the set of directives on <var>fragmentSpread</var></li>
  1049. <li>Let <var>fragmentDefinition</var> be the FragmentDefinition in the document named <var>fragmentSpread</var> refers to.</li>
  1050. <li>For each <var>directive</var> in directives on <var>fragmentDefinition</var>
  1051. <ol>
  1052. <li>If <var>directives</var> does not contain a directive named <var>directive</var>.</li>
  1053. <li>Add <var>directive</var> into <var>directives</var></li>
  1054. </ol>
  1055. </li>
  1056. <li>Return <var>directives</var> </li>
  1057. </ol>
  1058. </div>
  1059. </section>
  1060. </section>
  1061. </section>
  1062. <section id="sec-Type-System">
  1063. <h2><span class="spec-secnum" title="link to this section"><a href="#sec-Type-System">3</a></span>Type System</h2>
  1064. <p>The GraphQL Type system describes the capabilities of a GraphQL server and is used to determine if a query is valid. The type system also describes the input types of query variables to determine if values provided at runtime are valid.</p>
  1065. <p>A GraphQL server&rsquo;s capabilities are referred to as that server&rsquo;s &ldquo;schema&rdquo;. A schema is defined in terms of the types and directives it supports.</p>
  1066. <p>A given GraphQL schema must itself be internally valid. This section describes the rules for this validation process where relevant.</p>
  1067. <p>A GraphQL schema is represented by a root type for each kind of operation: query and mutation; this determines the place in the type system where those operations begin.</p>
  1068. <p>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>
  1069. <p>All directives within a GraphQL schema must have unique names. A directive and a type may share the same name, since there is no ambiguity between them.</p>
  1070. <section id="sec-Type-System.Types">
  1071. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Type-System.Types">3.1</a></span>Types</h3>
  1072. <p>The fundamental unit of any GraphQL Schema is the type. There are eight kinds of types in GraphQL.</p>
  1073. <p>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
  1074. the type specifies the space of valid responses.</p>
  1075. <p>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>
  1076. <p>GraphQL supports two abstract types: interfaces and unions.</p>
  1077. <p>An <code>Interface</code> defines a list of fields; <code>Object</code> types that implement that interface are guaranteed to implement those fields. Whenever the type system claims it will return an interface, it will return a valid implementing
  1078. type.</p>
  1079. <p>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>
  1080. <p>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. The type system might want to define that it returns a list of other types; the <code>List</code> type is provided
  1081. for this reason, and wraps another type. Similarly, the <code>Non-Null</code> type wraps another type, and denotes that the result will never be null. These two types are referred to as &ldquo;wrapping types&rdquo;; non&#8208;wrapping types are
  1082. referred to as &ldquo;base types&rdquo;. A wrapping type has an underlying &ldquo;base type&rdquo;, found by continually unwrapping the type until a base type is found.</p>
  1083. <p>Finally, oftentimes it is useful to provide complex structs as inputs to GraphQL queries; the <code>Input Object</code> type allows the schema to define exactly what data is expected from the client in these queries.</p>
  1084. <section id="sec-Scalars">
  1085. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Scalars">3.1.1</a></span>Scalars</h4>
  1086. <p>As expected by the name, a scalar represents a primitive value in GraphQL. GraphQL responses take the form of a hierarchical tree; the leaves on these trees are GraphQL scalars.</p>
  1087. <p>All GraphQL scalars are representable as strings, though depending on the response format being used, there may be a more appropriate primitive for the given scalar type, and server should use those types when appropriate.</p>
  1088. <p>GraphQL provides a number of built&#8208;in scalars, but type systems can add additional scalars with semantic meaning. For example, a GraphQL system could define a scalar called <code>Time</code> which, while serialized as a string, promises
  1089. to conform to ISO&#8208;8601. When querying a field of type <code>Time</code>, you can then rely on the ability to parse the result with an ISO&#8208;8601 parser and use a client&#8208;specific primitive for time. Another example of a potentially
  1090. useful custom scalar is <code>Url</code>, which serializes as a string, but is guaranteed by the server to be a valid URL.</p>
  1091. <p><strong>Result Coercion</strong></p>
  1092. <p>A GraphQL server, when preparing a field of a given scalar type, must uphold the contract the scalar type describes, either by coercing the value or producing an error.</p>
  1093. <p>For example, a GraphQL server could be preparing a field with the scalar type <code>Int</code> and encounter a floating&#8208;point number. Since the server must not break the contract by yielding a non&#8208;integer, the server should truncate
  1094. the fractional value and only yield the integer value. If the server encountered a boolean <code>true</code> value, it should return <code>1</code>. If the server encountered a string, it may attempt to parse the string for a base&#8208;10 integer
  1095. value. If the server encounters some value that cannot be reasonably coerced to an <code>Int</code>, then it must raise a field error.</p>
  1096. <p>Since this coercion behavior is not observable to clients of the GraphQL server, the precise rules of coercion are left to the implementation. The only requirement is that the server must yield values which adhere to the expected Scalar type.</p>
  1097. <p><strong>Input Coercion</strong></p>
  1098. <p>If a GraphQL server 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 query error must be raised.</p>
  1099. <p>GraphQL has different constant literals to represent integer and floating&#8208;point input values, and coercion rules may apply differently depending on which type of input value is encountered. GraphQL may be parameterized by query variables,
  1100. 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&#8208;point values, they are interpreted as an integer input value if
  1101. they have an empty fractional part (ex. <code>1.0</code>) and otherwise as floating&#8208;point input value.</p>
  1102. <section id="sec-Built-in-Scalars">
  1103. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Built-in-Scalars">3.1.1.1</a></span>Built-in Scalars</h5>
  1104. <p>GraphQL provides a basic set of well&#8208;defined Scalar types. A GraphQL server should support all of these types, and a GraphQL server which provide a type by these names must adhere to the behavior described below.</p>
  1105. <section id="sec-Int">
  1106. <h6><span class="spec-secnum" title="link to this section"><a href="#sec-Int">3.1.1.1.1</a></span>Int</h6>
  1107. <p>The Int scalar type represents a signed 32&#8208;bit numeric non&#8208;fractional values. Response formats that support a 32&#8208;bit integer or a number type should use that type to represent this scalar.</p>
  1108. <p><strong>Result Coercion</strong></p>
  1109. <p>GraphQL servers should coerce non&#8208;int raw values to Int when possible otherwise they must raise a field error. Examples of this may include returning <code>1</code> for the floating&#8208;point number <code>1.0</code>, or <code>2</code> for the string <code>&quot;2&quot;</code>.</p>
  1110. <p><strong>Input Coercion</strong></p>
  1111. <p>When expected as an input type, only integer input values are accepted. All other input values, including strings with numeric content, must raise a query error indicating an incorrect type. If the integer input value represents a value less
  1112. than -2<sup>31</sup> or greater than or equal to 2<sup>31</sup>, a query error should be raised.</p>
  1113. <div class="spec-note">Numeric integer values larger than 32&#8208;bit should either use String or a custom&#8208;defined Scalar type, as not all platforms and transports support encoding integer numbers larger than 32&#8208;bit.</div>
  1114. </section>
  1115. <section id="sec-Float">
  1116. <h6><span class="spec-secnum" title="link to this section"><a href="#sec-Float">3.1.1.1.2</a></span>Float</h6>
  1117. <p>The Float scalar type represents signed double&#8208;precision fractional values as specified by <a href="http://en.wikipedia.org/wiki/IEEE_floating_point">IEEE 754</a>. Response formats that support an appropriate double&#8208;precision number
  1118. type should use that type to represent this scalar.</p>
  1119. <p><strong>Result Coercion</strong></p>
  1120. <p>GraphQL servers should coerce non&#8208;floating&#8208;point raw values to Float when possible 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>2.0</code> for the string <code>&quot;2&quot;</code>.</p>
  1121. <p><strong>Input Coercion</strong></p>
  1122. <p>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
  1123. input values, including strings with numeric content, must raise a query error indicating an incorrect type. If the integer input value represents a value not representable by IEEE 754, a query error should be raised.</p>
  1124. </section>
  1125. <section id="sec-String">
  1126. <h6><span class="spec-secnum" title="link to this section"><a href="#sec-String">3.1.1.1.3</a></span>String</h6>
  1127. <p>The String scalar type represents textual data, represented as UTF&#8208;8 character sequences. The String type is most often used by GraphQL to represent free&#8208;form human&#8208;readable text. All response formats must support string
  1128. representations, and that representation must be used here.</p>
  1129. <p><strong>Result Coercion</strong></p>
  1130. <p>GraphQL servers should coerce non&#8208;string raw values to String when possible otherwise they must raise a field error. Examples of this may include returning the string <code>&quot;true&quot;</code> for a boolean true value, or the string
  1131. <code>&quot;1&quot;</code> for the integer <code>1</code>.</p>
  1132. <p><strong>Input Coercion</strong></p>
  1133. <p>When expected as an input type, only valid UTF&#8208;8 string input values are accepted. All other input values must raise a query error indicating an incorrect type.</p>
  1134. </section>
  1135. <section id="sec-Boolean">
  1136. <h6><span class="spec-secnum" title="link to this section"><a href="#sec-Boolean">3.1.1.1.4</a></span>Boolean</h6>
  1137. <p>The Boolean scalar type represents <code>true</code> or <code>false</code>. Response formats should use a built&#8208;in boolean type if supported; otherwise, they should use their representation of the integers <code>1</code> and <code>0</code>.</p>
  1138. <p><strong>Result Coercion</strong></p>
  1139. <p>GraphQL servers should coerce non&#8208;boolean raw values to Boolean when possible otherwise they must raise a field error. Examples of this may include returning <code>true</code> for any non&#8208;zero number.</p>
  1140. <p><strong>Input Coercion</strong></p>
  1141. <p>When expected as an input type, only boolean input values are accepted. All other input values must raise a query error indicating an incorrect type.</p>
  1142. </section>
  1143. <section id="sec-ID">
  1144. <h6><span class="spec-secnum" title="link to this section"><a href="#sec-ID">3.1.1.1.5</a></span>ID</h6>
  1145. <p>The ID scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type is serialized in the same way as a <code>String</code>; however, it is not intended to be human&#8208;readable. While it
  1146. is often numeric, it should always serialize as a <code>String</code>.</p>
  1147. <p><strong>Result Coercion</strong></p>
  1148. <p>GraphQL is agnostic to ID format, and serializes to string to ensure consistency across many formats ID could represent, from small auto&#8208;increment numbers, to large 128&#8208;bit random numbers, to base64 encoded values, or string values
  1149. of a format like <a href="http://en.wikipedia.org/wiki/Globally_unique_identifier">GUID</a>.</p>
  1150. <p>GraphQL servers should coerce as appropriate given the ID formats they expect, when coercion is not possible they must raise a field error.</p>
  1151. <p><strong>Input Coercion</strong></p>
  1152. <p>When expected as an input type, any string (such as <code>&quot;4&quot;</code>) or integer (such as <code>4</code>) input value should be coerced to ID as appropriate for the ID formats a given GraphQL server expects. Any other input value,
  1153. including float input values (such as <code>4.0</code>), must raise a query error indicating an incorrect type.</p>
  1154. </section>
  1155. </section>
  1156. </section>
  1157. <section id="sec-Objects">
  1158. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Objects">3.1.2</a></span>Objects</h4>
  1159. <p>GraphQL queries are hierarchical and composed, describing a tree of information. While Scalar types describe the leaf values of these hierarchical queries, Objects describe the intermediate levels.</p>
  1160. <p>GraphQL Objects represent a list of named fields, each of which yield a value of a specific type. Object values are serialized as unordered maps, where the queried field names (or aliases) are the keys and the result of evaluating the field is
  1161. the value.</p>
  1162. <p>For example, a type <code>Person</code> could be described as:</p><pre><code>type Person {
  1163. name: String
  1164. age: Int
  1165. picture: Url
  1166. }
  1167. </code></pre>
  1168. <p>Where <code>name</code> is a field that will yield a <code>String</code> value, and <code>age</code> is a field that will yield an <code>Int</code> value, and <code>picture</code> a field that will yield a <code>Url</code> value.</p>
  1169. <p>A query of an object value must select at least one field. This selection of fields will yield an unordered map containing exactly the subset of the object queried. Only fields that are declared on the object type may validly be queried on that
  1170. object.</p>
  1171. <p>For example, selecting all the fields of <code>Person</code>:</p><pre><code>{
  1172. name
  1173. age
  1174. picture
  1175. }
  1176. </code></pre>
  1177. <p>Would yield the object:</p><pre><code>{
  1178. <span class="hljs-string">"name"</span>: <span class="hljs-string">"Mark Zuckerberg"</span>,
  1179. <span class="hljs-string">"age"</span>: <span class="hljs-number">30</span>,
  1180. <span class="hljs-string">"picture"</span>: <span class="hljs-string">"http://some.cdn/picture.jpg"</span>
  1181. }
  1182. </code></pre>
  1183. <p>While selecting a subset of fields:</p><pre><code>{
  1184. name
  1185. age
  1186. }
  1187. </code></pre>
  1188. <p>Must only yield exactly that subset:</p><pre><code>{
  1189. <span class="hljs-string">"name"</span>: <span class="hljs-string">"Mark Zuckerberg"</span>,
  1190. <span class="hljs-string">"age"</span>: <span class="hljs-number">30</span>
  1191. }
  1192. </code></pre>
  1193. <p>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>
  1194. <p>For example, the <code>Person</code> type might include a <code>relationship</code>:</p><pre><code>type Person {
  1195. name: String
  1196. age: Int
  1197. picture: Url
  1198. relationship: Person
  1199. }
  1200. </code></pre>
  1201. <p>Valid queries must supply a nested field set for a field that returns an object, so this query is not valid:</p><pre class="spec-counter-example"><code>{
  1202. name
  1203. relationship
  1204. }
  1205. </code></pre>
  1206. <p>However, this example is valid:</p><pre><code>{
  1207. name
  1208. relationship {
  1209. name
  1210. }
  1211. }
  1212. </code></pre>
  1213. <p>And will yield the subset of each object type queried:</p><pre><code>{
  1214. <span class="hljs-string">"name"</span>: <span class="hljs-string">"Mark Zuckerberg"</span>,
  1215. <span class="hljs-string">"relationship"</span>: {
  1216. <span class="hljs-string">"name"</span>: <span class="hljs-string">"Priscilla Chan"</span>
  1217. }
  1218. }
  1219. </code></pre>
  1220. <p><strong>Result Coercion</strong></p>
  1221. <p>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>
  1222. <p><strong>Input Coercion</strong></p>
  1223. <p>Objects are never valid inputs.</p>
  1224. <section id="sec-Object-Field-Arguments">
  1225. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Object-Field-Arguments">3.1.2.1</a></span>Object Field Arguments</h5>
  1226. <p>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
  1227. input types.</p>
  1228. <p>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><code>type Person {
  1229. name: String
  1230. picture(size: Int): Url
  1231. }
  1232. </code></pre>
  1233. <p>GraphQL queries can optionally specify arguments to their fields to provide these arguments.</p>
  1234. <p>This example query:</p><pre><code>{
  1235. name
  1236. picture(size: 600)
  1237. }
  1238. </code></pre>
  1239. <p>May yield the result:</p><pre><code>{
  1240. <span class="hljs-string">"name"</span>: <span class="hljs-string">"Mark Zuckerberg"</span>,
  1241. <span class="hljs-string">"picture"</span>: <span class="hljs-string">"http://some.cdn/picture_600.jpg"</span>
  1242. }
  1243. </code></pre>
  1244. <p>The type of an object field argument can be any Input type.</p>
  1245. </section>
  1246. <section id="sec-Object-Field-deprecation">
  1247. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Object-Field-deprecation">3.1.2.2</a></span>Object Field deprecation</h5>
  1248. <p>Fields in an object may be marked as deprecated as deemed necessary by the application. It is still legal to query for these fields (to ensure existing clients are not broken by the change), but the fields should be appropriately treated in
  1249. documentation and tooling.</p>
  1250. </section>
  1251. <section id="sec-Object-type-validation">
  1252. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Object-type-validation">3.1.2.3</a></span>Object type validation</h5>
  1253. <p>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>
  1254. <ol>
  1255. <li>The fields of an Object type must have unique names within that Object type; no two fields may share the same name.</li>
  1256. <li>An object type must be a super&#8208;set of all interfaces it implements.
  1257. <ol>
  1258. <li>The object type must include a field of the same name for every field defined in an interface.
  1259. <ol>
  1260. <li>The object field must include an argument of the same name for every argument defined by the interface field.
  1261. <ol>
  1262. <li>The object field argument must accept the same type (invariant) as the interface field argument.</li>
  1263. </ol>
  1264. </li>
  1265. <li>The object field must be of a type which is equal to the interface field.</li>
  1266. </ol>
  1267. </li>
  1268. </ol>
  1269. </li>
  1270. </ol>
  1271. </section>
  1272. </section>
  1273. <section id="sec-Interfaces">
  1274. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Interfaces">3.1.3</a></span>Interfaces</h4>
  1275. <p>GraphQL Interfaces represent a list of named fields and their arguments. GraphQL object can then implement an interface, which guarantees that they will contain the specified fields.</p>
  1276. <p>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>
  1277. <p>For example, an interface may describe a required field and types such as <code>Person</code> or <code>Business</code> may then implement this interface.</p><pre><code>interface NamedEntity {
  1278. name: String
  1279. }</p>
  1280. <p>type Person : NamedEntity {
  1281. name: String
  1282. age: Int
  1283. }</p>
  1284. <p>type Business : NamedEntity {
  1285. name: String
  1286. employeeCount: Int
  1287. }
  1288. </code></pre>
  1289. <p>Fields which yield an interface are useful when one of many Object types are expected, but some fields should be guaranteed.</p>
  1290. <p>To continue the example, a <code>Contact</code> might refer to <code>NamedEntity</code>.</p><pre><code>type Contact {
  1291. entity: NamedEntity
  1292. phoneNumber: String
  1293. address: String
  1294. }
  1295. </code></pre>
  1296. <p>This allows us to write a query for a <code>Contact</code> that can select the common fields.</p><pre><code>{
  1297. entity {
  1298. name
  1299. }
  1300. phoneNumber
  1301. }
  1302. </code></pre>
  1303. <p>When querying for 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>,
  1304. so it is valid. However, the following would not be a valid query:</p><pre class="spec-counter-example"><code>{
  1305. entity {
  1306. name
  1307. age
  1308. }
  1309. phoneNumber
  1310. }
  1311. </code></pre>
  1312. <p>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>; the query can
  1313. express this using a fragment or an inline fragment:</p><pre><code>{
  1314. entity {
  1315. name
  1316. ... on Person {
  1317. age
  1318. }
  1319. },
  1320. phoneNumber
  1321. }
  1322. </code></pre>
  1323. <p><strong>Result Coercion</strong></p>
  1324. <p>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>
  1325. <p><strong>Input Coercion</strong></p>
  1326. <p>Interfaces are never valid inputs.</p>
  1327. <section id="sec-Interface-type-validation">
  1328. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Interface-type-validation">3.1.3.1</a></span>Interface type validation</h5>
  1329. <p>Interface types have the potential to be invalid if incorrectly defined.</p>
  1330. <ol>
  1331. <li>The fields of an Interface type must have unique names within that Interface type; no two fields may share the same name.</li>
  1332. </ol>
  1333. </section>
  1334. </section>
  1335. <section id="sec-Unions">
  1336. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Unions">3.1.4</a></span>Unions</h4>
  1337. <p>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
  1338. are not aware of what unions contain them.</p>
  1339. <p>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 typed fragments.</p>
  1340. <p>For example, we might have the following type system:</p><pre><code>Union SearchResult = Photo | Person</p>
  1341. <p>type Person {
  1342. name: String
  1343. age: Int
  1344. }</p>
  1345. <p>type Photo {
  1346. height: Int
  1347. width: Int
  1348. }</p>
  1349. <p>type SearchQuery {
  1350. firstSearchResult: SearchResult
  1351. }
  1352. </code></pre>
  1353. <p>When querying the <code>firstSearchResult</code> field of type <code>SearchQuery</code>, the query would ask for all fields inside of a fragment indicating the appropriate type. If the query wanted the name if the result was a Person, and the
  1354. height if it was a photo, the following query is invalid, because the union itself defines no fields:</p><pre class="spec-counter-example"><code>{
  1355. firstSearchResult {
  1356. name
  1357. height
  1358. }
  1359. }
  1360. </code></pre>
  1361. <p>Instead, the query would be:</p><pre><code>{
  1362. firstSearchResult {
  1363. ... on Person {
  1364. name
  1365. }
  1366. ... on Photo {
  1367. height
  1368. }
  1369. }
  1370. }
  1371. </code></pre>
  1372. <p><strong>Result Coercion</strong></p>
  1373. <p>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>
  1374. <p><strong>Input Coercion</strong></p>
  1375. <p>Unions are never valid inputs.</p>
  1376. <section id="sec-Union-type-validation">
  1377. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Union-type-validation">3.1.4.1</a></span>Union type validation</h5>
  1378. <p>Union types have the potential to be invalid if incorrectly defined.</p>
  1379. <ol>
  1380. <li>The member types of an Union type must all be Object base types; Scalar, Interface and Union types may not be member types of a Union. Similarly, wrapping types may not be member types of a Union.</li>
  1381. <li>A Union type must define two or more member types.</li>
  1382. </ol>
  1383. </section>
  1384. </section>
  1385. <section id="sec-Enums">
  1386. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Enums">3.1.5</a></span>Enums</h4>
  1387. <p>GraphQL Enums are a variant on the Scalar type, which represents one of a finite set of possible values.</p>
  1388. <p>GraphQL Enums are not references for a numeric value, but are unique values in their own right. They serialize as a string: the name of the represented value.</p>
  1389. <p><strong>Result Coercion</strong></p>
  1390. <p>GraphQL servers must return one of the defined set of possible values, if a reasonable coercion is not possible they must raise a field error.</p>
  1391. <p><strong>Input Coercion</strong></p>
  1392. <p>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 query error.</p>
  1393. <p>Query variable transport serializations which have a different representation for non&#8208;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,
  1394. for most transport serializations that do not, strings may be interpreted as the enum input value with the same name.</p>
  1395. </section>
  1396. <section id="sec-Input-Objects">
  1397. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Input-Objects">3.1.6</a></span>Input Objects</h4>
  1398. <p>Fields can define arguments that the client passes up with the query, to configure their behavior. These inputs can be Strings or Enums, but they sometimes need to be more complex than this.</p>
  1399. <p>The <code>Object</code> type defined above is inappropriate for re&#8208;use here, because <code>Object</code>s can contain fields that express circular references or references to interfaces and unions, neither of which is appropriate for use
  1400. as an input argument. For this reason, input objects have a separate type in the system.</p>
  1401. <p>An <code>Input Object</code> 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>
  1402. <p><strong>Result Coercion</strong></p>
  1403. <p>An input object is never a valid result.</p>
  1404. <p><strong>Input Coercion</strong></p>
  1405. <p>The input to an input object should be an unordered map, otherwise an error should be thrown. The result of the coercion is an unordered map, with an entry for each input field, whose key is the name of the input field. The value of an entry in
  1406. the coerced map is the result of input coercing the value of the entry in the input with the same key; if the input does not have a corresponding entry, the value is the result of coercing null. The input coercion above should be performed according
  1407. to the input coercion rules of the type declared by the input field.</p>
  1408. </section>
  1409. <section id="sec-Lists">
  1410. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Lists">3.1.7</a></span>Lists</h4>
  1411. <p>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 array is serialized as per the
  1412. item type. To denote that a field uses a List type the item type is wrapped in square brackets like this: <code>pets: [Pet]</code>.</p>
  1413. <p><strong>Result Coercion</strong></p>
  1414. <p>GraphQL servers 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 they must raise a field error. In particular, if
  1415. a non&#8208;list is returned, the coercion should fail, as this indicates a mismatch in expectations between the type system and the implementation.</p>
  1416. <p><strong>Input Coercion</strong></p>
  1417. <p>When expected as an input, list values are accepted only when each item in the list can be accepted by the list&rsquo;s item type.</p>
  1418. <p>If the value passed as an input to a list type is <em>not</em> as list, it should be coerced as though the input was a list of size one, where the value passed is the only item in the list. This is to allow inputs that accept a &ldquo;var args&rdquo;
  1419. to declare their input type as a list; if only one argument is passed (a common case), the client can just pass that value rather than constructing the list.</p>
  1420. </section>
  1421. <section id="sec-Non-Null">
  1422. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Non-Null">3.1.8</a></span>Non-Null</h4>
  1423. <p>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&#8208;Null type can be used. This type declares
  1424. an underlying type, and this type acts identically to that underlying type, with the exception that <code>null</code> is not a valid response for the wrapping type. A trailing exclamation mark is used to denote a field that uses a Non&#8208;Null
  1425. type like this: <code>name: String!</code>.</p>
  1426. <p><strong>Result Coercion</strong></p>
  1427. <p>In all of the above result coercion, <code>null</code> was considered a valid value. To coerce the result of a Non Null type, the result coercion of the underlying type should be performed. If that result was not <code>null</code>, then the result
  1428. of coercing the Non Null type is that result. If that result was <code>null</code>, then an error should be raised.</p>
  1429. <p><strong>Input Coercion</strong></p>
  1430. <div class="spec-note">that <code>null</code> is not a valid keyword in GraphQL, so a query cannot look like:</div><pre class="spec-counter-example"><code>{
  1431. field(arg: null)
  1432. }
  1433. </code></pre>
  1434. <p>to indicate that the argument is null. Instead, an argument would be null only if it is passed a variable that is then not set:</p><pre><code>{
  1435. field(arg: $var)
  1436. }
  1437. </code></pre>
  1438. <p>Hence, if the value for a non&#8208;null is hard&#8208;coded in the query, it is always coerced using the input coercion for the wrapped type.</p>
  1439. <p>When a non&#8208;null input has its value set using a variable, the coerced value should be <code>null</code> if the provided value is <code>null</code>-like in the provided representation, or if the provided value is omitted. Otherwise, the coerced
  1440. value is the result of running the wrapped type&rsquo;s input coercion on the provided value.</p>
  1441. </section>
  1442. </section>
  1443. <section id="sec-Type-System.Directives">
  1444. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Type-System.Directives">3.2</a></span>Directives</h3>
  1445. <p>A GraphQL schema includes a list of the directives the execution engine supports.</p>
  1446. <p>GraphQL implementations should provide the <code>@skip</code> and <code>@include</code> directives.</p>
  1447. <section id="sec--skip">
  1448. <h4><span class="spec-secnum" title="link to this section"><a href="#sec--skip">3.2.1</a></span>@skip</h4>
  1449. <p>The <code>@skip</code> directive may be provided for fields or fragments, and allows for conditional exclusion during execution as described by the if argument.</p>
  1450. <p>In this example <code>experimentalField</code> will be queried only if the <code>$someTest</code> is provided a <code>false</code> value.</p><pre><code>query myQuery($someTest: Boolean) {
  1451. experimentalField @skip(if: $someTest)
  1452. }
  1453. </code></pre></section>
  1454. <section id="sec--include">
  1455. <h4><span class="spec-secnum" title="link to this section"><a href="#sec--include">3.2.2</a></span>@include</h4>
  1456. <p>The <code>@include</code> directive may be provided for fields or fragments, and allows for conditional inclusion during execution as described by the if argument.</p>
  1457. <p>In this example <code>experimentalField</code> will be queried only if the <code>$someTest</code> is provided a <code>true</code> value.</p><pre><code>query myQuery($someTest: Boolean) {
  1458. experimentalField @include(if: $someTest)
  1459. }
  1460. </code></pre>
  1461. <p>The <code>@skip</code> directive has precedence over the <code>@include</code> directive should both be provided in the same context.</p>
  1462. </section>
  1463. </section>
  1464. <section id="sec-Starting-types">
  1465. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Starting-types">3.3</a></span>Starting types</h3>
  1466. <p>A GraphQL schema includes types, indicating where query and mutation operations start. This provides the initial entry points into the type system. The query type must always be provided, and is an Object base type. The mutation type is optional;
  1467. if it is null, that means the system does not support mutations. If it is provided, it must be an object base type.</p>
  1468. <p>The fields on the query type indicate what fields are available at the top level of a GraphQL query. For example, a basic GraphQL query like this one:</p><pre><code>query getMe {
  1469. me
  1470. }
  1471. </code></pre>
  1472. <p>Is valid when the type provided for the query starting type has a field named &ldquo;me&rdquo;. Similarly</p><pre><code>mutation setName {
  1473. setName(name: &quot;Zuck&quot;) {
  1474. newName
  1475. }
  1476. }
  1477. </code></pre>
  1478. <p>Is valid when the type provided for the mutation starting type is not null, and has a field named &ldquo;setName&rdquo; with a string argument named &ldquo;name&rdquo;. </p>
  1479. </section>
  1480. </section>
  1481. <section id="sec-Introspection">
  1482. <h2><span class="spec-secnum" title="link to this section"><a href="#sec-Introspection">4</a></span>Introspection</h2>
  1483. <p>A GraphQL server supports introspection over its schema. This schema is queried using GraphQL itself, creating a powerful platform for tool&#8208;building.</p>
  1484. <p>Take an example query for a trivial app. In this case there is a User type with three fields: id, user, and birthday.</p>
  1485. <p>For example, given a server with the following type definition:</p><pre><code>type User {
  1486. id: String
  1487. name: String
  1488. birthday: Date
  1489. }
  1490. </code></pre>
  1491. <p>The query</p><pre><code>{
  1492. __type(name: &quot;User&quot;) {
  1493. name
  1494. fields {
  1495. name
  1496. type {
  1497. name
  1498. }
  1499. }
  1500. }
  1501. }
  1502. </code></pre>
  1503. <p>would return</p><pre><code>{
  1504. <span class="hljs-string">"__type"</span>: {
  1505. <span class="hljs-string">"name"</span> : <span class="hljs-string">"User"</span>,
  1506. <span class="hljs-string">"fields"</span>: [
  1507. {
  1508. <span class="hljs-string">"name"</span>: <span class="hljs-string">"id"</span>,
  1509. <span class="hljs-string">"type"</span>: { <span class="hljs-string">"name"</span>: <span class="hljs-string">"String"</span> }
  1510. },
  1511. {
  1512. <span class="hljs-string">"name"</span>: <span class="hljs-string">"name"</span>,
  1513. <span class="hljs-string">"type"</span>: { <span class="hljs-string">"name"</span>: <span class="hljs-string">"String"</span> }
  1514. },
  1515. {
  1516. <span class="hljs-string">"name"</span>: <span class="hljs-string">"birthday"</span>,
  1517. <span class="hljs-string">"type"</span>: { <span class="hljs-string">"name"</span>: <span class="hljs-string">"Date"</span> }
  1518. },
  1519. ]
  1520. }
  1521. }
  1522. </code></pre>
  1523. <section id="sec-General-Principles">
  1524. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-General-Principles">4.1</a></span>General Principles</h3>
  1525. <section id="sec-Naming-conventions">
  1526. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Naming-conventions">4.1.1</a></span>Naming conventions</h4>
  1527. <p>Types and fields required by the GraphQL introspection system that are used in the same context as user&#8208;defined type and fields are prefixed with two underscores. This in order to avoid naming collisions with user&#8208;defined GraphQL types.
  1528. Conversely, GraphQL type system authors must not define any types, fields, arguments, or any other type system artifact with two leading underscores.</p>
  1529. </section>
  1530. <section id="sec-Documentation">
  1531. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Documentation">4.1.2</a></span>Documentation</h4>
  1532. <p>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 server may return the <code>description</code> field
  1533. using Markdown syntax. Therefore it is recommended that any tool that displays description use a Markdown renderer.</p>
  1534. </section>
  1535. <section id="sec-Deprecation">
  1536. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Deprecation">4.1.3</a></span>Deprecation</h4>
  1537. <p>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>
  1538. <p>Tools built using GraphQL introspection should respect deprecation by discouraging deprecated use through information hiding or developer&#8208;facing warnings.</p>
  1539. </section>
  1540. <section id="sec-Type-Name-Introspection">
  1541. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Type-Name-Introspection">4.1.4</a></span>Type Name Introspection</h4>
  1542. <p>GraphQL supports type name introspection at any point within a query by the meta field <code>__typename: String!</code> when querying against any Object, Interface, or Union. It returns the name of the object type currently being queried.</p>
  1543. <p>This is most often used when querying against Interface or Union types to identify which actual type of the possible types has been returned.</p>
  1544. <p>This field is implicit and does not appear in the fields list in any defined type.</p>
  1545. </section>
  1546. </section>
  1547. <section id="sec-Schema-Introspection">
  1548. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Schema-Introspection">4.2</a></span>Schema Introspection</h3>
  1549. <p>The schema introspection system is accessible from the meta&#8208;fields <code>__schema</code> and <code>__type</code> which are accessible from the type of the root of a query operation.</p><pre><code>__schema : __Schema!
  1550. __type(name: String) : __Type
  1551. </code></pre>
  1552. <p>These fields are implicit and do not appear in the fields list in the root type of the query operation.</p>
  1553. <p>The schema of the GraphQL schema introspection system:</p><pre><code>type __Schema {
  1554. types: [__Type!]!
  1555. queryType: __Type!
  1556. mutationType: __Type
  1557. directives: [__Directive!]!
  1558. }</p>
  1559. <p>type __Type {
  1560. kind: __TypeKind!
  1561. name: String
  1562. description: String</p>
  1563. <h1>OBJECT and INTERFACE only</h1>
  1564. <p>fields(includeDeprecated: Boolean = false): [__Field!]</p>
  1565. <h1>OBJECT only</h1>
  1566. <p>interfaces: [__Type!]</p>
  1567. <h1>INTERFACE and UNION only</h1>
  1568. <p>possibleTypes: [__Type!]</p>
  1569. <h1>ENUM only</h1>
  1570. <p>enumValues(includeDeprecated: Boolean = false): [__EnumValue!]</p>
  1571. <h1>INPUT_OBJECT only</h1>
  1572. <p>inputFields: [__InputValue!]</p>
  1573. <h1>NON_NULL and LIST only</h1>
  1574. <p>ofType: __Type
  1575. }</p>
  1576. <p>type __Field {
  1577. name: String!
  1578. description: String
  1579. args: [__InputValue!]!
  1580. type: __Type!
  1581. isDeprecated: Boolean!
  1582. deprecationReason: String
  1583. }</p>
  1584. <p>type __InputValue {
  1585. name: String!
  1586. description: String
  1587. type: __Type!
  1588. defaultValue: String
  1589. }</p>
  1590. <p>type __EnumValue {
  1591. name: String!
  1592. description: String
  1593. isDeprecated: Boolean!
  1594. deprecationReason: String
  1595. }</p>
  1596. <p>enum __TypeKind {
  1597. SCALAR
  1598. OBJECT
  1599. INTERFACE
  1600. UNION
  1601. ENUM
  1602. INPUT_OBJECT
  1603. LIST
  1604. NON_NULL
  1605. }</p>
  1606. <p>type __Directive {
  1607. name: String!
  1608. description: String
  1609. args: [__InputValue!]!
  1610. onOperation: Boolean!
  1611. onFragment: Boolean!
  1612. onField: Boolean!
  1613. }
  1614. </code></pre>
  1615. <section id="sec-The-__Type-Type">
  1616. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-The-__Type-Type">4.2.1</a></span>The &quot;__Type&quot; Type</h4>
  1617. <p><code>__Type</code> is at the core of the type introspection system. It represents scalars, interfaces, object types, unions, enums in the system.</p>
  1618. <p><code>__Type</code> also represents type modifiers, which are used to modify a type that it refers to (<code>ofType: __Type</code>). This is how we represent lists, non&#8208;nullable types, and the combinations thereof.</p>
  1619. </section>
  1620. <section id="sec-Type-Kinds">
  1621. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Type-Kinds">4.2.2</a></span>Type Kinds</h4>
  1622. <p>There are several different kinds of type. In each kind, different fields are actually valid. These kinds are listed in the <code>__TypeKind</code> enumeration.</p>
  1623. <section id="sec-Scalar">
  1624. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Scalar">4.2.2.1</a></span>Scalar</h5>
  1625. <p>Represents scalar types such as Int, String, and Boolean. Scalars cannot have fields.</p>
  1626. <p>A GraphQL type designer should describe the data format and scalar coercion rules in the description field of any scalar.</p>
  1627. <p>Fields</p>
  1628. <ul>
  1629. <li><code>kind</code> must return <code>__TypeKind.SCALAR</code>.</li>
  1630. <li><code>name</code> must return a String.</li>
  1631. <li><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li>
  1632. <li>All other fields must return <span class="spec-keyword">null</span>.</li>
  1633. </ul>
  1634. </section>
  1635. <section id="sec-Object">
  1636. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Object">4.2.2.2</a></span>Object</h5>
  1637. <p>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>
  1638. <p>Fields</p>
  1639. <ul>
  1640. <li><code>kind</code> must return <code>__TypeKind.OBJECT</code>.</li>
  1641. <li><code>name</code> must return a String.</li>
  1642. <li><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li>
  1643. <li><code>fields</code>: The set of fields query&#8208;able on this type.
  1644. <ul>
  1645. <li>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>
  1646. </ul>
  1647. </li>
  1648. <li><code>interfaces</code>: The set of interfaces that an object implements.</li>
  1649. <li>All other fields must return <span class="spec-keyword">null</span>.</li>
  1650. </ul>
  1651. </section>
  1652. <section id="sec-Union">
  1653. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Union">4.2.2.3</a></span>Union</h5>
  1654. <p>Unions are an abstract types 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>
  1655. <p>Fields</p>
  1656. <ul>
  1657. <li><code>kind</code> must return <code>__TypeKind.UNION</code>.</li>
  1658. <li><code>name</code> must return a String.</li>
  1659. <li><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li>
  1660. <li><code>possibleTypes</code> returns the list of types that can be represented within this union. They must be object types.</li>
  1661. <li>All other fields must return <span class="spec-keyword">null</span>.</li>
  1662. </ul>
  1663. </section>
  1664. <section id="sec-Interface">
  1665. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Interface">4.2.2.4</a></span>Interface</h5>
  1666. <p>Interfaces is 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
  1667. <code>possibleTypes</code>.</p>
  1668. <p>Fields</p>
  1669. <ul>
  1670. <li><code>kind</code> must return <code>__TypeKind.INTERFACE</code>.</li>
  1671. <li><code>name</code> must return a String.</li>
  1672. <li><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li>
  1673. <li><code>fields</code>: The set of fields required by this interface.
  1674. <ul>
  1675. <li>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>
  1676. </ul>
  1677. </li>
  1678. <li><code>possibleTypes</code> returns the list of types that implement this interface. They must be object types.</li>
  1679. <li>All other fields must return <span class="spec-keyword">null</span>.</li>
  1680. </ul>
  1681. </section>
  1682. <section id="sec-Enum">
  1683. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Enum">4.2.2.5</a></span>Enum</h5>
  1684. <p>Enums are special scalars that can only have a defined set of values.</p>
  1685. <p>Fields</p>
  1686. <ul>
  1687. <li><code>kind</code> must return <code>__TypeKind.ENUM</code>.</li>
  1688. <li><code>name</code> must return a String.</li>
  1689. <li><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li>
  1690. <li><code>enumValues</code>: The list of <code>EnumValue</code>. There must be at least one and they must have unique names.
  1691. <ul>
  1692. <li>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>
  1693. </ul>
  1694. </li>
  1695. <li>All other fields must return <span class="spec-keyword">null</span>.</li>
  1696. </ul>
  1697. </section>
  1698. <section id="sec-Input-Object">
  1699. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Input-Object">4.2.2.6</a></span>Input Object</h5>
  1700. <p>Input objects are composite types used as inputs into queries defined as a list of named input values.</p>
  1701. <p>For example the input object <code>Point</code> could be defined as:</p><pre><code>type Point {
  1702. x: Int
  1703. y: Int
  1704. }
  1705. </code></pre>
  1706. <p>Fields</p>
  1707. <ul>
  1708. <li><code>kind</code> must return <code>__TypeKind.INPUT_OBJECT</code>.</li>
  1709. <li><code>name</code> must return a String.</li>
  1710. <li><code>description</code> may return a String or <span class="spec-keyword">null</span>.</li>
  1711. <li><code>inputFields</code>: a list of <code>InputValue</code>.</li>
  1712. <li>All other fields must return <span class="spec-keyword">null</span>.</li>
  1713. </ul>
  1714. </section>
  1715. <section id="sec-List">
  1716. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-List">4.2.2.7</a></span>List</h5>
  1717. <p>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>
  1718. <p>Fields</p>
  1719. <ul>
  1720. <li><code>kind</code> must return <code>__TypeKind.LIST</code>.</li>
  1721. <li><code>ofType</code>: Any type.</li>
  1722. <li>All other fields must return <span class="spec-keyword">null</span>.</li>
  1723. </ul>
  1724. </section>
  1725. <section id="sec-Non-null">
  1726. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Non-null">4.2.2.8</a></span>Non-null</h5>
  1727. <p>GraphQL types are nullable. The value <span class="spec-keyword">null</span> is a valid response for field type.</p>
  1728. <p>A Non&#8208;null type is a type modifier: it wraps another type instance in the <code>ofType</code> field. Non&#8208;null types do not allow <span class="spec-keyword">null</span> as a response, and indicate required inputs for arguments and
  1729. input object fields.</p>
  1730. <ul>
  1731. <li><code>kind</code> must return <code>__TypeKind.NON_NULL</code>.</li>
  1732. <li><code>ofType</code>: Any type except Non&#8208;null.</li>
  1733. <li>All other fields must return <span class="spec-keyword">null</span>.</li>
  1734. </ul>
  1735. </section>
  1736. <section id="sec-Combining-List-and-Non-Null">
  1737. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Combining-List-and-Non-Null">4.2.2.9</a></span>Combining List and Non-Null</h5>
  1738. <p>List and Non&#8208;Null can compose, representing more complex types.</p>
  1739. <p>If the modified type of a List is Non&#8208;Null, then that List may not contain any <span class="spec-keyword">null</span> items.</p>
  1740. <p>If the modified type of a Non&#8208;Null is List, then <span class="spec-keyword">null</span> is not accepted, however an empty list is accepted.</p>
  1741. <p>If the modified type of a List is a List, then each item in the first List is another List of the second List&rsquo;s type.</p>
  1742. <p>A Non&#8208;Null type cannot modify another Non&#8208;Null type. </p>
  1743. </section>
  1744. </section>
  1745. </section>
  1746. </section>
  1747. <section id="sec-Validation">
  1748. <h2><span class="spec-secnum" title="link to this section"><a href="#sec-Validation">5</a></span>Validation</h2>
  1749. <p>GraphQL does not just verify if a request is syntactically correct.</p>
  1750. <p>Prior to execution, it can also verify that a request is valid within the context of a given GraphQL schema. Validation is primarily targeted at development&#8208;time tooling. Any client&#8208;side tooling should return errors and not allow the formulation
  1751. of queries known to violate the type system at a given point in time.</p>
  1752. <p>Total request validation on the server&#8208;side during execution is optional. As schemas and systems change over time existing clients may end up emitting queries that are no longer valid given the current type system. Servers (as described in the
  1753. Execution section of this spec) attempt to satisfy as much as the request as possible and continue to execute in the presence of type system errors rather than cease execution completely.</p>
  1754. <p>For this section of this schema, we will assume the following type system in order to demonstrate examples:</p><pre><code>enum DogCommand { SIT, DOWN, HEEL }</p>
  1755. <p>type Dog : Pet {
  1756. name: String!
  1757. nickname: String
  1758. barkVolume: Int
  1759. doesKnowCommand(dogCommand: DogCommand!) : Boolean!
  1760. isHousetrained(atOtherHomes: Boolean): Boolean!
  1761. }</p>
  1762. <p>interface Sentient {
  1763. name: String!
  1764. }</p>
  1765. <p>interface Pet {
  1766. name: String!
  1767. }</p>
  1768. <p>type Alien : Sentient {
  1769. name: String!
  1770. homePlanet: String
  1771. }</p>
  1772. <p>type Human : Sentient {
  1773. name: String!
  1774. }</p>
  1775. <p>type Cat : Pet {
  1776. name: String!
  1777. nickname: String
  1778. meowVolume: Int
  1779. }</p>
  1780. <p>union CatOrDog = Cat | Dog
  1781. union DogOrHuman = Dog | Human
  1782. union HumanOrAlien = Human | Alien
  1783. </code></pre>
  1784. <section id="sec-Validation.Fields">
  1785. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Validation.Fields">5.1</a></span>Fields</h3>
  1786. <section id="sec-Field-Selections-on-Objects-Interfaces-and-Unions-Types">
  1787. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Field-Selections-on-Objects-Interfaces-and-Unions-Types">5.1.1</a></span>Field Selections on Objects, Interfaces, and Unions Types</h4>
  1788. <p><strong> Formal Specification </strong></p>
  1789. <ul>
  1790. <li>For each <var>selection</var> in the document.</li>
  1791. <li>Let <var>fieldName</var> be the target field of <var>selection</var></li>
  1792. <li><var>fieldName</var> must be defined on type in scope</li>
  1793. </ul>
  1794. <p><strong> Explanatory Text </strong></p>
  1795. <p>The target field of a field selection must defined on the scoped type of the selection set. There are no limitations on alias names.</p>
  1796. <p>For example the following fragment would not pass validation:</p><pre class="spec-counter-example"><code>fragment fieldNotDefined on Dog {
  1797. meowVolume
  1798. }</p>
  1799. <p>fragment aliasedLyingFieldTargetNotDefined on Dog {
  1800. barkVolume: kawVolume
  1801. }
  1802. </code></pre>
  1803. <p>For interfaces, direct field selection can only be done on fields. Fields of concrete implementors is not relevant to the validity of the given interface&#8208;typed selection set.</p>
  1804. <p>For example, the following is valid:</p><pre><code>fragment interfaceFieldSelection on Pet {
  1805. name
  1806. }
  1807. </code></pre>
  1808. <p>and the following is invalid:</p><pre class="spec-counter-example"><code>fragment definedOnImplementorsButNotInterface on Pet {
  1809. nickname
  1810. }
  1811. </code></pre>
  1812. <p>Because fields are not declared on unions, direct field selection on union&#8208;typed selection set. This is true even if concrete implementors of the union define the fieldName.</p>
  1813. <p>For example the following is invalid</p><pre class="spec-counter-example"><code>fragment directFieldSelectionOnUnion on CatOrDog {
  1814. directField
  1815. }</p>
  1816. <p>fragment definedOnImplementorsQueriedOnUnion on CatOrDog {
  1817. name
  1818. }
  1819. </code></pre></section>
  1820. <section id="sec-Field-Selection-Merging">
  1821. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Field-Selection-Merging">5.1.2</a></span>Field Selection Merging</h4>
  1822. <p><strong> Formal Specification </strong></p>
  1823. <ul>
  1824. <li>Let <var>set</var> be any selection set defined in the GraphQL document</li>
  1825. <li>Let <var>setForKey</var> be the set of selections with a given response key in <var>set</var></li>
  1826. <li>All members of <var>setForKey</var> must:
  1827. <ul>
  1828. <li>Have identical target fields</li>
  1829. <li>Have identical sets of arguments.</li>
  1830. <li>Have identical sets of directives.</li>
  1831. </ul>
  1832. </li>
  1833. </ul>
  1834. <p><strong> Explanatory Text </strong></p>
  1835. <p>Selection names are de&#8208;duplicated and merged for validation, but the target field, arguments, and directives must all be identical.</p>
  1836. <p>For human&#8208;curated GraphQL, this rules seem a bit counterintuitive since it appears to be clear developer error. However in the presence of nested fragments or machine&#8208;generated GraphQL, requiring unique selections is a burdensome limitation
  1837. on tool authors.</p>
  1838. <p>The following selections correctly merge:</p><pre><code>fragment mergeIdenticalFields on Dog {
  1839. name
  1840. name
  1841. }</p>
  1842. <p>fragment mergeIdenticalAliasesAndFields on Dog {
  1843. otherName: name
  1844. otherName: name
  1845. }
  1846. </code></pre>
  1847. <p>The following is not able to merge:</p><pre class="spec-counter-example"><code>fragment conflictingBecauseAlias on Dog {
  1848. name: nickname
  1849. name
  1850. }
  1851. </code></pre>
  1852. <p>Identical arguments are also merged if they have identical arguments. Both values and variables can be correctly merged.</p>
  1853. <p>For example the following correctly merge:</p><pre><code>fragment mergeIdenticalFieldsWithIdenticalArgs on Dog {
  1854. doesKnowCommand(dogCommand: SIT)
  1855. doesKnowCommand(dogCommand: SIT)
  1856. }</p>
  1857. <p>fragment mergeIdenticalFieldsWithIdenticalValues on Dog {
  1858. doesKnowCommand(dogCommand: $dogCommand)
  1859. doesKnowCommand(dogCommand: $dogCommand)
  1860. }
  1861. </code></pre>
  1862. <p>The following do not correctly merge:</p><pre class="spec-counter-example"><code>fragment conflictingArgsOnValues on Dog {
  1863. doesKnowCommand(dogCommand: SIT)
  1864. doesKnowCommand(dogCommand: HEEL)
  1865. }</p>
  1866. <p>fragment conflictingArgsValueAndVar on Dog {
  1867. doesKnowCommand(dogCommand: SIT)
  1868. doesKnowCommand(dogCommand: $dogCommand)
  1869. }</p>
  1870. <p>fragment conflictingArgsWithVars on Dog {
  1871. doesKnowCommand(dogCommand: $varOne)
  1872. doesKnowCommand(dogCommand: $varTwo)
  1873. }
  1874. </code></pre>
  1875. <p>The same logic applies to directives. The set of directives on each selection with the same response key in a given scope must be identical.</p>
  1876. <p>The following is valid:</p><pre><code>fragment mergeSameFieldsWithSameDirectives on Dog {
  1877. name @include(if: true)
  1878. name @include(if: true)
  1879. }
  1880. </code></pre>
  1881. <p>and the following is invalid:</p><pre class="spec-counter-example"><code>fragment conflictingDirectiveArgs on Dog {
  1882. name @include(if: true)
  1883. name @include(if: false)
  1884. }
  1885. </code></pre></section>
  1886. <section id="sec-Leaf-Field-Selections">
  1887. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Leaf-Field-Selections">5.1.3</a></span>Leaf Field Selections</h4>
  1888. <p><strong> Formal Specification </strong></p>
  1889. <ul>
  1890. <li>For each <var>selection</var> in the document</li>
  1891. <li>Let <var>selectionType</var> be the result type of <var>selection</var></li>
  1892. <li>If <var>selectionType</var> is a scalar:
  1893. <ul>
  1894. <li>The subselection set of that selection must be empty</li>
  1895. </ul>
  1896. </li>
  1897. <li>If <var>selectionType</var> is an interface, union, or object
  1898. <ul>
  1899. <li>The subselection set of that selection must NOT BE empty</li>
  1900. </ul>
  1901. </li>
  1902. </ul>
  1903. <p><strong> Explanatory Text </strong></p>
  1904. <p>Field selections on scalars are never allowed: scalars are the leaf nodes of any GraphQL query.</p>
  1905. <p>The following is valid.</p><pre><code>fragment scalarSelection: Dog {
  1906. barkVolume
  1907. }
  1908. </code></pre>
  1909. <p>The following is invalid.</p><pre class="spec-counter-example"><code>fragment scalarSelectionsNotAllowedOnBoolean : Dog {
  1910. barkVolume {
  1911. sinceWhen
  1912. }
  1913. }
  1914. </code></pre>
  1915. <p>Conversely the leaf field selections of GraphQL queries must be scalars. Leaf selections on objects, interfaces, and unions without subfields are disallowed.</p>
  1916. <p>Let&rsquo;s assume the following query root type of the schema:</p><pre><code>type QueryRoot {
  1917. human: Human
  1918. pet: Pet
  1919. catOrDog: CatOrDog
  1920. }
  1921. </code></pre>
  1922. <p>The following examples are invalid</p><pre class="spec-counter-example"><code>query directQueryOnObjectWithoutSubFields {
  1923. human
  1924. }</p>
  1925. <p>query directQueryOnInterfaceWithoutSubFields {
  1926. pet
  1927. }</p>
  1928. <p>query directQueryOnUnionWithoutSubFields {
  1929. catOrDog
  1930. }
  1931. </code></pre></section>
  1932. </section>
  1933. <section id="sec-Validation.Arguments">
  1934. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Validation.Arguments">5.2</a></span>Arguments</h3>
  1935. <p>Arguments are provided to both fields and directives. The following validation rules apply in both cases.</p>
  1936. <section id="sec-Argument-Names">
  1937. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Argument-Names">5.2.1</a></span>Argument Names</h4>
  1938. <p><strong> Formal Specification </strong></p>
  1939. <ul>
  1940. <li>For each <var>argument</var> in the document</li>
  1941. <li>Let <var>argumentName</var> be the Name of <var>argument</var>.</li>
  1942. <li>Let <var>argumentDefinition</var> be the argument definition provided by the parent field or definition named <var>argumentName</var>.</li>
  1943. <li><var>argumentDefinition</var> must exist.</li>
  1944. </ul>
  1945. <p><strong> Explanatory Text </strong></p>
  1946. <p>Every argument provided to a field or directive must be defined in the set of possible arguments of that field or directive.</p>
  1947. <p>For example the following are valid:</p><pre><code>fragment argOnRequiredArg on Dog {
  1948. doesKnowCommand(dogCommand: SIT)
  1949. }</p>
  1950. <p>fragment argOnOptional on Dog {
  1951. isHousetrained(atOtherHomes: true) @include(if: true)
  1952. }
  1953. </code></pre>
  1954. <p>the following is invalid since <code>command</code> is not defined on <code>DogCommand</code>.</p><pre class="spec-counter-example"><code>fragment invalidArgName on Dog {
  1955. doesKnowCommand(command: CLEAN_UP_HOUSE)
  1956. }
  1957. </code></pre>
  1958. <p>and this is also invalid as <code>unless</code> is not defined on <code>@include</code>.</p><pre class="spec-counter-example"><code>fragment invalidArgName on Dog {
  1959. isHousetrained(atOtherHomes: true) @include(unless: false)
  1960. }
  1961. </code></pre>
  1962. <p>In order to explore more complicated argument examples, let&rsquo;s add the following to our type system:</p><pre><code>type Arguments {
  1963. multipleReqs(x: Int!, y: Int!)
  1964. booleanArgField(booleanArg: Boolean)
  1965. floatArgField(floatArg: Float)
  1966. intArgField(intArg: Int)
  1967. nonNullBooleanArgField(nonNullBooleanArg: Boolean!)
  1968. }
  1969. </code></pre>
  1970. <p>Order does not matter in arguments. Therefore both the following example are valid.</p><pre><code>fragment multipleArgs on Arguments {
  1971. multipleReqs(x: 1, y: 2)
  1972. }</p>
  1973. <p>fragment multipleArgsReverseOrder on Arguments {
  1974. multipleReqs(y: 1, x: 2)
  1975. }
  1976. </code></pre></section>
  1977. <section id="sec-Argument-Values-Type-Correctness">
  1978. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Argument-Values-Type-Correctness">5.2.2</a></span>Argument Values Type Correctness</h4>
  1979. <section id="sec-Compatible-Values">
  1980. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Compatible-Values">5.2.2.1</a></span>Compatible Values</h5>
  1981. <p><strong> Formal Specification </strong></p>
  1982. <ul>
  1983. <li>For each <var>argument</var> in the document</li>
  1984. <li>Let <var>value</var> be the Value of <var>argument</var></li>
  1985. <li>If <var>value</var> is not a Variable
  1986. <ul>
  1987. <li>Let <var>argumentName</var> be the Name of <var>argument</var>.</li>
  1988. <li>Let <var>argumentDefinition</var> be the argument definition provided by the parent field or definition named <var>argumentName</var>.</li>
  1989. <li>Let <var>type</var> be the type expected by <var>argumentDefinition</var>.</li>
  1990. <li>The type of <var>literalArgument</var> must be coercible to <var>type</var>.</li>
  1991. </ul>
  1992. </li>
  1993. </ul>
  1994. <p><strong> Explanatory Text </strong></p>
  1995. <p>Literal values must be compatible with the type defined by the argument they are being provided to, as per the coercion rules defined in the Type System chapter.</p>
  1996. <p>For example, an Int can be coerced into a Float.</p><pre><code>fragment goodBooleanArg on Arguments {
  1997. booleanArgField(booleanArg: true)
  1998. }</p>
  1999. <p>fragment coercedIntIntoFloatArg on Arguments {
  2000. floatArgField(floatArg: 1)
  2001. }
  2002. </code></pre>
  2003. <p>An incoercible conversion, is string to int. Therefore, the following example is invalid.</p><pre class="spec-counter-example"><code>fragment stringIntoInt on Arguments {
  2004. intArgField(intArg: &quot;3&quot;)
  2005. }
  2006. </code></pre></section>
  2007. <section id="sec-Required-Arguments">
  2008. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Required-Arguments">5.2.2.2</a></span>Required Arguments</h5>
  2009. <ul>
  2010. <li>For each Field or Directive in the document.</li>
  2011. <li>Let <var>arguments</var> be the arguments provided by the Field or Directive.</li>
  2012. <li>Let <var>argumentDefinitions</var> be the set of argument definitions of that Field or Directive.</li>
  2013. <li>For each <var>definition</var> in <var>argumentDefinitions</var>
  2014. <ul>
  2015. <li>Let <var>type</var> be the expected type of <var>definition</var></li>
  2016. <li>If <var>type</var> is Non&#8208;Null
  2017. <ul>
  2018. <li>Let <var>argumentName</var> be the name of <var>definition</var></li>
  2019. <li>Let <var>argument</var> be the argument in <var>arguments</var> named <var>argumentName</var></li>
  2020. <li><var>argument</var> must exist.</li>
  2021. </ul>
  2022. </li>
  2023. </ul>
  2024. </li>
  2025. </ul>
  2026. <p><strong> Explanatory Text </strong></p>
  2027. <p>Arguments can be required. Arguments are required if the type of the argument is non&#8208;null. If it is not non&#8208;null, the argument is optional.</p>
  2028. <p>For example the following are valid:</p><pre><code>fragment goodBooleanArg on Arguments {
  2029. booleanArgField(booleanArg: true)
  2030. }</p>
  2031. <p>fragment goodNonNullArg on Arguments {
  2032. nonNullBooleanArgField(nonNullBooleanArg: true)
  2033. }
  2034. </code></pre>
  2035. <p>The argument can be omitted from a field with a nullable argument.</p>
  2036. <p>Therefore the following query is valid:</p><pre><code>fragment goodBooleanArgDefault on Arguments {
  2037. booleanArgField
  2038. }
  2039. </code></pre>
  2040. <p>but this is not valid on a non&#8208;null argument.</p><pre class="spec-counter-example"><code>fragment missingRequiredArg on Arguments {
  2041. notNullBooleanArgField
  2042. }
  2043. </code></pre></section>
  2044. </section>
  2045. </section>
  2046. <section id="sec-Validation.Fragments">
  2047. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Validation.Fragments">5.3</a></span>Fragments</h3>
  2048. <section id="sec-Fragment-Declarations">
  2049. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Fragment-Declarations">5.3.1</a></span>Fragment Declarations</h4>
  2050. <section id="sec-Fragment-Spread-Type-Existence">
  2051. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Fragment-Spread-Type-Existence">5.3.1.1</a></span>Fragment Spread Type Existence</h5>
  2052. <p><strong> Formal Specification </strong></p>
  2053. <ul>
  2054. <li>For each named spread <var>namedSpread</var> in the document</li>
  2055. <li>Let <var>fragment</var> be the target of <var>namedSpread</var></li>
  2056. <li>The target type of <var>fragment</var> must be defined in the schema</li>
  2057. </ul>
  2058. <p><strong> Explanatory Text </strong></p>
  2059. <p>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 query does not validate.</p>
  2060. <p>For example the following fragments are valid:</p><pre><code>fragment correctType on Dog {
  2061. name
  2062. }</p>
  2063. <p>fragment inlineFragment on Dog {
  2064. ... on Dog {
  2065. name
  2066. }
  2067. }
  2068. </code></pre>
  2069. <p>and the following do not validate:</p><pre class="spec-counter-example"><code>fragment notOnExistingType on NotInSchema {
  2070. name
  2071. }</p>
  2072. <p>fragment inlineNotExistingType on Dog {
  2073. ... on NotInSchema {
  2074. name
  2075. }
  2076. }
  2077. </code></pre></section>
  2078. <section id="sec-Fragments-On-Composite-Types">
  2079. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Fragments-On-Composite-Types">5.3.1.2</a></span>Fragments On Composite Types</h5>
  2080. <p><strong> Formal Specification </strong></p>
  2081. <ul>
  2082. <li>For each <var>fragment</var> defined in the document.</li>
  2083. <li>The target type of fragment must be have kind <span class="spec-nt">UNION</span>, <span class="spec-nt">INTERFACE</span>, or <span class="spec-nt">OBJECT</span>.</li>
  2084. </ul>
  2085. <p><strong> Explanatory Text </strong></p>
  2086. <p>Fragments can only be declared on unions, interfaces, and objects. They are invalid on scalars. They can only be applied on non&#8208;leaf fields. This rule applies to both inline and named fragments.</p>
  2087. <p>The following fragment declarations are valid:</p><pre><code>fragment fragOnObject on Dog {
  2088. name
  2089. }</p>
  2090. <p>fragment fragOnInterface on Pet {
  2091. name
  2092. }</p>
  2093. <p>fragment fragOnUnion on CatOrDog {
  2094. ... on Dog {
  2095. name
  2096. }
  2097. }
  2098. </code></pre>
  2099. <p>and the following are invalid:</p><pre class="spec-counter-example"><code>fragment fragOnScalar on Int {
  2100. something
  2101. }</p>
  2102. <p>fragment inlineFragOnScalar on Dog {
  2103. ... on Boolean {
  2104. somethingElse
  2105. }
  2106. }
  2107. </code></pre></section>
  2108. <section id="sec-Fragments-Must-Be-Used">
  2109. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Fragments-Must-Be-Used">5.3.1.3</a></span>Fragments Must Be Used</h5>
  2110. <p><strong> Formal Specification </strong></p>
  2111. <ul>
  2112. <li>For each <var>fragment</var> defined in the document.</li>
  2113. <li><var>fragment</var> must be be the target of at least one spread in the document</li>
  2114. </ul>
  2115. <p><strong> Explanatory Text </strong></p>
  2116. <p>Defined fragments must be used within a query document.</p>
  2117. <p>For example the following is an invalid query document:</p><pre class="spec-counter-example"><code>fragment nameFragment on Dog { # unused
  2118. name
  2119. }</p>
  2120. <p>{
  2121. dog {
  2122. name
  2123. }
  2124. }
  2125. </code></pre></section>
  2126. </section>
  2127. <section id="sec-Fragment-Spreads">
  2128. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Fragment-Spreads">5.3.2</a></span>Fragment Spreads</h4>
  2129. <p>Field selection is also determined by spreading fragments into one another. The selection set of the target fragment is unioned with the selection set at the level at which the target fragment is referenced.</p>
  2130. <section id="sec-Fragment-spread-target-defined">
  2131. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Fragment-spread-target-defined">5.3.2.1</a></span>Fragment spread target defined</h5>
  2132. <p><strong> Formal Specification </strong></p>
  2133. <ul>
  2134. <li>For every <var>namedSpread</var> in the document.</li>
  2135. <li>Let <var>fragment</var> be the target of <var>namedSpread</var></li>
  2136. <li><var>fragment</var> must be defined in the document</li>
  2137. </ul>
  2138. <p><strong> Explanatory Text </strong></p>
  2139. <p>Named fragment spreads must refer to fragments defined within the document. If the target of a spread is not defined, this is an error:</p><pre class="spec-counter-example"><code>{
  2140. dog {
  2141. ...undefinedFragment
  2142. }
  2143. }
  2144. </code></pre></section>
  2145. <section id="sec-Fragment-spreads-must-not-form-cycles">
  2146. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Fragment-spreads-must-not-form-cycles">5.3.2.2</a></span>Fragment spreads must not form cycles</h5>
  2147. <p><strong> Formal Specification </strong></p>
  2148. <ul>
  2149. <li>For each <var>fragmentDefinition</var> in the document</li>
  2150. <li>Let <var>visited</var> be the empty set.</li>
  2151. <li><span class="spec-call">DetectCycles(<var>fragmentDefinition</var>, <var>visited</var>)</span></li>
  2152. </ul>
  2153. <p><span class="spec-call">DetectCycles(<var>fragmentDefinition</var>, <var>visited</var>)</span> :</p>
  2154. <ul>
  2155. <li>Let <var>spreads</var> be all fragment spread descendants of <var>fragmentDefinition</var></li>
  2156. <li>For each <var>spread</var> in <var>spreads</var>
  2157. <ul>
  2158. <li><var>visited</var> must not contain <var>spread</var></li>
  2159. <li>Let <var>nextVisited</var> be the set including <var>spread</var> and members of <var>visited</var></li>
  2160. <li>Let <var>nextFragmentDefinition</var> be the target of <var>spread</var></li>
  2161. <li><span class="spec-call">DetectCycles(<var>nextFragmentDefinition</var>, <var>nextVisited</var>)</span></li>
  2162. </ul>
  2163. </li>
  2164. </ul>
  2165. <p><strong> Explanatory Text </strong></p>
  2166. <p>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>
  2167. <p>This invalidates fragments that would result in an infinite spread:</p><pre class="spec-counter-example"><code>{
  2168. dog {
  2169. ...nameFragment
  2170. }
  2171. }</p>
  2172. <p>fragment nameFragment on Dog {
  2173. name
  2174. ...barkVolumeFragment
  2175. }</p>
  2176. <p>fragment barkVolumeFragment on Dog {
  2177. barkVolume
  2178. ...nameFragment
  2179. }
  2180. </code></pre>
  2181. <p>If the above fragments were inlined, this would result in the infinitely large:</p><pre class="spec-counter-example"><code>{
  2182. dog {
  2183. name
  2184. barkVolume
  2185. name
  2186. barkVolume
  2187. name
  2188. barkVolume
  2189. name</p>
  2190. <h1>forever...</h1>
  2191. <p>}
  2192. }
  2193. </code></pre>
  2194. <p>This also invalidates fragments that would result in an infinite recursion when executed against cyclic data:</p><pre class="spec-counter-example"><code>{
  2195. dog {
  2196. ...dogFragment
  2197. }
  2198. }</p>
  2199. <p>fragment dogFragment on Dog {
  2200. name
  2201. owner {
  2202. ...ownerFragment
  2203. }
  2204. }</p>
  2205. <p>fragment ownerFragment on Dog {
  2206. name
  2207. pets {
  2208. ...dogFragment
  2209. }
  2210. }
  2211. </code></pre></section>
  2212. <section id="sec-Fragment-spread-is-possible">
  2213. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Fragment-spread-is-possible">5.3.2.3</a></span>Fragment spread is possible</h5>
  2214. <p><strong> Formal Specification </strong></p>
  2215. <ul>
  2216. <li>For each <var>spread</var> (named or inline) in defined in the document.</li>
  2217. <li>Let <var>fragment</var> be the target of <var>spread</var></li>
  2218. <li>Let <var>fragmentType</var> be the type condition of <var>fragment</var></li>
  2219. <li>Let <var>parentType</var> be the type of the selection set containing <var>spread</var></li>
  2220. <li>Let <var>applicableTypes</var> be the intersection of <span class="spec-call"><a href="#GetPossibleTypes()">GetPossibleTypes</a>(<var>fragmentType</var>)</span> and <span class="spec-call"><a href="#GetPossibleTypes()">GetPossibleTypes</a>(<var>parentType</var>)</span></li>
  2221. <li><var>applicableTypes</var> must not be empty.</li>
  2222. </ul>
  2223. <div class="spec-algo" id="GetPossibleTypes()"><span class="spec-call"><a href="#GetPossibleTypes()">GetPossibleTypes</a>(<var>type</var>)</span>
  2224. <ol>
  2225. <li>If <var>type</var> is an object type, return a set containing <var>type</var></li>
  2226. <li>If <var>type</var> is an interface type, return the set of types implementing <var>type</var></li>
  2227. <li>If <var>type</var> is a union type, return the set of possible types of <var>type</var></li>
  2228. </ol>
  2229. </div>
  2230. <p><strong> Explanatory Text </strong></p>
  2231. <p>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
  2232. the parent type.</p>
  2233. <p>and the following valid fragments:</p>
  2234. <section id="sec-Object-Spreads-In-Object-Scope">
  2235. <h6><span class="spec-secnum" title="link to this section"><a href="#sec-Object-Spreads-In-Object-Scope">5.3.2.3.1</a></span>Object Spreads In Object Scope</h6>
  2236. <p>In the scope of a object type, the only valid object type fragment spread is one that applies to the same type that is in scope.</p>
  2237. <p>For example</p><pre><code>fragment dogFragment on Dog {
  2238. ... on Dog {
  2239. barkVolume
  2240. }
  2241. }
  2242. </code></pre>
  2243. <p>and the following is invalid</p><pre class="spec-counter-example"><code>fragment catInDogFragmentInvalid on Dog {
  2244. ... on Cat {
  2245. meowVolume
  2246. }
  2247. }
  2248. </code></pre></section>
  2249. <section id="sec-Abstract-Spreads-in-Object-Scope">
  2250. <h6><span class="spec-secnum" title="link to this section"><a href="#sec-Abstract-Spreads-in-Object-Scope">5.3.2.3.2</a></span>Abstract Spreads in Object Scope</h6>
  2251. <p>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>
  2252. <p>For example</p><pre><code>fragment petNameFragment on Pet {
  2253. name
  2254. }</p>
  2255. <p>fragment interfaceWithinObjectFragment on Dog {
  2256. ...petNameFragment
  2257. }
  2258. </code></pre>
  2259. <p>is valid because <span class="spec-nt">Dog</span> implements Pet.</p>
  2260. <p>Likewise</p><pre><code>fragment catOrDogNameFragment on CatOrDog {
  2261. ... on Cat {
  2262. meowVolume
  2263. }
  2264. }</p>
  2265. <p>fragment unionWithObjectFragment on Dog {
  2266. ...CatOrDogFragment
  2267. }
  2268. </code></pre>
  2269. <p>is valid because <span class="spec-nt">Dog</span> is a member of the <span class="spec-nt">CatOrDog</span> union. It is worth noting that if one inspected the contents of the <span class="spec-nt">CatOrDogNameFragment</span> you could note
  2270. that the 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>
  2271. </section>
  2272. <section id="sec-Object-Spreads-In-Abstract-Scope">
  2273. <h6><span class="spec-secnum" title="link to this section"><a href="#sec-Object-Spreads-In-Abstract-Scope">5.3.2.3.3</a></span>Object Spreads In Abstract Scope</h6>
  2274. <p>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 the that interface or union.</p>
  2275. <p>For example, the following fragments are valid:</p><pre><code>fragment petFragment on Pet {
  2276. name
  2277. ... on Dog {
  2278. barkVolume
  2279. }
  2280. }</p>
  2281. <p>fragment catOrDogFragment on CatOrDog {
  2282. ... on Cat {
  2283. meowVolume
  2284. }
  2285. }
  2286. </code></pre>
  2287. <p><var>petFragment</var> is valid because <span class="spec-nt">Dog</span> implements the interface <span class="spec-nt">Pet</span>. <var>catOrDogFragment</var> is valid because <span class="spec-nt">Cat</span> is a member of the <span class="spec-nt">CatOrDog</span> union.</p>
  2288. <p>By contrast the following fragments are invalid:</p><pre class="spec-counter-example"><code>fragment sentientFragment on Sentient {
  2289. ... on Dog {
  2290. barkVolume
  2291. }
  2292. }</p>
  2293. <p>fragment humanOrAlienFragment on HumanOrAlien {
  2294. ... on Cat {
  2295. meowVolume
  2296. }
  2297. }
  2298. </code></pre>
  2299. <p><span class="spec-nt">Dog</span> does not implement the interface <span class="spec-nt">Sentient</span> and therefore <var>sentientFragment</var> can never return meaningful results. Therefore the fragment is invalid. Likewise <span class="spec-nt">Cat</span> is not a member of the union <span class="spec-nt">HumanOrAlien</span>, and it can also never return meaningful results, making it invalid.</p>
  2300. </section>
  2301. <section id="sec-Abstract-Spreads-in-Abstract-Scope">
  2302. <h6><span class="spec-secnum" title="link to this section"><a href="#sec-Abstract-Spreads-in-Abstract-Scope">5.3.2.3.4</a></span>Abstract Spreads in Abstract Scope</h6>
  2303. <p>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>
  2304. <p>So for example</p><pre><code>fragment unionWithInterface on Pet {
  2305. ...dogOrHumanFragment
  2306. }</p>
  2307. <p>fragment dogOrHumanFragment on DogOrHuman {
  2308. ... on Dog {
  2309. barkVolume
  2310. }
  2311. }
  2312. </code></pre>
  2313. <p>is consider valid because <span class="spec-nt">Dog</span> implements interface <span class="spec-nt">Pet</span> and is a member of <span class="spec-nt">DogOrHuman</span>.</p>
  2314. <p>However</p><pre class="spec-counter-example"><code>fragment nonIntersectingInterfaces on Pet {
  2315. ...sentientFragment
  2316. }</p>
  2317. <p>fragment sentientFragment on Sentient {
  2318. name
  2319. }
  2320. </code></pre>
  2321. <p>is not valid because there exists no type that implements both <span class="spec-nt">Pet</span> and <span class="spec-nt">Sentient</span>.</p>
  2322. </section>
  2323. </section>
  2324. </section>
  2325. </section>
  2326. <section id="sec-Validation.Directives">
  2327. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Validation.Directives">5.4</a></span>Directives</h3>
  2328. <section id="sec-Directives-Are-Defined">
  2329. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Directives-Are-Defined">5.4.1</a></span>Directives Are Defined</h4>
  2330. <p><strong> Formal Specification </strong></p>
  2331. <ul>
  2332. <li>For every <var>directive</var> in a document.</li>
  2333. <li>Let <var>directiveName</var> be the name of <var>directive</var>.</li>
  2334. <li>Let <var>directiveDefinition</var> be the directive named <var>directiveName</var>.</li>
  2335. <li><var>directiveDefinition</var> must exist.</li>
  2336. </ul>
  2337. <p><strong> Explanatory Text </strong></p>
  2338. <p>GraphQL servers define what directives they support. For each usage of a directive, the directive must be available on that server.</p>
  2339. </section>
  2340. </section>
  2341. <section id="sec-Validation.Operations">
  2342. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Validation.Operations">5.5</a></span>Operations</h3>
  2343. <section id="sec-Validation.Operations.Variables">
  2344. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Validation.Operations.Variables">5.5.1</a></span>Variables</h4>
  2345. <section id="sec-Variable-Default-Values-Are-Correctly-Typed">
  2346. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Variable-Default-Values-Are-Correctly-Typed">5.5.1.1</a></span>Variable Default Values Are Correctly Typed</h5>
  2347. <p><strong> Formal Specification </strong></p>
  2348. <ul>
  2349. <li>For every <var>operation</var> in a document</li>
  2350. <li>For every <var>variable</var> on each <var>operation</var>
  2351. <ul>
  2352. <li>Let <var>variableType</var> be the type of <var>variable</var></li>
  2353. <li>If <var>variableType</var> is non&#8208;null it cannot have a default value</li>
  2354. <li>If <var>variable</var> has a default value it must be of the same types or able to be coerced to <var>variableType</var></li>
  2355. </ul>
  2356. </li>
  2357. </ul>
  2358. <p><strong> Explanatory Text </strong></p>
  2359. <p>Variable defined by operations are allowed to define default values if the type of that variable not non&#8208;null.</p>
  2360. <p>For example the following query will pass validation.</p><pre><code>query houseTrainedQuery($atOtherHomes: Boolean = true) {
  2361. dog {
  2362. isHousetrained(atOtherHomes: $atOtherHomes)
  2363. }
  2364. }
  2365. </code></pre>
  2366. <p>However if the variable is defined as non&#8208;null, default values are unreachable. Therefore queries such as the following fail validation</p><pre class="spec-counter-example"><code>query houseTrainedQuery($atOtherHomes: Boolean! = true) {
  2367. dog {
  2368. isHousetrained(atOtherHomes: $atOtherHomes)
  2369. }
  2370. }
  2371. </code></pre>
  2372. <p>Default values must be compatible with the types of variables. Types much match or they must be coercible to the type.</p>
  2373. <p>Non&#8208;matching types fail, such as in the following example:</p><pre class="spec-counter-example"><code>query houseTrainedQuery($atOtherHomes: Boolean = &quot;true&quot;) {
  2374. dog {
  2375. isHousetrained(atOtherHomes: $atOtherHomes)
  2376. }
  2377. }
  2378. </code></pre>
  2379. <p>However if a type is coercible the query will pass validation.</p>
  2380. <p>For example:</p><pre><code>query intToFloatQuery($floatVar: Float = 1) {
  2381. arguments {
  2382. floatArgField(floatArg: $floatVar)
  2383. }
  2384. }
  2385. </code></pre></section>
  2386. <section id="sec-Variables-Are-Input-Types">
  2387. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Variables-Are-Input-Types">5.5.1.2</a></span>Variables Are Input Types</h5>
  2388. <p><strong> Formal Specification </strong></p>
  2389. <ul>
  2390. <li>For every <var>operation</var> in a <var>document</var></li>
  2391. <li>For every <var>variable</var> on each <var>operation</var>
  2392. <ul>
  2393. <li>Let <var>variableType</var> be the type of <var>variable</var></li>
  2394. <li><var>variableType</var> must of kind <span class="spec-nt">SCALAR</span>, <span class="spec-nt">ENUM</span> or <span class="spec-nt">INPUT_OBJECT</span></li>
  2395. </ul>
  2396. </li>
  2397. </ul>
  2398. <p><strong> Explanatory Text </strong></p>
  2399. <p>Variables can only be scalars, enums, input objects, or lists and non&#8208;null variants of those types. These are known as input types. Object, unions, and interfaces cannot be used as inputs.</p>
  2400. <p>The following queries are valid:</p><pre><code>query takesBoolean($atOtherHomes: Boolean) {</p>
  2401. <h1>...</h1>
  2402. <p>}</p>
  2403. <p>query takesComplexInput($complexInput: ComplexInput) {</p>
  2404. <h1>...</h1>
  2405. <p>}</p>
  2406. <p>query TakesListOfBooleanBang($booleans: [Boolean!]) {</p>
  2407. <h1>...</h1>
  2408. <p>}
  2409. </code></pre>
  2410. <p>The following queries are invalid:</p><pre class="spec-counter-example"><code>query takesCat($cat: Cat) {</p>
  2411. <h1>...</h1>
  2412. <p>}</p>
  2413. <p>query takesDogBang($dog: Dog!) {</p>
  2414. <h1>...</h1>
  2415. <p>}</p>
  2416. <p>query takesListOfPet($pets: [Pet]) {</p>
  2417. <h1>...</h1>
  2418. <p>}</p>
  2419. <p>query takesCatOrDog($catOrDog: CatOrDog) {</p>
  2420. <h1>...</h1>
  2421. <p>}
  2422. </code></pre></section>
  2423. <section id="sec-All-Variable-Uses-Defined">
  2424. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-All-Variable-Uses-Defined">5.5.1.3</a></span>All Variable Uses Defined</h5>
  2425. <p><strong> Formal Specification </strong></p>
  2426. <ul>
  2427. <li>For each <var>operation</var> in a document
  2428. <ul>
  2429. <li>For each <var>variableUsage</var> in scope, variable must be operation&rsquo;s variable list.</li>
  2430. <li>Let <var>fragments</var> be every fragment reference by that operation transitively</li>
  2431. <li>For each <var>fragment</var> in <var>fragments</var>
  2432. <ul>
  2433. <li>For each <var>variableUsage</var> in scope of <var>fragment</var>, variable must be <var>operation</var>&lsquo;s variable list.</li>
  2434. </ul>
  2435. </li>
  2436. </ul>
  2437. </li>
  2438. </ul>
  2439. <p><strong> Explanatory Text </strong></p>
  2440. <p>Variables are scoped on a per&#8208;operation basis. That means that any variable used within the context of a operation must be defined at the top level of that operation</p>
  2441. <p>For example:</p><pre><code>query variableIsDefined($atOtherHomes: Boolean) {
  2442. dog {
  2443. isHousetrained(atOtherHomes: $booleanArg)
  2444. }
  2445. }
  2446. </code></pre>
  2447. <p>is valid. $<var>atOtherHomes</var> is defined by the operation.</p>
  2448. <p>By contrast the following query is invalid:</p><pre class="spec-counter-example"><code>query variableIsNotDefined {
  2449. dog {
  2450. isHousetrained(atOtherHomes: $atOtherHomes)
  2451. }
  2452. }
  2453. </code></pre>
  2454. <p>$<var>atOtherHomes</var> is not defined by the operation.</p>
  2455. <p>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
  2456. definitions in all of those operations.</p>
  2457. <p>For example the following is valid:</p><pre><code>query variableIsDefinedUsedInSingleFragment($atOtherHomes: Boolean) {
  2458. dog {
  2459. ...isHousetrainedFragment
  2460. }
  2461. }</p>
  2462. <p>fragment isHousetrainedFragment on Dog {
  2463. isHousetrained(atOtherHomes: $atOtherHomes}
  2464. }
  2465. </code></pre>
  2466. <p>since <var>isHousetrainedFragment</var> is used within the context of the operation <var>variableIsDefinedUsedInSingleFragment</var> and the variable is defined by that operation.</p>
  2467. <p>On the contrary is a fragment is included within an operation that does not define a referenced variable, this is a validation error.</p><pre class="spec-counter-example"><code>query variableIsNotDefinedUsedInSingleFragment {
  2468. dog {
  2469. ...isHousetrainedFragment
  2470. }
  2471. }</p>
  2472. <p>fragment isHousetrainedFragment on Dog {
  2473. isHousetrained(atOtherHomes: $atOtherHomes}
  2474. }
  2475. </code></pre>
  2476. <p>This applies transitively as well, so the following also fails:</p><pre class="spec-counter-example"><code>query variableIsNotDefinedUsedInNestedFragment {
  2477. dog {
  2478. ...outerHousetrainedFragment
  2479. }
  2480. }</p>
  2481. <p>fragment outerHousetrainedFragment on Dog {
  2482. ...isHousetrainedFragment
  2483. }</p>
  2484. <p>fragment isHousetrainedFragment on Dog {
  2485. isHousetrained(atOtherHomes: $atOtherHomes}
  2486. }
  2487. </code></pre>
  2488. <p>Variables must be defined in all operations in which a fragment is used.</p><pre><code>query housetrainedQueryOne($atOtherHomes: Boolean) {
  2489. dog {
  2490. ...isHousetrainedFragment
  2491. }
  2492. }</p>
  2493. <p>query housetrainedQueryTwo($atOtherHomes: Boolean) {
  2494. dog {
  2495. ...isHousetrainedFragment
  2496. }
  2497. }</p>
  2498. <p>fragment isHousetrainedFragment on Dog {
  2499. isHousetrained(atOtherHomes: $atOtherHomes}
  2500. }
  2501. </code></pre>
  2502. <p>However the following does not validate:</p><pre class="spec-counter-example"><code>query housetrainedQueryOne($atOtherHomes: Boolean) {
  2503. dog {
  2504. ...isHousetrainedFragment
  2505. }
  2506. }</p>
  2507. <p>query housetrainedQueryTwoNotDefined {
  2508. dog {
  2509. ...isHousetrainedFragment
  2510. }
  2511. }</p>
  2512. <p>fragment isHousetrainedFragment on Dog {
  2513. isHousetrained(atOtherHomes: $atOtherHomes)
  2514. }
  2515. </code></pre>
  2516. <p>This is because <var>housetrainedQueryTwoNotDefined</var> does not define a variable $<var>atOtherHomes</var> but that variable is used by <var>isHousetrainedFragment</var> which is included in that operation.</p>
  2517. </section>
  2518. <section id="sec-All-Variables-Used">
  2519. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-All-Variables-Used">5.5.1.4</a></span>All Variables Used</h5>
  2520. <p><strong> Formal Specification </strong></p>
  2521. <ul>
  2522. <li>For every <var>operation</var> in the document.</li>
  2523. <li>Let <var>variables</var> be the variables defined by that <var>operation</var></li>
  2524. <li>Each <var>variable</var> in <var>variables</var> must be used at least once in either the operation scope itself or any fragment transitively referenced by that operation.</li>
  2525. </ul>
  2526. <p><strong> Explanatory Text </strong></p>
  2527. <p>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>
  2528. <p>For example the following is invalid:</p><pre class="spec-counter-example"><code>query variableUnused($atOtherHomes: Boolean) {
  2529. dog {
  2530. isHousetrained
  2531. }
  2532. }
  2533. </code></pre>
  2534. <p>because $<var>atOtherHomes</var> in not referenced.</p>
  2535. <p>These rules apply to transitive fragment spreads as well:</p><pre><code>query variableUsedInFragment($atOtherHomes: Boolean) {
  2536. dog {
  2537. ...isHousetrainedFragment
  2538. }
  2539. }</p>
  2540. <p>fragment isHousetrainedFragment on Dog {
  2541. isHousetrained(atOtherHomes: $atOtherHomes)
  2542. }
  2543. </code></pre>
  2544. <p>The above is valid since $<var>atOtherHomes</var> is used in <var>isHousetrainedFragment</var> which is included by <var>variableUsedInFragment</var>.</p>
  2545. <p>If that fragment did not have a reference to $<var>atOtherHomes</var> it would be not valid:</p><pre class="spec-counter-example"><code>query variableNotUsedWithinFragment($atOtherHomes: Boolean) {
  2546. ...isHousetrainedWithoutVariableFragment
  2547. }</p>
  2548. <p>fragment isHousetrainedWithoutVariableFragment on Dog {
  2549. isHousetrained
  2550. }
  2551. </code></pre>
  2552. <p>All operations in a document must use all of their variables.</p>
  2553. <p>As a result, the following document does not validate.</p><pre class="spec-counter-example"><code>query queryWithUsedVar($atOtherHomes: Boolean) {
  2554. dog {
  2555. ...isHousetrainedFragment
  2556. }
  2557. }</p>
  2558. <p>query queryWithExtraVar($atOtherHomes: Boolean, $extra: Int) {
  2559. dog {
  2560. ...isHousetrainedFragment
  2561. }
  2562. }</p>
  2563. <p>fragment isHousetrainedFragment on Dog {
  2564. isHousetrained(atOtherHomes: $atOtherHomes)
  2565. }
  2566. </code></pre>
  2567. <p>This document is not valid because <var>queryWithExtraVar</var> defines an extraneous variable.</p>
  2568. </section>
  2569. <section id="sec-All-Variable-Usages-are-Allowed">
  2570. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-All-Variable-Usages-are-Allowed">5.5.1.5</a></span>All Variable Usages are Allowed</h5>
  2571. <p><strong> Formal Specification </strong></p>
  2572. <ul>
  2573. <li>For each <var>operation</var> in <var>document</var></li>
  2574. <li>Let <var>variableUsages</var> be all usages transitively included in the <var>operation</var></li>
  2575. <li>For each <var>variableUsage</var> in <var>variableUsages</var>
  2576. <ul>
  2577. <li>Let <var>variableType</var> be the type of variable definition in the operation</li>
  2578. <li>Let <var>argumentType</var> be the type of the argument the variable is passed to.</li>
  2579. <li>Let <var>hasDefault</var> be true if the variable definition defines a default.</li>
  2580. <li>AreTypesCompatible(<var>argumentType</var>, <var>variableType</var>, <var>hasDefault</var>) must be true</li>
  2581. </ul>
  2582. </li>
  2583. <li>AreTypesCompatible(<var>argumentType</var>, <var>variableType</var>, <var>hasDefault</var>):
  2584. <ul>
  2585. <li>If <var>hasDefault</var> is true, treat the <var>variableType</var> as non&#8208;null.</li>
  2586. <li>If inner type of <var>argumentType</var> and <var>variableType</var> be different, return false</li>
  2587. <li>If <var>argumentType</var> and <var>variableType</var> have different list dimensions, return false</li>
  2588. <li>If any list level of <var>variableType</var> is not non&#8208;null, and the corresponding level in <var>argument</var> is non&#8208;null, the types are not compatible.</li>
  2589. </ul>
  2590. </li>
  2591. </ul>
  2592. <p><strong> Explanatory Text </strong></p>
  2593. <p>Variable usages must be compatible with the arguments they are passed to.</p>
  2594. <p>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 not&#8208;null argument type.</p>
  2595. <p>Types must match:</p><pre class="spec-counter-example"><code>query intCannotGoIntoBoolean($intArg: Int) {
  2596. arguments {
  2597. booleanArgField(booleanArg: $intArg)
  2598. }
  2599. }
  2600. </code></pre>
  2601. <p>$<var>intArg</var> typed as <span class="spec-nt">Int</span> cannot be used as a argument to <var>booleanArg</var>, typed as <span class="spec-nt">Boolean</span>.</p>
  2602. <p>List cardinality must also be the same. For example, lists cannot be passed into singular values.</p><pre class="spec-counter-example"><code>query booleanListCannotGoIntoBoolean($booleanListArg: [Boolean]) {
  2603. arguments {
  2604. booleanArgField(booleanArg: $booleanListArg)
  2605. }
  2606. }
  2607. </code></pre>
  2608. <p>Nullability must also be respected. In general a nullable variable cannot be passed to a non&#8208;null argument.</p><pre class="spec-counter-example"><code>query booleanArgQuery($booleanArg: Boolean) {
  2609. arguments {
  2610. nonNullBooleanArgField(nonNullBooleanArg: $booleanArg)
  2611. }
  2612. }
  2613. </code></pre>
  2614. <p>A notable exception is when default arguments are provided. They are, in effect, treated as non&#8208;nulls.</p><pre><code>query booleanArgQueryWithDefault($booleanArg: Boolean = true) {
  2615. arguments {
  2616. nonNullBooleanArgField(nonNullBooleanArg: $booleanArg)
  2617. }
  2618. }
  2619. </code></pre>
  2620. <p>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&#8208;null list, and a lists of nullable values cannot be passed to a list of non&#8208;null values.</p><pre><code>query nonNullListToList($nonNullBooleanList: ![Boolean]) {
  2621. arguments {
  2622. booleanListArgField(booleanListArg: $nonNullBooleanList)
  2623. }
  2624. }
  2625. </code></pre>
  2626. <p>However a nullable list could not be passed to a non&#8208;null list.</p><pre class="spec-counter-example"><code>query listToNonNullList($booleanList: [Boolean]) {
  2627. arguments {
  2628. nonNullBooleanListField(nonNullBooleanListArg: $booleanList)
  2629. }
  2630. }
  2631. </code></pre>
  2632. <p>This would fail validation because a <code>[T]</code> cannot be passed to a <code>[T]!</code>.</p>
  2633. <p>Similarly a <code>[T]</code> cannot be passed to a <code>[T!]</code>. </p>
  2634. </section>
  2635. </section>
  2636. </section>
  2637. </section>
  2638. <section id="sec-Execution">
  2639. <h2><span class="spec-secnum" title="link to this section"><a href="#sec-Execution">6</a></span>Execution</h2>
  2640. <p>This section describes how GraphQL generates a response from a request.</p>
  2641. <section id="sec-Evaluating-requests">
  2642. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Evaluating-requests">6.1</a></span>Evaluating requests</h3>
  2643. <p>To evaluate a request, the executor must have a parsed <code>Document</code> (as defined in the &ldquo;Query Language&rdquo; part of this spec) and a selected operation name to run.</p>
  2644. <p>The executor should find the <code>Operation</code> in the <code>Document</code> with the given operation name. If no such operation exists, the executor should throw an error. If the operation is found, then the result of evaluating the request
  2645. should be the result of evaluating the operation according to the &ldquo;Evaluating operations&rdquo; section.</p>
  2646. </section>
  2647. <section id="sec-Evaluating-operations">
  2648. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Evaluating-operations">6.2</a></span>Evaluating operations</h3>
  2649. <p>The type system, as described in the &ldquo;Type System&rdquo; part of the spec, must provide a &ldquo;Query Root&rdquo; and a &ldquo;Mutation Root&rdquo; object.</p>
  2650. <p>If the operation is a mutation, the result of the operation is the result of evaluating the mutation&rsquo;s top level selection set on the &ldquo;Mutation Root&rdquo; object. This selection set should be evaluated serially.</p>
  2651. <p>If the operation is a query, the result of the operation is the result of evaluating the query&rsquo;s top level selection set on the &ldquo;Query Root&rdquo; object.</p>
  2652. </section>
  2653. <section id="sec-Evaluating-selection-sets">
  2654. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Evaluating-selection-sets">6.3</a></span>Evaluating selection sets</h3>
  2655. <p>To evaluate a selection set, the executor needs to know the object on which it is evaluating the set and whether it is being evaluated serially.</p>
  2656. <p>If the selection set is being evaluated on the <code>null</code> object, then the result of evaluating the selection set is <code>null</code>.</p>
  2657. <p>Otherwise, the selection set is turned into a grouped field set; each entry in the grouped field set is a list of fields that share a responseKey.</p>
  2658. <p>The selection set is converted to a grouped field set by calling <code>CollectFields</code>, initializing <code>visitedFragments</code> to an empty list.</p>
  2659. <div class="spec-algo" id="CollectFields()"><span class="spec-call"><a href="#CollectFields()">CollectFields</a>(<var>objectType</var>, <var>selectionSet</var>, <var>visitedFragments</var>)</span>
  2660. <ol>
  2661. <li>Initialize <var>groupedFields</var> to an empty list of lists.</li>
  2662. <li>For each <var>selection</var> in <var>selectionSet</var>;
  2663. <ol>
  2664. <li>If <var>selection</var> provides the directive <code>@skip</code>, let <var>skipDirective</var> be that directive.
  2665. <ol>
  2666. <li>If <var>skipDirective</var>&lsquo;s <var>if</var> argument is <span class="spec-keyword">true</span>, continue with the next <var>selection</var> in <var>selectionSet</var>.</li>
  2667. </ol>
  2668. </li>
  2669. <li>If <var>selection</var> provides the directive <code>@include</code>, let <var>includeDirective</var> be that directive.
  2670. <ol>
  2671. <li>If <var>includeDirective</var>&lsquo;s <var>if</var> argument is <span class="spec-keyword">false</span>, continue with the next <var>selection</var> in <var>selectionSet</var>.</li>
  2672. </ol>
  2673. </li>
  2674. <li>If <var>selection</var> is a Field:
  2675. <ol>
  2676. <li>Let <var>responseKey</var> be the response key of <var>selection</var>.</li>
  2677. <li>Let <var>groupForResponseKey</var> be the list in <var>groupedFields</var> for <var>responseKey</var>; if no such list exists, create it as an empty list.</li>
  2678. <li>Append <var>selection</var> to the <var>groupForResponseKey</var>.</li>
  2679. </ol>
  2680. </li>
  2681. <li>If <var>selection</var> is a FragmentSpread:
  2682. <ol>
  2683. <li>Let <var>fragmentSpreadName</var> be the name of <var>selection</var>.</li>
  2684. <li>If <var>fragmentSpreadName</var> is in <var>visitedFragments</var>, continue with the next <var>selection</var> in <var>selectionSet</var>.</li>
  2685. <li>Add <var>fragmentSpreadName</var> to <var>visitedFragments</var>.</li>
  2686. <li>Let <var>fragment</var> be the Fragment in the current Document whose name is <var>fragmentSpreadName</var>.</li>
  2687. <li>If no such <var>fragment</var> exists, continue with the next <var>selection</var> in <var>selectionSet</var>.</li>
  2688. <li>Let <var>fragmentType</var> be the type condition on <var>fragment</var>.</li>
  2689. <li>If <span class="spec-call"><a href="#doesFragmentTypeApply()">doesFragmentTypeApply</a>(<var>objectType</var>, <var>fragmentType</var>)</span> is false, continue with the next <var>selection</var> in <var>selectionSet</var>.</li>
  2690. <li>Let <var>fragmentSelectionSet</var> be the top&#8208;level selection set of <var>fragment</var>.</li>
  2691. <li>Let <var>fragmentGroupedFields</var> be the result of calling <span class="spec-call"><a href="#CollectFields()">CollectFields</a>(<var>objectType</var>, <var>fragmentSelectionSet</var>)</span>.</li>
  2692. <li>For each <var>fragmentGroup</var> in <var>fragmentGroupedFields</var>:
  2693. <ol>
  2694. <li>Let <var>responseKey</var> be the response key shared by all fields in <var>fragmentGroup</var></li>
  2695. <li>Let <var>groupForResponseKey</var> be the list in <var>groupedFields</var> for <var>responseKey</var>; if no such list exists, create it as an empty list.</li>
  2696. <li>Append all items in <var>fragmentGroup</var> to <var>groupForResponseKey</var>.</li>
  2697. </ol>
  2698. </li>
  2699. </ol>
  2700. </li>
  2701. <li>If <var>selection</var> is an inline fragment:
  2702. <ol>
  2703. <li>Let <var>fragmentType</var> be the type condition on <var>selection</var>.</li>
  2704. <li>If <span class="spec-call"><a href="#doesFragmentTypeApply()">doesFragmentTypeApply</a>(<var>objectType</var>, <var>fragmentType</var>)</span> is false, continue with the next <var>selection</var> in <var>selectionSet</var>.</li>
  2705. <li>Let <var>fragmentSelectionSet</var> be the top&#8208;level selection set of <var>selection</var>.</li>
  2706. <li>Let <var>fragmentGroupedFields</var> be the result of calling <span class="spec-call"><a href="#CollectFields()">CollectFields</a>(<var>objectType</var>, <var>fragmentSelectionSet</var>)</span>.</li>
  2707. <li>For each <var>fragmentGroup</var> in <var>fragmentGroupedFields</var>:
  2708. <ol>
  2709. <li>Let <var>responseKey</var> be the response key shared by all fields in <var>fragmentGroup</var></li>
  2710. <li>Let <var>groupForResponseKey</var> be the list in <var>groupedFields</var> for <var>responseKey</var>; if no such list exists, create it as an empty list.</li>
  2711. <li>Append all items in <var>fragmentGroup</var> to <var>groupForResponseKey</var>.</li>
  2712. </ol>
  2713. </li>
  2714. </ol>
  2715. </li>
  2716. </ol>
  2717. </li>
  2718. <li>Return <var>groupedFields</var>.</li>
  2719. </ol>
  2720. </div>
  2721. <div class="spec-algo" id="doesFragmentTypeApply()"><span class="spec-call"><a href="#doesFragmentTypeApply()">doesFragmentTypeApply</a>(<var>objectType</var>, <var>fragmentType</var>)</span>
  2722. <ol>
  2723. <li>If <var>fragmentType</var> is an Object Type, return <span class="spec-keyword">true</span> if <var>objectType</var> is <var>fragmentType</var>, otherwise return <span class="spec-keyword">false</span>.</li>
  2724. <li>If <var>fragmentType</var> is an Interface Type, return <span class="spec-keyword">true</span> if <var>objectType</var> is an implementation of <var>fragmentType</var>, otherwise return <span class="spec-keyword">false</span>.</li>
  2725. <li>If <var>fragmentType</var> is a Union, return <span class="spec-keyword">true</span> if <var>objectType</var> is a possible type of <var>fragmentType</var>, otherwise return <span class="spec-keyword">false</span>.</li>
  2726. </ol>
  2727. </div>
  2728. <p>The result of evaluating the selection set is the result of evaluating the corresponding grouped field set. The corresponding grouped field set should be evaluated serially if the selection set is being evaluated serially, otherwise it should be
  2729. evaluated normally.</p>
  2730. </section>
  2731. <section id="sec-Evaluating-a-grouped-field-set">
  2732. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Evaluating-a-grouped-field-set">6.4</a></span>Evaluating a grouped field set</h3>
  2733. <p>The result of evaluating a grouped field set will be an unordered map. There will be an entry in this map for every item in the grouped field set.</p>
  2734. <section id="sec-Field-entries">
  2735. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Field-entries">6.4.1</a></span>Field entries</h4>
  2736. <p>Each item in the grouped field set can potentially create an entry in the result map. That entry in the result map is the result is the result of calling <code>GetFieldEntry</code> on the corresponding item in the grouped field set. <code>GetFieldEntry</code> can return <code>null</code>, which indicates that there should be no entry in the result map for this item. Note that this is distinct from returning an entry with a string key and a null value, which indicates that an entry in the result should
  2737. be added for that key, and its value should be null.</p>
  2738. <p><code>GetFieldEntry</code> assumes the existence of two functions that are not defined in this section of the spec. It is expected that the type system provides these methods:</p>
  2739. <ul>
  2740. <li><code>ResolveFieldOnObject</code>, which takes an object type, a field, and an object, and returns the result of resolving that field on the object.</li>
  2741. <li><code>GetFieldTypeFromObjectType</code>, which takes an object type and a field, and returns that field&rsquo;s type on the object type, or <code>null</code> if the field is not valid on the object type.</li>
  2742. </ul>
  2743. <div class="spec-algo" id="GetFieldEntry()"><span class="spec-call"><a href="#GetFieldEntry()">GetFieldEntry</a>(<var>objectType</var>, <var>object</var>, <var>fields</var>)</span>
  2744. <ol>
  2745. <li>Let <var>firstField</var> be the first entry in the ordered list <var>fields</var>. Note that <var>fields</var> is never empty, as the entry in the grouped field set would not exist if there were no fields.</li>
  2746. <li>Let <var>responseKey</var> be the response key of <var>firstField</var>.</li>
  2747. <li>Let <var>fieldType</var> be the result of calling <span class="spec-call"><a href="#GetFieldTypeFromObjectType()">GetFieldTypeFromObjectType</a>(<var>objectType</var>, <var>firstField</var>)</span>.</li>
  2748. <li>If <var>fieldType</var> is <span class="spec-keyword">null</span>, return <span class="spec-keyword">null</span>, indicating that no entry exists in the result map.</li>
  2749. <li>Let <var>resolvedObject</var> be <span class="spec-call"><a href="#ResolveFieldOnObject()">ResolveFieldOnObject</a>(<var>objectType</var>, <var>object</var>, <var>fieldEntry</var>)</span>.</li>
  2750. <li>If <var>resolvedObject</var> is <span class="spec-keyword">null</span>, return <span class="spec-call">tuple(<var>responseKey</var>, <span class="spec-keyword">null</span>)</span>, indicating that an entry exists in the result map whose value
  2751. is <code>null</code>.</li>
  2752. <li>Let <var>subSelectionSet</var> be the result of calling <span class="spec-call"><a href="#MergeSelectionSets()">MergeSelectionSets</a>(<var>fields</var>)</span>.</li>
  2753. <li>Let <var>responseValue</var> be the result of calling <span class="spec-call"><a href="#CompleteValue()">CompleteValue</a>(<var>fieldType</var>, <var>resolvedObject</var>, <var>subSelectionSet</var>)</span>.</li>
  2754. <li>Return <span class="spec-call">tuple(<var>responseKey</var>, <var>responseValue</var>)</span>.</li>
  2755. </ol>
  2756. </div>
  2757. <div class="spec-algo" id="GetFieldTypeFromObjectType()"><span class="spec-call"><a href="#GetFieldTypeFromObjectType()">GetFieldTypeFromObjectType</a>(<var>objectType</var>, <var>firstField</var>)</span>
  2758. <ol>
  2759. <li>Call the method provided by the type system for determining the field type on a given object type.</li>
  2760. </ol>
  2761. </div>
  2762. <div class="spec-algo" id="ResolveFieldOnObject()"><span class="spec-call"><a href="#ResolveFieldOnObject()">ResolveFieldOnObject</a>(<var>objectType</var>, <var>object</var>, <var>firstField</var>)</span>
  2763. <ol>
  2764. <li>Call the method provided by the type system for determining the resolution of a field on a given object.</li>
  2765. </ol>
  2766. </div>
  2767. <div class="spec-algo" id="MergeSelectionSets()"><span class="spec-call"><a href="#MergeSelectionSets()">MergeSelectionSets</a>(<var>fields</var>)</span>
  2768. <ol>
  2769. <li>Let <var>selectionSet</var> be an empty list.</li>
  2770. <li>For each <var>field</var> in <var>fields</var>:
  2771. <ol>
  2772. <li>Let <var>fieldSelectionSet</var> be the selection set of <var>field</var>.</li>
  2773. <li>If <var>fieldSelectionSet</var> is null or empty, continue to the next field.</li>
  2774. <li>Append all selections in <var>fieldSelectionSet</var> to <var>selectionSet</var>.</li>
  2775. </ol>
  2776. </li>
  2777. <li>Return <var>selectionSet</var>.</li>
  2778. </ol>
  2779. </div>
  2780. <div class="spec-algo" id="CompleteValue()"><span class="spec-call"><a href="#CompleteValue()">CompleteValue</a>(<var>fieldType</var>, <var>result</var>, <var>subSelectionSet</var>)</span>
  2781. <ol>
  2782. <li>If the <var>fieldType</var> is a Non&#8208;Null type:
  2783. <ol>
  2784. <li>Let <var>innerType</var> be the inner type of <var>fieldType</var>.</li>
  2785. <li>Let <var>completedResult</var> be the result of calling <span class="spec-call"><a href="#CompleteValue()">CompleteValue</a>(<var>innerType</var>, <var>result</var>)</span>.</li>
  2786. <li>If <var>completedResult</var> is <span class="spec-keyword">null</span>, throw a field error.</li>
  2787. <li>Return <var>completedResult</var>.</li>
  2788. </ol>
  2789. </li>
  2790. <li>If <var>result</var> is <span class="spec-keyword">null</span> or a value similar to <span class="spec-keyword">null</span> such as <span class="spec-keyword">undefined</span> or <span class="spec-nt">NaN</span>, return <span class="spec-keyword">null</span>.</li>
  2791. <li>If <var>fieldType</var> is a List type:
  2792. <ol>
  2793. <li>If <var>result</var> is not a collection of values, throw a field error.</li>
  2794. <li>Let <var>innerType</var> be the inner type of <var>fieldType</var>.</li>
  2795. <li>Return a list where each item is the result of calling <span class="spec-call"><a href="#CompleteValue()">CompleteValue</a>(<var>innerType</var>, <var>resultItem</var>)</span>, where <var>resultItem</var> is each item in <var>result</var>.</li>
  2796. </ol>
  2797. </li>
  2798. <li>If <var>fieldType</var> is a Scalar or Enum type:
  2799. <ol>
  2800. <li>Return the result of &ldquo;coercing&rdquo; <var>result</var>, ensuring it is a legal value of <var>fieldType</var>, otherwise <span class="spec-keyword">null</span>.</li>
  2801. </ol>
  2802. </li>
  2803. <li>If <var>fieldType</var> is an Object, Interface, or Union type:
  2804. <ol>
  2805. <li>Return the result of evaluating <var>subSelectionSet</var> on <var>fieldType</var> normally.</li>
  2806. </ol>
  2807. </li>
  2808. </ol>
  2809. </div>
  2810. </section>
  2811. <section id="sec-Normal-evaluation">
  2812. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Normal-evaluation">6.4.2</a></span>Normal evaluation</h4>
  2813. <p>When evaluating a grouped field set without a serial execution order requirement, the executor can determine the entries in the result map in whatever order it chooses. Because the resolution of fields other than top&#8208;level mutation fields
  2814. is always side effect&ndash;free and idempotent, the execution order must not affect the result, and hence the server has the freedom to evaluate the field entries in whatever order it deems optimal.</p>
  2815. <p>For example, given the following grouped field set to be evaluated normally:</p><pre><code>{
  2816. birthday {
  2817. month
  2818. }
  2819. address {
  2820. street
  2821. }
  2822. }
  2823. </code></pre>
  2824. <p>A valid GraphQL executor can resolve the four fields in whatever order it chose.</p>
  2825. </section>
  2826. <section id="sec-Serial-execution">
  2827. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Serial-execution">6.4.3</a></span>Serial execution</h4>
  2828. <p>Observe that based on the above sections, the only time an executor will run in serial execution order is on the top level selection set of a mutation operation and on its corresponding grouped field set.</p>
  2829. <p>When evaluating 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
  2830. before it continues on to the next item in the grouped field set:</p>
  2831. <p>For example, given the following selection set to be evaluated serially:</p><pre><code>{
  2832. changeBirthday(birthday: $newBirthday) {
  2833. month
  2834. }
  2835. changeAddress(address: $newAddress) {
  2836. street
  2837. }
  2838. }
  2839. </code></pre>
  2840. <p>The executor must, in serial:</p>
  2841. <ul>
  2842. <li>Run <code>getFieldEntry</code> for <code>changeBirthday</code>, which during <code>CompleteValue</code> will evaluate the <code>{ month }</code> sub&#8208;selection set normally.</li>
  2843. <li>Run <code>getFieldEntry</code> for <code>changeAddress</code>, which during <code>CompleteValue</code> will evaluate the <code>{ street }</code> sub&#8208;selection set normally.</li>
  2844. </ul>
  2845. <p>As an illustrative example, let&rsquo;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><code>{
  2846. first: changeTheNumber(newNumber: 1) {
  2847. theNumber
  2848. }
  2849. second: changeTheNumber(newNumber: 3) {
  2850. theNumber
  2851. }
  2852. third: changeTheNumber(newNumber: 2) {
  2853. theNumber
  2854. }
  2855. }
  2856. </code></pre>
  2857. <p>The executor will evaluate the following serially:</p>
  2858. <ul>
  2859. <li>Resolve the <code>changeTheNumber(newNumber: 1)</code> field</li>
  2860. <li>Evaluate the <code>{ theNumber }</code> sub&#8208;selection set of <code>first</code> normally</li>
  2861. <li>Resolve the <code>changeTheNumber(newNumber: 3)</code> field</li>
  2862. <li>Evaluate the <code>{ theNumber }</code> sub&#8208;selection set of <code>second</code> normally</li>
  2863. <li>Resolve the <code>changeTheNumber(newNumber: 2)</code> field</li>
  2864. <li>Evaluate the <code>{ theNumber }</code> sub&#8208;selection set of <code>third</code> normally</li>
  2865. </ul>
  2866. <p>A correct executor must generate the following result for that selection set:</p><pre><code>{
  2867. <span class="hljs-string">"first"</span>: {
  2868. <span class="hljs-string">"theNumber"</span>: <span class="hljs-number">1</span>
  2869. },
  2870. <span class="hljs-string">"second"</span>: {
  2871. <span class="hljs-string">"theNumber"</span>: <span class="hljs-number">3</span>
  2872. },
  2873. <span class="hljs-string">"third"</span>: {
  2874. <span class="hljs-string">"theNumber"</span>: <span class="hljs-number">2</span>
  2875. }
  2876. }
  2877. </code></pre></section>
  2878. <section id="sec-Error-handling">
  2879. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Error-handling">6.4.4</a></span>Error handling</h4>
  2880. <p>If an error occurs when resolving a field, it should be treated as though the field returned null, and an error must be added to the &ldquo;errors&rdquo; list in the response.</p>
  2881. </section>
  2882. <section id="sec-Nullability">
  2883. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Nullability">6.4.5</a></span>Nullability</h4>
  2884. <p>If the result of resolving a field is null (either because the function to resolve the field returned null or because an error occurred), and that field is marked as being non&#8208;null in the type system, then the result of evaluating the entire
  2885. field set that contains this field is now null.</p>
  2886. <p>If the field was null because of an error, then the error has already been logged, and the &ldquo;errors&rdquo; list in the response must not be affected.</p>
  2887. <p>If the field resolution function returned null, and the field was non&#8208;null, then no error has been logged, so an appropriate error must be added to the &ldquo;errors&rdquo; list. </p>
  2888. </section>
  2889. </section>
  2890. </section>
  2891. <section id="sec-Response">
  2892. <h2><span class="spec-secnum" title="link to this section"><a href="#sec-Response">7</a></span>Response</h2>
  2893. <p>When a GraphQL server receives a request, it must return a well&#8208;formed response. The server&rsquo;s response describes the result of executing the requested operation if successful, and describes any errors encountered during the request.</p>
  2894. <p>A response may contain both a partial response as well as encountered errors in the case that an error occurred on a field which was replaced with null.</p>
  2895. <section id="sec-Serialization-Format">
  2896. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Serialization-Format">7.1</a></span>Serialization Format</h3>
  2897. <p>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 support representations of the
  2898. following four primitives:</p>
  2899. <ul>
  2900. <li>Map</li>
  2901. <li>List</li>
  2902. <li>String</li>
  2903. <li>Null</li>
  2904. </ul>
  2905. <p>A serialization format may support the following primitives, however, strings may be used as a substitute for those primitives.</p>
  2906. <ul>
  2907. <li>Boolean</li>
  2908. <li>Int</li>
  2909. <li>Float</li>
  2910. <li>Enum Value</li>
  2911. </ul>
  2912. <section id="sec-JSON-Serialization">
  2913. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-JSON-Serialization">7.1.1</a></span>JSON Serialization</h4>
  2914. <p>JSON is the preferred serialization format for GraphQL, though as noted above, GraphQL does not require a specific serialization format. For consistency and ease of notation, examples of the response are given in JSON throughout the spec. In particular,
  2915. in our JSON examples, we will represent primitives using the following JSON concepts:</p>
  2916. <table>
  2917. <thead>
  2918. <tr>
  2919. <th>GraphQL Value </th>
  2920. <th>JSON Value </th>
  2921. </tr>
  2922. </thead>
  2923. <tbody>
  2924. <tr>
  2925. <td>Map </td>
  2926. <td>Object </td>
  2927. </tr>
  2928. <tr>
  2929. <td>List </td>
  2930. <td>Array </td>
  2931. </tr>
  2932. <tr>
  2933. <td>Null </td>
  2934. <td><span class="spec-keyword">null</span> </td>
  2935. </tr>
  2936. <tr>
  2937. <td>String </td>
  2938. <td>String </td>
  2939. </tr>
  2940. <tr>
  2941. <td>Boolean </td>
  2942. <td><span class="spec-keyword">true</span> or <span class="spec-keyword">false</span> </td>
  2943. </tr>
  2944. <tr>
  2945. <td>Int </td>
  2946. <td>Number </td>
  2947. </tr>
  2948. <tr>
  2949. <td>Float </td>
  2950. <td>Number </td>
  2951. </tr>
  2952. <tr>
  2953. <td>Enum Value </td>
  2954. <td>String </td>
  2955. </tr>
  2956. </tbody>
  2957. </table>
  2958. </section>
  2959. </section>
  2960. <section id="sec-Response-Format">
  2961. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Response-Format">7.2</a></span>Response Format</h3>
  2962. <p>A response to a GraphQL operation must be a map.</p>
  2963. <p>If the operation included execution, the response map must contain an entry with key <code>data</code>. The value of this entry is described in the &ldquo;Data&rdquo; section. If the operation failed before execution, due to a syntax error, missing
  2964. information, or validation error, this entry must not be present.</p>
  2965. <p>If the operation encountered any errors, the response map must contain an entry with key <code>errors</code>. The value of this entry is described in the &ldquo;Errors&rdquo; section. If the operation completed without encountering any errors, this
  2966. entry must not be present.</p>
  2967. <p>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
  2968. restrictions on its contents.</p>
  2969. <p>To ensure future changes to the protocol do not break existing servers and clients, the top level response map must not contain any entries other than the three described above.</p>
  2970. <section id="sec-Data">
  2971. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Data">7.2.1</a></span>Data</h4>
  2972. <p>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 schema&rsquo;s query root type; if the operation was a mutation, this
  2973. output will be an object of the schema&rsquo;s mutation root type.</p>
  2974. <p>If an error was encountered before execution begins, the <code>data</code> entry should not be present in the result.</p>
  2975. <p>If an error was encountered during the execution that prevented a valid response, the <code>data</code> entry in the response should be <code>null</code>.</p>
  2976. </section>
  2977. <section id="sec-Errors">
  2978. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Errors">7.2.2</a></span>Errors</h4>
  2979. <p>The <code>errors</code> entry in the response is a non&#8208;empty list of errors, where each error is a map.</p>
  2980. <p>If no errors were encountered during the requested operation, the <code>errors</code> entry should not be present in the result.</p>
  2981. <p>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>
  2982. <p>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>,
  2983. both positive numbers starting from <code>1</code> which describe the beginning of an associated syntax element.</p>
  2984. <p>GraphQL servers may provide additional entries to error as they choose to produce more helpful or machine&#8208;readable errors, however future versions of the spec may describe additional entries to errors.</p>
  2985. <p>If the <code>data</code> entry in the response is <code>null</code> or 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
  2986. to be returned.</p>
  2987. <p>If the <code>data</code> entry in the response is not <code>null</code>, the <code>errors</code> entry in the response may contain any errors that occurred during execution. If errors occurred during execution, it should contain those errors.
  2988. </p>
  2989. </section>
  2990. </section>
  2991. </section>
  2992. <section id="sec-Grammar">
  2993. <h2><span class="spec-secnum" title="link to this section"><a href="#sec-Grammar">8</a></span>Grammar</h2>
  2994. <p>A GraphQL document 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 sequence of source UTF&#8208;8 characters produces
  2995. a GraphQL AST.</p>
  2996. <p>Symbols are defined (ex. Symbol :) as either one sequence of symbols or a list of possible sequences of symbols, either as a bulleted list or using the &ldquo;one of&rdquo; short hand.</p>
  2997. <p>A subscript suffix &ldquo;<span class="spec-nt optional">Symbol<span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  2998. </span>&rdquo; is shorthand for two possible sequences, one including that symbol and one excluding it.</p>
  2999. <p>As an example:</p>
  3000. <div class="spec-production" id="Sentence"><span class="spec-nt"><a href="#Sentence">Sentence</a></span>
  3001. <div class="spec-rhs"><span class="spec-nt">Noun</span><span class="spec-nt">Verb</span><span class="spec-nt optional">Adverb<span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3002. </span>
  3003. </div>
  3004. </div>
  3005. <p>is shorthand for</p>
  3006. <div class="spec-production" id="Sentence"><span class="spec-nt"><a href="#Sentence">Sentence</a></span>
  3007. <div class="spec-rhs"><span class="spec-nt">Noun</span><span class="spec-nt">Verb</span></div>
  3008. <div class="spec-rhs"><span class="spec-nt">Noun</span><span class="spec-nt">Verb</span><span class="spec-nt">Adverb</span></div>
  3009. </div>
  3010. <p>A subscript suffix &ldquo;<span class="spec-nt list">Symbol<span class="spec-mods"><span class="spec-mod list">list</span></span>
  3011. </span>&rdquo; is shorthand for a list of one or more of that symbol.</p>
  3012. <p>As an example:</p>
  3013. <div class="spec-production" id="Book"><span class="spec-nt"><a href="#Book">Book</a></span>
  3014. <div class="spec-rhs"><span class="spec-nt">Cover</span><span class="spec-nt list">Page<span class="spec-mods"><span class="spec-mod list">list</span></span>
  3015. </span><span class="spec-nt">Cover</span></div>
  3016. </div>
  3017. <p>is shorthand for</p>
  3018. <div class="spec-production" id="Book"><span class="spec-nt"><a href="#Book">Book</a></span>
  3019. <div class="spec-rhs"><span class="spec-nt">Cover</span><span class="spec-nt"><a href="#Page_list">Page_list</a></span><span class="spec-nt">Cover</span></div>
  3020. </div>
  3021. <div class="spec-production" id="Page_list"><span class="spec-nt"><a href="#Page_list">Page_list</a></span>
  3022. <div class="spec-rhs"><span class="spec-nt">Page</span></div>
  3023. <div class="spec-rhs"><span class="spec-nt"><a href="#Page_list">Page_list</a></span><span class="spec-nt">Page</span></div>
  3024. </div>
  3025. <p>A symbol definition subscript suffix parameter in braces &ldquo;<span class="spec-nt">Symbol<span class="spec-mods"><span class="spec-params"><span class="spec-param">Param</span></span>
  3026. </span>
  3027. </span>&rdquo; 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 &ldquo;?&rdquo;, that
  3028. 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 &ldquo;[+Param]&rdquo; and &ldquo;[~Param]&rdquo;.</p>
  3029. <p>As an example:</p>
  3030. <div class="spec-production" id="Example"><span class="spec-nt"><a href="#Example">Example</a><span class="spec-mods"><span class="spec-params"><span class="spec-param">Param</span></span>
  3031. </span>
  3032. </span>
  3033. <div class="spec-rhs"><span class="spec-nt">A</span></div>
  3034. <div class="spec-rhs"><span class="spec-nt">B<span class="spec-mods"><span class="spec-params"><span class="spec-param">Param</span></span>
  3035. </span>
  3036. </span>
  3037. </div>
  3038. <div class="spec-rhs"><span class="spec-nt">C<span class="spec-mods"><span class="spec-params"><span class="spec-param conditional">Param</span></span>
  3039. </span>
  3040. </span>
  3041. </div>
  3042. <div class="spec-rhs"><span class="spec-condition">Param</span><span class="spec-nt">D</span></div>
  3043. <div class="spec-rhs"><span class="spec-condition not">Param</span><span class="spec-nt">E</span></div>
  3044. </div>
  3045. <p>is shorthand for</p>
  3046. <div class="spec-production" id="Example"><span class="spec-nt"><a href="#Example">Example</a></span>
  3047. <div class="spec-rhs"><span class="spec-nt">A</span></div>
  3048. <div class="spec-rhs"><span class="spec-nt">B_param</span></div>
  3049. <div class="spec-rhs"><span class="spec-nt">C</span></div>
  3050. <div class="spec-rhs"><span class="spec-nt">E</span></div>
  3051. </div>
  3052. <div class="spec-production" id="Example_param"><span class="spec-nt"><a href="#Example_param">Example_param</a></span>
  3053. <div class="spec-rhs"><span class="spec-nt">A</span></div>
  3054. <div class="spec-rhs"><span class="spec-nt">B_param</span></div>
  3055. <div class="spec-rhs"><span class="spec-nt">C_param</span></div>
  3056. <div class="spec-rhs"><span class="spec-nt">D</span></div>
  3057. </div>
  3058. <section id="sec-Ignored-Source">
  3059. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Ignored-Source">8.1</a></span>Ignored Source</h3>
  3060. <p>Before and after every lexical token may be any amount of ignored source characters including whitespace and comments. No ignored regions of a source document are significant, however ignored source characters may appear within a lexical token,
  3061. for example a <span class="spec-nt">String</span> may contain whitespace.</p>
  3062. <p><strong>Ignoring commas</strong></p>
  3063. <p>GraphQL ignores the comma (<span class="spec-t">,</span>) character. This ensures 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&#8208;error in other languages.
  3064. It also allows for the stylistic use of either trailing commas or line&#8208;terminators as delimiters which are often desired for legibility and maintainability of source code. The use of commas, whitespace, and line&#8208;terminators is encouraged
  3065. only when they improve the legibility of GraphQL documents.</p>
  3066. <p>GraphQL ignores these character sequences:</p>
  3067. <div class="spec-production" id="Ignored"><span class="spec-nt"><a href="#Ignored">Ignored</a></span>
  3068. <div class="spec-rhs"><span class="spec-nt"><a href="#WhiteSpace">WhiteSpace</a></span></div>
  3069. <div class="spec-rhs"><span class="spec-nt"><a href="#LineTerminator">LineTerminator</a></span></div>
  3070. <div class="spec-rhs"><span class="spec-nt"><a href="#Comment">Comment</a></span></div>
  3071. <div class="spec-rhs"><span class="spec-t">,</span></div>
  3072. </div>
  3073. <div class="spec-production" id="WhiteSpace"><span class="spec-nt"><a href="#WhiteSpace">WhiteSpace</a></span>
  3074. <div class="spec-rhs"><span class="spec-prose">Horizontal Tab (U+0009)</span></div>
  3075. <div class="spec-rhs"><span class="spec-prose">Vertical Tab (U+000B)</span></div>
  3076. <div class="spec-rhs"><span class="spec-prose">Form Feed (U+000C)</span></div>
  3077. <div class="spec-rhs"><span class="spec-prose">Space (U+0020)</span></div>
  3078. <div class="spec-rhs"><span class="spec-prose">No-break Space (U+00A0)</span></div>
  3079. </div>
  3080. <div class="spec-production" id="LineTerminator"><span class="spec-nt"><a href="#LineTerminator">LineTerminator</a></span>
  3081. <div class="spec-rhs"><span class="spec-prose">New Line (U+000A)</span></div>
  3082. <div class="spec-rhs"><span class="spec-prose">Carriage Return (U+000D)</span></div>
  3083. <div class="spec-rhs"><span class="spec-prose">Line Separator (U+2028)</span></div>
  3084. <div class="spec-rhs"><span class="spec-prose">Paragraph Separator (U+2029)</span></div>
  3085. </div>
  3086. <div class="spec-production" id="Comment"><span class="spec-nt"><a href="#Comment">Comment</a></span>
  3087. <div class="spec-rhs"><span class="spec-t">#</span><span class="spec-nt list optional"><a href="#CommentChar">CommentChar</a><span class="spec-mods"><span class="spec-mod list">list</span><span class="spec-mod optional">opt</span></span>
  3088. </span>
  3089. </div>
  3090. </div>
  3091. <div class="spec-production" id="CommentChar"><span class="spec-nt"><a href="#CommentChar">CommentChar</a></span>
  3092. <div class="spec-rhs"><span class="spec-constrained"><span class="spec-prose">Any character</span><span class="spec-butnot"><span class="spec-nt"><a href="#LineTerminator">LineTerminator</a></span></span>
  3093. </span>
  3094. </div>
  3095. </div>
  3096. </section>
  3097. <section id="sec-Tokens">
  3098. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Tokens">8.2</a></span>Tokens</h3>
  3099. <p>A GraphQL document is comprised of several kinds of source tokens defined here in a lexical grammar. This lexical grammar defines patterns of source characters by specifying character patterns in <span class="spec-t">monospace</span> or as
  3100. <span
  3101. class="spec-rx">/regular_expressions/</span>. Non&#8208;terminal patterns are defined as <span class="spec-nt">Italics</span>.</p>
  3102. <p>No characters are ignored while parsing a given token, for example no whitespace is allowed between the characters defining a <span class="spec-nt"><a href="#FloatValue">FloatValue</a></span>, however ignored characters are skipped before and after
  3103. each well&#8208;formed Token.</p>
  3104. <p>Tokens are later used as terminal symbols in GraphQL&rsquo;s syntactic grammar.</p>
  3105. <p>The GraphQL document syntactic grammar is defined in terms of these lexical tokens:</p>
  3106. <div class="spec-production" id="Token"><span class="spec-nt"><a href="#Token">Token</a></span>
  3107. <div class="spec-rhs"><span class="spec-nt"><a href="#Punctuator">Punctuator</a></span></div>
  3108. <div class="spec-rhs"><span class="spec-nt"><a href="#Name">Name</a></span></div>
  3109. <div class="spec-rhs"><span class="spec-nt"><a href="#IntValue">IntValue</a></span></div>
  3110. <div class="spec-rhs"><span class="spec-nt"><a href="#FloatValue">FloatValue</a></span></div>
  3111. <div class="spec-rhs"><span class="spec-nt"><a href="#StringValue">StringValue</a></span></div>
  3112. </div>
  3113. <div class="spec-production oneof" id="Punctuator"><span class="spec-nt"><a href="#Punctuator">Punctuator</a></span>
  3114. <table>
  3115. <tr>
  3116. <td class="spec-rhs"><span class="spec-t">!</span></td>
  3117. <td class="spec-rhs"><span class="spec-t">$</span></td>
  3118. <td class="spec-rhs"><span class="spec-t">(</span></td>
  3119. <td class="spec-rhs"><span class="spec-t">)</span></td>
  3120. <td class="spec-rhs"><span class="spec-t">...</span></td>
  3121. <td class="spec-rhs"><span class="spec-t">:</span></td>
  3122. <td class="spec-rhs"><span class="spec-t">=</span></td>
  3123. <td class="spec-rhs"><span class="spec-t">@</span></td>
  3124. <td class="spec-rhs"><span class="spec-t">[</span></td>
  3125. <td class="spec-rhs"><span class="spec-t">]</span></td>
  3126. <td class="spec-rhs"><span class="spec-t">{</span></td>
  3127. <td class="spec-rhs"><span class="spec-t">|</span></td>
  3128. <td class="spec-rhs"><span class="spec-t">}</span></td>
  3129. </tr>
  3130. </table>
  3131. </div>
  3132. <div class="spec-production" id="Name"><span class="spec-nt"><a href="#Name">Name</a></span>
  3133. <div class="spec-rhs"><span class="spec-rx">/[_A-Za-z][_0-9A-Za-z]*/</span></div>
  3134. </div>
  3135. <div class="spec-production" id="IntValue"><span class="spec-nt"><a href="#IntValue">IntValue</a></span>
  3136. <div class="spec-rhs"><span class="spec-nt optional"><a href="#Sign">Sign</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3137. </span><span class="spec-nt"><a href="#IntegerPart">IntegerPart</a></span></div>
  3138. </div>
  3139. <div class="spec-production" id="FloatValue"><span class="spec-nt"><a href="#FloatValue">FloatValue</a></span>
  3140. <div class="spec-rhs"><span class="spec-nt optional"><a href="#Sign">Sign</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3141. </span><span class="spec-nt"><a href="#IntegerPart">IntegerPart</a></span><span class="spec-t">.</span><span class="spec-nt list"><a href="#Digit">Digit</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3142. </span><span class="spec-nt optional"><a href="#ExponentPart">ExponentPart</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3143. </span>
  3144. </div>
  3145. </div>
  3146. <div class="spec-production" id="Sign"><span class="spec-nt"><a href="#Sign">Sign</a></span>
  3147. <div class="spec-rhs"><span class="spec-t">-</span></div>
  3148. </div>
  3149. <div class="spec-production" id="IntegerPart"><span class="spec-nt"><a href="#IntegerPart">IntegerPart</a></span>
  3150. <div class="spec-rhs"><span class="spec-t">0</span></div>
  3151. <div class="spec-rhs"><span class="spec-nt"><a href="#NonZeroDigit">NonZeroDigit</a></span></div>
  3152. <div class="spec-rhs"><span class="spec-nt"><a href="#NonZeroDigit">NonZeroDigit</a></span><span class="spec-nt list"><a href="#Digit">Digit</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3153. </span>
  3154. </div>
  3155. </div>
  3156. <div class="spec-production" id="ExponentPart"><span class="spec-nt"><a href="#ExponentPart">ExponentPart</a></span>
  3157. <div class="spec-rhs"><span class="spec-t">e</span><span class="spec-nt optional"><a href="#Sign">Sign</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3158. </span><span class="spec-nt list"><a href="#Digit">Digit</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3159. </span>
  3160. </div>
  3161. </div>
  3162. <div class="spec-production oneof" id="NonZeroDigit"><span class="spec-nt"><a href="#NonZeroDigit">NonZeroDigit</a></span>
  3163. <table>
  3164. <tr>
  3165. <td class="spec-rhs"><span class="spec-t">1</span></td>
  3166. <td class="spec-rhs"><span class="spec-t">2</span></td>
  3167. <td class="spec-rhs"><span class="spec-t">3</span></td>
  3168. <td class="spec-rhs"><span class="spec-t">4</span></td>
  3169. <td class="spec-rhs"><span class="spec-t">5</span></td>
  3170. <td class="spec-rhs"><span class="spec-t">6</span></td>
  3171. <td class="spec-rhs"><span class="spec-t">7</span></td>
  3172. <td class="spec-rhs"><span class="spec-t">8</span></td>
  3173. <td class="spec-rhs"><span class="spec-t">9</span></td>
  3174. </tr>
  3175. </table>
  3176. </div>
  3177. <div class="spec-production" id="Digit"><span class="spec-nt"><a href="#Digit">Digit</a></span>
  3178. <div class="spec-rhs"><span class="spec-t">0</span></div>
  3179. <div class="spec-rhs"><span class="spec-nt"><a href="#NonZeroDigit">NonZeroDigit</a></span></div>
  3180. </div>
  3181. <div class="spec-production" id="StringValue"><span class="spec-nt"><a href="#StringValue">StringValue</a></span>
  3182. <div class="spec-rhs"><span class="spec-t">&quot;&quot;</span></div>
  3183. <div class="spec-rhs"><span class="spec-t">&quot;</span><span class="spec-nt list"><a href="#StringCharacter">StringCharacter</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3184. </span><span class="spec-t">&quot;</span></div>
  3185. </div>
  3186. <div class="spec-production" id="StringCharacter"><span class="spec-nt"><a href="#StringCharacter">StringCharacter</a></span>
  3187. <div class="spec-rhs"><span class="spec-constrained"><span class="spec-prose">Any character</span><span class="spec-butnot"><span class="spec-t">&quot;</span><span class="spec-t">\</span><span class="spec-nt"><a href="#LineTerminator">LineTerminator</a></span></span>
  3188. </span>
  3189. </div>
  3190. <div class="spec-rhs"><span class="spec-t">\</span><span class="spec-nt"><a href="#EscapedUnicode">EscapedUnicode</a></span></div>
  3191. <div class="spec-rhs"><span class="spec-t">\</span><span class="spec-nt"><a href="#EscapedCharacter">EscapedCharacter</a></span></div>
  3192. </div>
  3193. <div class="spec-production" id="EscapedUnicode"><span class="spec-nt"><a href="#EscapedUnicode">EscapedUnicode</a></span>
  3194. <div class="spec-rhs"><span class="spec-t">u</span><span class="spec-rx">/[0-9A-Fa-f]{4}/</span></div>
  3195. </div>
  3196. <div class="spec-production oneof" id="EscapedCharacter"><span class="spec-nt"><a href="#EscapedCharacter">EscapedCharacter</a></span>
  3197. <table>
  3198. <tr>
  3199. <td class="spec-rhs"><span class="spec-t">&quot;</span></td>
  3200. <td class="spec-rhs"><span class="spec-t">\</span></td>
  3201. <td class="spec-rhs"><span class="spec-t">/</span></td>
  3202. <td class="spec-rhs"><span class="spec-t">b</span></td>
  3203. <td class="spec-rhs"><span class="spec-t">f</span></td>
  3204. <td class="spec-rhs"><span class="spec-t">n</span></td>
  3205. <td class="spec-rhs"><span class="spec-t">r</span></td>
  3206. <td class="spec-rhs"><span class="spec-t">t</span></td>
  3207. </tr>
  3208. </table>
  3209. </div>
  3210. </section>
  3211. <section id="sec-Syntax">
  3212. <h3><span class="spec-secnum" title="link to this section"><a href="#sec-Syntax">8.3</a></span>Syntax</h3>
  3213. <p>A GraphQL document is defined in a syntactic grammar where terminal symbols are expressed as either an italicized token (ex. <span class="spec-nt"><a href="#Document">Document</a></span>) or as monospaced short&#8208;hand for a <span class="spec-nt"><a href="#Punctuator">Punctuator</a></span> (ex. <span class="spec-t">:</span>) or short&#8208;hand for a <span class="spec-nt"><a href="#Name">Name</a></span> (ex. <span class="spec-t">query</span>).</p>
  3214. <p>Since whitespace, comments, and other ignored source is skipped between each well&#8208;formed token, this ignored source can appear at any point between the terminal tokens in the syntactic grammars defined below. However GraphQL source documents
  3215. are encouraged to use ignored source only to improve legibility.</p>
  3216. <section id="sec-Syntax.Document">
  3217. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Syntax.Document">8.3.1</a></span>Document</h4>
  3218. <p>A GraphQL document describes a complete file or request string. A document contains multiple definitions including an Operation.</p>
  3219. <div class="spec-production" id="Document"><span class="spec-nt"><a href="#Document">Document</a></span>
  3220. <div class="spec-rhs"><span class="spec-nt list"><a href="#Definition">Definition</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3221. </span>
  3222. </div>
  3223. </div>
  3224. <div class="spec-production" id="Definition"><span class="spec-nt"><a href="#Definition">Definition</a></span>
  3225. <div class="spec-rhs"><span class="spec-nt"><a href="#OperationDefinition">OperationDefinition</a></span></div>
  3226. <div class="spec-rhs"><span class="spec-nt"><a href="#FragmentDefinition">FragmentDefinition</a></span></div>
  3227. </div>
  3228. </section>
  3229. <section id="sec-Syntax.Operations">
  3230. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Syntax.Operations">8.3.2</a></span>Operations</h4>
  3231. <p>An operation describes some type of request to GraphQL. The most common operation is a <code>query</code>, a read&#8208;only request for data from GraphQL. A short&#8208;hand syntax exists for a query operation.</p>
  3232. <div class="spec-production"
  3233. id="OperationDefinition"><span class="spec-nt"><a href="#OperationDefinition">OperationDefinition</a></span>
  3234. <div class="spec-rhs"><span class="spec-nt"><a href="#SelectionSet">SelectionSet</a></span></div>
  3235. <div class="spec-rhs"><span class="spec-nt"><a href="#OperationType">OperationType</a></span><span class="spec-nt"><a href="#Name">Name</a></span><span class="spec-nt optional"><a href="#VariableDefinitions">VariableDefinitions</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3236. </span><span class="spec-nt optional"><a href="#Directives">Directives</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3237. </span><span class="spec-nt"><a href="#SelectionSet">SelectionSet</a></span></div>
  3238. </div>
  3239. <div class="spec-production oneof" id="OperationType"><span class="spec-nt"><a href="#OperationType">OperationType</a></span>
  3240. <table>
  3241. <tr>
  3242. <td class="spec-rhs"><span class="spec-t">query</span></td>
  3243. <td class="spec-rhs"><span class="spec-t">mutation</span></td>
  3244. </tr>
  3245. </table>
  3246. </div>
  3247. <div class="spec-production" id="VariableDefinitions"><span class="spec-nt"><a href="#VariableDefinitions">VariableDefinitions</a></span>
  3248. <div class="spec-rhs"><span class="spec-t">(</span><span class="spec-nt list"><a href="#VariableDefinition">VariableDefinition</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3249. </span><span class="spec-t">)</span></div>
  3250. </div>
  3251. <div class="spec-production" id="VariableDefinition"><span class="spec-nt"><a href="#VariableDefinition">VariableDefinition</a></span>
  3252. <div class="spec-rhs"><span class="spec-nt"><a href="#Variable">Variable</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Type">Type</a></span><span class="spec-nt optional"><a href="#DefaultValue">DefaultValue</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3253. </span>
  3254. </div>
  3255. </div>
  3256. <div class="spec-production" id="Variable"><span class="spec-nt"><a href="#Variable">Variable</a></span>
  3257. <div class="spec-rhs"><span class="spec-t">$</span><span class="spec-nt"><a href="#Name">Name</a></span></div>
  3258. </div>
  3259. <div class="spec-production" id="DefaultValue"><span class="spec-nt"><a href="#DefaultValue">DefaultValue</a></span>
  3260. <div class="spec-rhs"><span class="spec-t">=</span><span class="spec-nt"><a href="#Value">Value</a><span class="spec-mods"><span class="spec-params"><span class="spec-param">Const</span></span>
  3261. </span>
  3262. </span>
  3263. </div>
  3264. </div>
  3265. <div class="spec-production" id="SelectionSet"><span class="spec-nt"><a href="#SelectionSet">SelectionSet</a></span>
  3266. <div class="spec-rhs"><span class="spec-t">{</span><span class="spec-nt list"><a href="#Selection">Selection</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3267. </span><span class="spec-t">}</span></div>
  3268. </div>
  3269. <div class="spec-production" id="Selection"><span class="spec-nt"><a href="#Selection">Selection</a></span>
  3270. <div class="spec-rhs"><span class="spec-nt"><a href="#Field">Field</a></span></div>
  3271. <div class="spec-rhs"><span class="spec-nt"><a href="#FragmentSpread">FragmentSpread</a></span></div>
  3272. <div class="spec-rhs"><span class="spec-nt"><a href="#InlineFragment">InlineFragment</a></span></div>
  3273. </div>
  3274. <div class="spec-production" id="Field"><span class="spec-nt"><a href="#Field">Field</a></span>
  3275. <div class="spec-rhs"><span class="spec-nt optional"><a href="#Alias">Alias</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3276. </span><span class="spec-nt"><a href="#Name">Name</a></span><span class="spec-nt optional"><a href="#Arguments">Arguments</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3277. </span><span class="spec-nt optional"><a href="#Directives">Directives</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3278. </span><span class="spec-nt optional"><a href="#SelectionSet">SelectionSet</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3279. </span>
  3280. </div>
  3281. </div>
  3282. <div class="spec-production" id="Alias"><span class="spec-nt"><a href="#Alias">Alias</a></span>
  3283. <div class="spec-rhs"><span class="spec-nt"><a href="#Name">Name</a></span><span class="spec-t">:</span></div>
  3284. </div>
  3285. <div class="spec-production" id="Arguments"><span class="spec-nt"><a href="#Arguments">Arguments</a></span>
  3286. <div class="spec-rhs"><span class="spec-t">(</span><span class="spec-nt list"><a href="#Argument">Argument</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3287. </span><span class="spec-t">)</span></div>
  3288. </div>
  3289. <div class="spec-production" id="Argument"><span class="spec-nt"><a href="#Argument">Argument</a></span>
  3290. <div class="spec-rhs"><span class="spec-nt"><a href="#Name">Name</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Value">Value</a></span></div>
  3291. </div>
  3292. </section>
  3293. <section id="sec-Syntax.Fragments">
  3294. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Syntax.Fragments">8.3.3</a></span>Fragments</h4>
  3295. <p>Fragments allow for the reuse of common selections of fields, reducing duplicated text in the document. Inline fragments can be used directly inline a selection to apply a type condition when querying against an interface or union.</p>
  3296. <div class="spec-production"
  3297. id="FragmentSpread"><span class="spec-nt"><a href="#FragmentSpread">FragmentSpread</a></span>
  3298. <div class="spec-rhs"><span class="spec-t">...</span><span class="spec-nt"><a href="#FragmentName">FragmentName</a></span><span class="spec-nt optional"><a href="#Directives">Directives</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3299. </span>
  3300. </div>
  3301. </div>
  3302. <div class="spec-production" id="InlineFragment"><span class="spec-nt"><a href="#InlineFragment">InlineFragment</a></span>
  3303. <div class="spec-rhs"><span class="spec-t">...</span><span class="spec-t">on</span><span class="spec-nt"><a href="#TypeCondition">TypeCondition</a></span><span class="spec-nt optional"><a href="#Directives">Directives</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3304. </span><span class="spec-nt"><a href="#SelectionSet">SelectionSet</a></span></div>
  3305. </div>
  3306. <div class="spec-production" id="FragmentDefinition"><span class="spec-nt"><a href="#FragmentDefinition">FragmentDefinition</a></span>
  3307. <div class="spec-rhs"><span class="spec-t">fragment</span><span class="spec-nt"><a href="#FragmentName">FragmentName</a></span><span class="spec-t">on</span><span class="spec-nt"><a href="#TypeCondition">TypeCondition</a></span><span class="spec-nt optional"><a href="#Directives">Directives</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3308. </span><span class="spec-nt"><a href="#SelectionSet">SelectionSet</a></span></div>
  3309. </div>
  3310. <div class="spec-production" id="FragmentName"><span class="spec-nt"><a href="#FragmentName">FragmentName</a></span>
  3311. <div class="spec-rhs"><span class="spec-lookahead not"><span class="spec-t">on</span></span><span class="spec-nt"><a href="#Name">Name</a></span></div>
  3312. </div>
  3313. <div class="spec-production" id="TypeCondition"><span class="spec-nt"><a href="#TypeCondition">TypeCondition</a></span>
  3314. <div class="spec-rhs"><span class="spec-nt"><a href="#TypeName">TypeName</a></span></div>
  3315. </div>
  3316. </section>
  3317. <section id="sec-Values">
  3318. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Values">8.3.4</a></span>Values</h4>
  3319. <p>Fields may take values for arguments. A value may be any JSON&#8208;style value, a variable or an Enum value.</p>
  3320. <div class="spec-production" id="Value"><span class="spec-nt"><a href="#Value">Value</a><span class="spec-mods"><span class="spec-params"><span class="spec-param">Const</span></span>
  3321. </span>
  3322. </span>
  3323. <div class="spec-rhs"><span class="spec-condition not">Const</span><span class="spec-nt"><a href="#Variable">Variable</a></span></div>
  3324. <div class="spec-rhs"><span class="spec-nt"><a href="#IntValue">IntValue</a></span></div>
  3325. <div class="spec-rhs"><span class="spec-nt"><a href="#FloatValue">FloatValue</a></span></div>
  3326. <div class="spec-rhs"><span class="spec-nt"><a href="#StringValue">StringValue</a></span></div>
  3327. <div class="spec-rhs"><span class="spec-nt"><a href="#BooleanValue">BooleanValue</a></span></div>
  3328. <div class="spec-rhs"><span class="spec-nt"><a href="#EnumValue">EnumValue</a></span></div>
  3329. <div class="spec-rhs"><span class="spec-nt"><a href="#ArrayValue">ArrayValue</a><span class="spec-mods"><span class="spec-params"><span class="spec-param conditional">Const</span></span>
  3330. </span>
  3331. </span>
  3332. </div>
  3333. <div class="spec-rhs"><span class="spec-nt"><a href="#ObjectValue">ObjectValue</a><span class="spec-mods"><span class="spec-params"><span class="spec-param conditional">Const</span></span>
  3334. </span>
  3335. </span>
  3336. </div>
  3337. </div>
  3338. <div class="spec-production" id="BooleanValue"><span class="spec-nt"><a href="#BooleanValue">BooleanValue</a></span>
  3339. <div class="spec-rhs"><span class="spec-t">true</span></div>
  3340. <div class="spec-rhs"><span class="spec-t">false</span></div>
  3341. </div>
  3342. <div class="spec-production" id="EnumValue"><span class="spec-nt"><a href="#EnumValue">EnumValue</a></span>
  3343. <div class="spec-rhs"><span class="spec-nt"><a href="#Name">Name</a></span></div>
  3344. </div>
  3345. <section id="sec-Array-Value">
  3346. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Array-Value">8.3.4.1</a></span>Array Value</h5>
  3347. <div class="spec-production" id="ArrayValue"><span class="spec-nt"><a href="#ArrayValue">ArrayValue</a><span class="spec-mods"><span class="spec-params"><span class="spec-param">Const</span></span>
  3348. </span>
  3349. </span>
  3350. <div class="spec-rhs"><span class="spec-t">[</span><span class="spec-t">]</span></div>
  3351. <div class="spec-rhs"><span class="spec-t">[</span><span class="spec-nt list"><a href="#Value">Value</a><span class="spec-mods"><span class="spec-params"><span class="spec-param conditional">Const</span></span><span class="spec-mod list">list</span></span>
  3352. </span><span class="spec-t">]</span></div>
  3353. </div>
  3354. <p><strong>Semantics</strong></p>
  3355. <div class="spec-semantic"><span class="spec-nt"><a href="#ArrayValue">ArrayValue</a></span>
  3356. <div class="spec-rhs"><span class="spec-t">[</span><span class="spec-t">]</span></div>
  3357. <ol>
  3358. <li>Return a new empty list value.</li>
  3359. </ol>
  3360. </div>
  3361. <div class="spec-semantic"><span class="spec-nt"><a href="#ArrayValue">ArrayValue</a></span>
  3362. <div class="spec-rhs"><span class="spec-t">[</span><span class="spec-nt list"><a href="#Value">Value</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3363. </span><span class="spec-t">]</span></div>
  3364. <ol>
  3365. <li>Let <var>inputList</var> be a new empty list value.</li>
  3366. <li>For each <span class="spec-nt list"><a href="#Value">Value</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3367. </span>
  3368. <ol>
  3369. <li>Let <var>value</var> be the result of evaluating <span class="spec-nt"><a href="#Value">Value</a></span>.</li>
  3370. <li>Append <var>value</var> to <var>inputList</var>.</li>
  3371. </ol>
  3372. </li>
  3373. <li>Return <var>inputList</var></li>
  3374. </ol>
  3375. </div>
  3376. </section>
  3377. <section id="sec-Object-Value">
  3378. <h5><span class="spec-secnum" title="link to this section"><a href="#sec-Object-Value">8.3.4.2</a></span>Object Value</h5>
  3379. <div class="spec-production" id="ObjectValue"><span class="spec-nt"><a href="#ObjectValue">ObjectValue</a><span class="spec-mods"><span class="spec-params"><span class="spec-param">Const</span></span>
  3380. </span>
  3381. </span>
  3382. <div class="spec-rhs"><span class="spec-t">{</span><span class="spec-t">}</span></div>
  3383. <div class="spec-rhs"><span class="spec-t">{</span><span class="spec-nt list"><a href="#ObjectField">ObjectField</a><span class="spec-mods"><span class="spec-params"><span class="spec-param conditional">Const</span></span><span class="spec-mod list">list</span></span>
  3384. </span><span class="spec-t">}</span></div>
  3385. </div>
  3386. <div class="spec-production" id="ObjectField"><span class="spec-nt"><a href="#ObjectField">ObjectField</a><span class="spec-mods"><span class="spec-params"><span class="spec-param">Const</span></span>
  3387. </span>
  3388. </span>
  3389. <div class="spec-rhs"><span class="spec-nt"><a href="#Name">Name</a></span><span class="spec-t">:</span><span class="spec-nt"><a href="#Value">Value</a><span class="spec-mods"><span class="spec-params"><span class="spec-param conditional">Const</span></span>
  3390. </span>
  3391. </span>
  3392. </div>
  3393. </div>
  3394. <p><strong>Semantics</strong></p>
  3395. <div class="spec-semantic"><span class="spec-nt"><a href="#ObjectValue">ObjectValue</a></span>
  3396. <div class="spec-rhs"><span class="spec-t">{</span><span class="spec-t">}</span></div>
  3397. <ol>
  3398. <li>Return a new input object value with no fields.</li>
  3399. </ol>
  3400. </div>
  3401. <div class="spec-semantic"><span class="spec-nt"><a href="#ObjectValue">ObjectValue</a></span>
  3402. <div class="spec-rhs"><span class="spec-t">{</span><span class="spec-nt list"><a href="#ObjectField">ObjectField</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3403. </span><span class="spec-t">}</span></div>
  3404. <ol>
  3405. <li>Let <var>inputObject</var> be a new input object value with no fields.</li>
  3406. <li>For each <var>field</var> in <span class="spec-nt list"><a href="#ObjectField">ObjectField</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3407. </span>
  3408. <ol>
  3409. <li>Let <var>name</var> be <span class="spec-nt"><a href="#Name">Name</a></span> in <var>field</var>.</li>
  3410. <li>If <var>inputObject</var> contains a field named <var>name</var> throw Syntax Error.</li>
  3411. <li>Let <var>value</var> be the result of evaluating <span class="spec-nt"><a href="#Value">Value</a></span> in <var>field</var>.</li>
  3412. <li>Add a field to <var>inputObject</var> of name <var>name</var> containing value <var>value</var>.</li>
  3413. </ol>
  3414. </li>
  3415. <li>Return <var>inputObject</var></li>
  3416. </ol>
  3417. </div>
  3418. </section>
  3419. </section>
  3420. <section id="sec-Syntax.Directives">
  3421. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Syntax.Directives">8.3.5</a></span>Directives</h4>
  3422. <p>Directives provide a way to describe runtime execution and type validation behavior in a GraphQL document.</p>
  3423. <div class="spec-production" id="Directives"><span class="spec-nt"><a href="#Directives">Directives</a></span>
  3424. <div class="spec-rhs"><span class="spec-nt list"><a href="#Directive">Directive</a><span class="spec-mods"><span class="spec-mod list">list</span></span>
  3425. </span>
  3426. </div>
  3427. </div>
  3428. <div class="spec-production" id="Directive"><span class="spec-nt"><a href="#Directive">Directive</a></span>
  3429. <div class="spec-rhs"><span class="spec-t">@</span><span class="spec-nt"><a href="#Name">Name</a></span><span class="spec-nt optional"><a href="#Arguments">Arguments</a><span class="spec-mods"><span class="spec-mod optional">opt</span></span>
  3430. </span>
  3431. </div>
  3432. </div>
  3433. </section>
  3434. <section id="sec-Syntax.Types">
  3435. <h4><span class="spec-secnum" title="link to this section"><a href="#sec-Syntax.Types">8.3.6</a></span>Types</h4>
  3436. <p>GraphQL describes the schema of the data it provides using a type system. These types are referred to in the document when defining query variables.</p>
  3437. <div class="spec-production" id="Type"><span class="spec-nt"><a href="#Type">Type</a></span>
  3438. <div class="spec-rhs"><span class="spec-nt"><a href="#TypeName">TypeName</a></span></div>
  3439. <div class="spec-rhs"><span class="spec-nt"><a href="#ListType">ListType</a></span></div>
  3440. <div class="spec-rhs"><span class="spec-nt"><a href="#NonNullType">NonNullType</a></span></div>
  3441. </div>
  3442. <div class="spec-production" id="TypeName"><span class="spec-nt"><a href="#TypeName">TypeName</a></span>
  3443. <div class="spec-rhs"><span class="spec-nt"><a href="#Name">Name</a></span></div>
  3444. </div>
  3445. <div class="spec-production" id="ListType"><span class="spec-nt"><a href="#ListType">ListType</a></span>
  3446. <div class="spec-rhs"><span class="spec-t">[</span><span class="spec-nt"><a href="#Type">Type</a></span><span class="spec-t">]</span></div>
  3447. </div>
  3448. <div class="spec-production" id="NonNullType"><span class="spec-nt"><a href="#NonNullType">NonNullType</a></span>
  3449. <div class="spec-rhs"><span class="spec-nt"><a href="#TypeName">TypeName</a></span><span class="spec-t">!</span></div>
  3450. <div class="spec-rhs"><span class="spec-nt"><a href="#ListType">ListType</a></span><span class="spec-t">!</span></div>
  3451. </div>
  3452. <p><strong>Semantics</strong></p>
  3453. <div class="spec-semantic"><span class="spec-nt"><a href="#Type">Type</a></span>
  3454. <div class="spec-rhs"><span class="spec-nt"><a href="#Name">Name</a></span></div>
  3455. <ol>
  3456. <li>Let <var>name</var> be the string value of <span class="spec-nt"><a href="#Name">Name</a></span></li>
  3457. <li>Let <var>type</var> be the type defined in the Schema named <var>name</var></li>
  3458. <li><var>type</var> must not be <span class="spec-keyword">null</span></li>
  3459. <li>Return <var>type</var></li>
  3460. </ol>
  3461. </div>
  3462. <div class="spec-semantic"><span class="spec-nt"><a href="#Type">Type</a></span>
  3463. <div class="spec-rhs"><span class="spec-t">[</span><span class="spec-nt"><a href="#Type">Type</a></span><span class="spec-t">]</span></div>
  3464. <ol>
  3465. <li>Let <var>itemType</var> be the result of evaluating <span class="spec-nt"><a href="#Type">Type</a></span></li>
  3466. <li>Let <var>type</var> be a List type where <var>itemType</var> is the contained type.</li>
  3467. <li>Return <var>type</var></li>
  3468. </ol>
  3469. </div>
  3470. <div class="spec-semantic"><span class="spec-nt"><a href="#Type">Type</a></span>
  3471. <div class="spec-rhs"><span class="spec-nt"><a href="#Type">Type</a></span><span class="spec-t">!</span></div>
  3472. <ol>
  3473. <li>Let <var>nullableType</var> be the result of evaluating <span class="spec-nt"><a href="#Type">Type</a></span></li>
  3474. <li>Let <var>type</var> be a Non&#8208;Null type where <var>nullableType</var> is the contained type.</li>
  3475. <li>Return <var>type</var> </li>
  3476. </ol>
  3477. </div>
  3478. </section>
  3479. </section>
  3480. </section>
  3481. <footer>Written in <a href="http://leebyron.com/spec-md/" target="_blank">Spec Markdown</a>.</footer></p>
  3482. </article>
  3483. </section>
  3484. <nav id="jumpto">
  3485. <p>
  3486. <a href="/david/blog/">Accueil du blog</a> |
  3487. <a href="http://facebook.github.io/graphql/">Source originale</a> |
  3488. <a href="/david/stream/2019/">Accueil du flux</a>
  3489. </p>
  3490. </nav>
  3491. <footer>
  3492. <div>
  3493. <img src="/static/david/david-larlet-avatar.jpg" loading="lazy" class="avatar" width="200" height="200">
  3494. <p>
  3495. Bonjour/Hi!
  3496. Je suis <a href="/david/" title="Profil public">David&nbsp;Larlet</a>, je vis actuellement à Montréal et j’alimente cet espace depuis 15 ans. <br>
  3497. Si tu as apprécié cette lecture, n’hésite pas à poursuivre ton exploration. Par exemple via les <a href="/david/blog/" title="Expériences bienveillantes">réflexions bimestrielles</a>, la <a href="/david/stream/2019/" title="Pensées (dés)articulées">veille hebdomadaire</a> ou en t’abonnant au <a href="/david/log/" title="S’abonner aux publications via RSS">flux RSS</a> (<a href="/david/blog/2019/flux-rss/" title="Tiens c’est quoi un flux RSS ?">so 2005</a>).
  3498. </p>
  3499. <p>
  3500. Je m’intéresse à la place que je peux avoir dans ce monde. En tant qu’humain, en tant que membre d’une famille et en tant qu’associé d’une coopérative. De temps en temps, je fais aussi des <a href="https://github.com/davidbgk" title="Principalement sur Github mais aussi ailleurs">trucs techniques</a>. Et encore plus rarement, <a href="/david/talks/" title="En ce moment je laisse plutôt la place aux autres">j’en parle</a>.
  3501. </p>
  3502. <p>
  3503. Voici quelques articles choisis :
  3504. <a href="/david/blog/2019/faire-equipe/" title="Accéder à l’article complet">Faire équipe</a>,
  3505. <a href="/david/blog/2018/bivouac-automnal/" title="Accéder à l’article complet">Bivouac automnal</a>,
  3506. <a href="/david/blog/2018/commodite-effondrement/" title="Accéder à l’article complet">Commodité et effondrement</a>,
  3507. <a href="/david/blog/2017/donnees-communs/" title="Accéder à l’article complet">Des données aux communs</a>,
  3508. <a href="/david/blog/2016/accompagner-enfant/" title="Accéder à l’article complet">Accompagner un enfant</a>,
  3509. <a href="/david/blog/2016/senior-developer/" title="Accéder à l’article complet">Senior developer</a>,
  3510. <a href="/david/blog/2016/illusion-sociale/" title="Accéder à l’article complet">L’illusion sociale</a>,
  3511. <a href="/david/blog/2016/instantane-scopyleft/" title="Accéder à l’article complet">Instantané Scopyleft</a>,
  3512. <a href="/david/blog/2016/enseigner-web/" title="Accéder à l’article complet">Enseigner le Web</a>,
  3513. <a href="/david/blog/2016/simplicite-defaut/" title="Accéder à l’article complet">Simplicité par défaut</a>,
  3514. <a href="/david/blog/2016/minimalisme-esthetique/" title="Accéder à l’article complet">Minimalisme et esthétique</a>,
  3515. <a href="/david/blog/2014/un-web-omni-present/" title="Accéder à l’article complet">Un web omni-présent</a>,
  3516. <a href="/david/blog/2014/manifeste-developpeur/" title="Accéder à l’article complet">Manifeste de développeur</a>,
  3517. <a href="/david/blog/2013/confort-convivialite/" title="Accéder à l’article complet">Confort et convivialité</a>,
  3518. <a href="/david/blog/2013/testament-numerique/" title="Accéder à l’article complet">Testament numérique</a>,
  3519. et <a href="/david/blog/" title="Accéder aux archives">bien d’autres…</a>
  3520. </p>
  3521. <p>
  3522. On peut <a href="mailto:david%40larlet.fr" title="Envoyer un courriel">échanger par courriel</a>. Si éventuellement tu souhaites que l’on travaille ensemble, tu devrais commencer par consulter le <a href="http://larlet.com">profil dédié à mon activité professionnelle</a> et/ou contacter directement <a href="http://scopyleft.fr/">scopyleft</a>, la <abbr title="Société coopérative et participative">SCOP</abbr> dont je fais partie depuis six ans. Je recommande au préalable de lire <a href="/david/blog/2018/cout-site/" title="Attention ce qui va suivre peut vous choquer">combien coûte un site</a> et pourquoi je suis plutôt favorable à une <a href="/david/pro/devis/" title="Discutons-en !">non-demande de devis</a>.
  3523. </p>
  3524. <p>
  3525. Je ne traque pas ta navigation mais mon
  3526. <abbr title="Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33.184162340">hébergeur</abbr>
  3527. conserve des logs d’accès.
  3528. </p>
  3529. </div>
  3530. </footer>
  3531. <script type="text/javascript">
  3532. ;(_ => {
  3533. const jumper = document.getElementById('jumper')
  3534. jumper.addEventListener('click', e => {
  3535. e.preventDefault()
  3536. const anchor = e.target.getAttribute('href')
  3537. const targetEl = document.getElementById(anchor.substring(1))
  3538. targetEl.scrollIntoView({behavior: 'smooth'})
  3539. })
  3540. })()
  3541. </script>