introspection.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package interpreter
  11. import (
  12. "fmt"
  13. "strings"
  14. "devt.de/krotik/common/lang/graphql/parser"
  15. )
  16. /*
  17. ProcessIntrospection filters the full introspection down to the required fields.
  18. */
  19. func (rt *selectionSetRuntime) ProcessIntrospection() map[string]interface{} {
  20. return rt.FilterIntrospectionResponse(rt.ProcessFullIntrospection())
  21. }
  22. /*
  23. ProcessFullIntrospection returns the full introspection with all known fields.
  24. */
  25. func (rt *selectionSetRuntime) ProcessFullIntrospection() map[string]interface{} {
  26. res := make(map[string]interface{})
  27. fieldMap := rt.GetFields()
  28. for symbol := range fieldMap {
  29. // General types
  30. if symbol == "queryType" {
  31. res["queryType"] = map[string]interface{}{
  32. "name": "Query",
  33. }
  34. if !rt.rtp.readOnly {
  35. res["mutationType"] = map[string]interface{}{
  36. "name": "Mutation",
  37. }
  38. } else {
  39. res["mutationType"] = nil
  40. }
  41. res["subscriptionType"] = map[string]interface{}{
  42. "name": "Subscription",
  43. }
  44. }
  45. if symbol == "types" {
  46. res["types"] = rt.GetTypesIntrospection()
  47. }
  48. if symbol == "directives" {
  49. res["directives"] = rt.GetDirectivesIntrospection()
  50. }
  51. }
  52. return res
  53. }
  54. func (rt *selectionSetRuntime) FilterIntrospectionResponse(res map[string]interface{}) map[string]interface{} {
  55. filteredRes := make(map[string]interface{})
  56. fieldMap := rt.GetFields()
  57. for symbol, field := range fieldMap {
  58. reschild := res[symbol]
  59. if srt := field.SelectionSetRuntime(); srt != nil {
  60. // Check for list
  61. if reschildList, ok := reschild.([]interface{}); ok {
  62. filterResList := []interface{}{}
  63. for _, reschild := range reschildList {
  64. filterResList = append(filterResList, srt.FilterIntrospectionResponse(reschild.(map[string]interface{})))
  65. }
  66. filteredRes[symbol] = filterResList
  67. } else if reschildMap, ok := reschild.(map[string]interface{}); ok {
  68. filteredRes[symbol] = srt.FilterIntrospectionResponse(reschildMap)
  69. } else {
  70. filteredRes[symbol] = reschild
  71. }
  72. } else {
  73. filteredRes[symbol] = reschild
  74. }
  75. }
  76. return filteredRes
  77. }
  78. /*
  79. GetTypesIntrospection returns the introspection for all available types.
  80. */
  81. func (rt *selectionSetRuntime) GetTypesIntrospection() interface{} {
  82. res := make([]interface{}, 0)
  83. queryType := map[string]interface{}{
  84. "kind": "OBJECT",
  85. "name": "Query",
  86. "description": "Entry point for single read queryies.",
  87. "fields": rt.GetFieldTypesIntrospection("Lookup", true),
  88. "inputFields": nil,
  89. "interfaces": []interface{}{},
  90. "enumValues": nil,
  91. "possibleTypes": nil,
  92. }
  93. res = append(res, queryType)
  94. if !rt.rtp.readOnly {
  95. mutationType := map[string]interface{}{
  96. "kind": "OBJECT",
  97. "name": "Mutation",
  98. "description": "Entry point for writing queryies.",
  99. "fields": rt.GetFieldTypesIntrospection("Insert or modify", false),
  100. "inputFields": nil,
  101. "interfaces": []interface{}{},
  102. "enumValues": nil,
  103. "possibleTypes": nil,
  104. }
  105. res = append(res, mutationType)
  106. }
  107. subscriptionType := map[string]interface{}{
  108. "kind": "OBJECT",
  109. "name": "Subscription",
  110. "description": "Entry point for subscriptions.",
  111. "fields": rt.GetFieldTypesIntrospection("Subscribe to", true),
  112. "inputFields": nil,
  113. "interfaces": []interface{}{},
  114. "enumValues": nil,
  115. "possibleTypes": nil,
  116. }
  117. res = append(res, subscriptionType)
  118. // Add EliasDB specific types
  119. res = append(res, rt.GetEliasDBTypesIntrospection().([]interface{})...)
  120. // Add all the default GraphQL types like __Schema, __Type, etc.
  121. res = append(res, rt.GetStandardTypesIntrospection().([]interface{})...)
  122. return res
  123. }
  124. /*
  125. GetFieldTypesIntrospection returns the introspection for all available field types.
  126. */
  127. func (rt *selectionSetRuntime) GetFieldTypesIntrospection(action string, lookupArgs bool) interface{} {
  128. var args []interface{}
  129. res := make([]interface{}, 0)
  130. if lookupArgs {
  131. args = []interface{}{
  132. map[string]interface{}{
  133. "name": "key",
  134. "defaultValue": nil,
  135. "description": "Lookup a particular node by key.",
  136. "type": map[string]interface{}{
  137. "kind": "SCALAR",
  138. "name": "String",
  139. "ofType": nil,
  140. },
  141. },
  142. map[string]interface{}{
  143. "name": "matches",
  144. "defaultValue": nil,
  145. "description": "Lookup nodes matching this template.",
  146. "type": map[string]interface{}{
  147. "kind": "OBJECT",
  148. "name": "NodeTemplate",
  149. "ofType": nil,
  150. },
  151. },
  152. map[string]interface{}{
  153. "name": "storeNode",
  154. "defaultValue": nil,
  155. "description": "Store a node according to this template.",
  156. "type": map[string]interface{}{
  157. "kind": "OBJECT",
  158. "name": "NodeTemplate",
  159. "ofType": nil,
  160. },
  161. },
  162. map[string]interface{}{
  163. "name": "removeNode",
  164. "defaultValue": nil,
  165. "description": "Remove a node according to this template (only kind is needed).",
  166. "type": map[string]interface{}{
  167. "kind": "OBJECT",
  168. "name": "NodeTemplate",
  169. "ofType": nil,
  170. },
  171. },
  172. map[string]interface{}{
  173. "name": "storeEdge",
  174. "defaultValue": nil,
  175. "description": "Store an edge according to this template.",
  176. "type": map[string]interface{}{
  177. "kind": "OBJECT",
  178. "name": "NodeTemplate",
  179. "ofType": nil,
  180. },
  181. },
  182. map[string]interface{}{
  183. "name": "removeEdge",
  184. "defaultValue": nil,
  185. "description": "Remove an edge according to this template (only key and kind are needed).",
  186. "type": map[string]interface{}{
  187. "kind": "OBJECT",
  188. "name": "NodeTemplate",
  189. "ofType": nil,
  190. },
  191. },
  192. map[string]interface{}{
  193. "name": "ascending",
  194. "defaultValue": nil,
  195. "description": "Sort resuting data ascending using the values of the specified key.",
  196. "type": map[string]interface{}{
  197. "kind": "SCALAR",
  198. "name": "String",
  199. "ofType": nil,
  200. },
  201. },
  202. map[string]interface{}{
  203. "name": "descending",
  204. "defaultValue": nil,
  205. "description": "Sort resuting data descending using the values of the specified key.",
  206. "type": map[string]interface{}{
  207. "kind": "SCALAR",
  208. "name": "String",
  209. "ofType": nil,
  210. },
  211. },
  212. map[string]interface{}{
  213. "name": "from",
  214. "defaultValue": nil,
  215. "description": "Retrieve data after the first n entries.",
  216. "type": map[string]interface{}{
  217. "kind": "SCALAR",
  218. "name": "Int",
  219. "ofType": nil,
  220. },
  221. },
  222. map[string]interface{}{
  223. "name": "items",
  224. "defaultValue": nil,
  225. "description": "Retrieve n entries.",
  226. "type": map[string]interface{}{
  227. "kind": "SCALAR",
  228. "name": "Int",
  229. "ofType": nil,
  230. },
  231. },
  232. map[string]interface{}{
  233. "name": "last",
  234. "defaultValue": nil,
  235. "description": "Only return last n entries.",
  236. "type": map[string]interface{}{
  237. "kind": "SCALAR",
  238. "name": "Int",
  239. "ofType": nil,
  240. },
  241. },
  242. }
  243. } else {
  244. args = []interface{}{}
  245. }
  246. for _, kind := range rt.rtp.gm.NodeKinds() {
  247. res = append(res, map[string]interface{}{
  248. "name": kind,
  249. "description": fmt.Sprintf("%s %s nodes in the datastore.", action, kind),
  250. "args": args,
  251. "type": map[string]interface{}{
  252. "kind": "LIST",
  253. "name": nil,
  254. "ofType": map[string]interface{}{
  255. "kind": "OBJECT",
  256. "name": fmt.Sprintf("%sNode", strings.Title(kind)),
  257. "ofType": nil,
  258. },
  259. },
  260. "isDeprecated": false,
  261. "deprecationReason": nil,
  262. })
  263. }
  264. return res
  265. }
  266. /*
  267. GetEliasDBTypesIntrospection returns EliasDB types.
  268. */
  269. func (rt *selectionSetRuntime) GetEliasDBTypesIntrospection() interface{} {
  270. res := make([]interface{}, 0)
  271. for _, kind := range rt.rtp.gm.NodeKinds() {
  272. fields := make([]interface{}, 0)
  273. for _, attr := range rt.rtp.gm.NodeAttrs(kind) {
  274. fields = append(fields, map[string]interface{}{
  275. "name": attr,
  276. "description": fmt.Sprintf("The %s attribute of a %s node.", attr, kind),
  277. "args": []interface{}{},
  278. "type": map[string]interface{}{
  279. "kind": "SCALAR",
  280. "name": "String",
  281. "ofType": nil,
  282. },
  283. "isDeprecated": false,
  284. "deprecationReason": nil,
  285. })
  286. }
  287. for _, edge := range rt.rtp.gm.NodeEdges(kind) {
  288. edgeName := strings.Replace(edge, ":", "_", -1)
  289. edgeTargetKind := strings.Split(edge, ":")[3]
  290. fields = append(fields, map[string]interface{}{
  291. "name": edgeName,
  292. "description": fmt.Sprintf("The %s edge of a %s node to a %s node.", edge, kind, edgeTargetKind),
  293. "args": []interface{}{
  294. map[string]interface{}{
  295. "name": "traverse",
  296. "defaultValue": nil,
  297. "description": fmt.Sprintf("Use %s to traverse from %s to %s.", edge, kind, edgeTargetKind),
  298. "type": map[string]interface{}{
  299. "kind": "NON_NULL",
  300. "name": nil,
  301. "ofType": map[string]interface{}{
  302. "kind": "SCALAR",
  303. "name": "String",
  304. "ofType": nil,
  305. },
  306. },
  307. },
  308. map[string]interface{}{
  309. "name": "matches",
  310. "defaultValue": nil,
  311. "description": "Lookup nodes matching this template.",
  312. "type": map[string]interface{}{
  313. "kind": "OBJECT",
  314. "name": "NodeTemplate",
  315. "ofType": nil,
  316. },
  317. },
  318. map[string]interface{}{
  319. "name": "ascending",
  320. "defaultValue": nil,
  321. "description": "Sort resuting data ascending using the values of the specified key.",
  322. "type": map[string]interface{}{
  323. "kind": "SCALAR",
  324. "name": "String",
  325. "ofType": nil,
  326. },
  327. },
  328. map[string]interface{}{
  329. "name": "descending",
  330. "defaultValue": nil,
  331. "description": "Sort resuting data descending using the values of the specified key.",
  332. "type": map[string]interface{}{
  333. "kind": "SCALAR",
  334. "name": "String",
  335. "ofType": nil,
  336. },
  337. },
  338. map[string]interface{}{
  339. "name": "from",
  340. "defaultValue": nil,
  341. "description": "Retrieve data after the first n entries.",
  342. "type": map[string]interface{}{
  343. "kind": "SCALAR",
  344. "name": "Int",
  345. "ofType": nil,
  346. },
  347. },
  348. map[string]interface{}{
  349. "name": "items",
  350. "defaultValue": nil,
  351. "description": "Retrieve n entries.",
  352. "type": map[string]interface{}{
  353. "kind": "SCALAR",
  354. "name": "Int",
  355. "ofType": nil,
  356. },
  357. },
  358. map[string]interface{}{
  359. "name": "last",
  360. "defaultValue": nil,
  361. "description": "Only return last n entries.",
  362. "type": map[string]interface{}{
  363. "kind": "SCALAR",
  364. "name": "Int",
  365. "ofType": nil,
  366. },
  367. },
  368. },
  369. "type": map[string]interface{}{
  370. "kind": "LIST",
  371. "name": nil,
  372. "ofType": map[string]interface{}{
  373. "kind": "OBJECT",
  374. "name": fmt.Sprintf("%sNode", strings.Title(edgeTargetKind)),
  375. "ofType": nil,
  376. },
  377. },
  378. "isDeprecated": false,
  379. "deprecationReason": nil,
  380. })
  381. }
  382. res = append(res, map[string]interface{}{
  383. "kind": "OBJECT",
  384. "name": fmt.Sprintf("%sNode", strings.Title(kind)),
  385. "description": fmt.Sprintf("Represents a %s node.", kind),
  386. "fields": fields,
  387. "inputFields": nil,
  388. "interfaces": []interface{}{},
  389. "enumValues": nil,
  390. "possibleTypes": nil,
  391. })
  392. }
  393. res = append(res, map[string]interface{}{
  394. "kind": "INPUT_OBJECT",
  395. "name": "NodeTemplate",
  396. "description": "Template of a node. Fields of this object can either be regular expressions or direct matches. A `not_` prefix negates the condition (e.g. `not_key`).",
  397. "fields": []interface{}{},
  398. "inputFields": []interface{}{},
  399. "interfaces": []interface{}{},
  400. "enumValues": nil,
  401. "possibleTypes": nil,
  402. })
  403. return res
  404. }
  405. /*
  406. GetStandardTypesIntrospection returns the standard types.
  407. */
  408. func (rt *selectionSetRuntime) GetStandardTypesIntrospection() interface{} {
  409. res := make([]interface{}, 0)
  410. // Schema type
  411. res = append(res, map[string]interface{}{
  412. "kind": "OBJECT",
  413. "name": "__Schema",
  414. "description": "A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.",
  415. "fields": []interface{}{
  416. map[string]interface{}{
  417. "name": "types",
  418. "description": "A list of all types supported by this server.",
  419. "args": []interface{}{},
  420. "type": map[string]interface{}{
  421. "kind": "NON_NULL",
  422. "name": nil,
  423. "ofType": map[string]interface{}{
  424. "kind": "LIST",
  425. "name": nil,
  426. "ofType": map[string]interface{}{
  427. "kind": "NON_NULL",
  428. "name": nil,
  429. "ofType": map[string]interface{}{
  430. "kind": "OBJECT",
  431. "name": "__Type",
  432. "ofType": nil,
  433. },
  434. },
  435. },
  436. },
  437. "isDeprecated": false,
  438. "deprecationReason": nil,
  439. },
  440. map[string]interface{}{
  441. "name": "queryType",
  442. "description": "The type that query operations will be rooted at.",
  443. "args": []interface{}{},
  444. "type": map[string]interface{}{
  445. "kind": "NON_NULL",
  446. "name": nil,
  447. "ofType": map[string]interface{}{
  448. "kind": "OBJECT",
  449. "name": "__Type",
  450. "ofType": nil,
  451. },
  452. },
  453. "isDeprecated": false,
  454. "deprecationReason": nil,
  455. },
  456. map[string]interface{}{
  457. "name": "mutationType",
  458. "description": "The type that mutation operations will be rooted at.",
  459. "args": []interface{}{},
  460. "type": map[string]interface{}{
  461. "kind": "OBJECT",
  462. "name": "__Type",
  463. "ofType": nil,
  464. },
  465. "isDeprecated": false,
  466. "deprecationReason": nil,
  467. },
  468. map[string]interface{}{
  469. "name": "subscriptionType",
  470. "description": "The type that subscription operations will be rooted at.",
  471. "args": []interface{}{},
  472. "type": map[string]interface{}{
  473. "kind": "OBJECT",
  474. "name": "__Type",
  475. "ofType": nil,
  476. },
  477. "isDeprecated": false,
  478. "deprecationReason": nil,
  479. },
  480. map[string]interface{}{
  481. "name": "directives",
  482. "description": "A list of all directives supported by this server.",
  483. "args": []interface{}{},
  484. "type": map[string]interface{}{
  485. "kind": "NON_NULL",
  486. "name": nil,
  487. "ofType": map[string]interface{}{
  488. "kind": "LIST",
  489. "name": nil,
  490. "ofType": map[string]interface{}{
  491. "kind": "NON_NULL",
  492. "name": nil,
  493. "ofType": map[string]interface{}{
  494. "kind": "OBJECT",
  495. "name": "__Directive",
  496. "ofType": nil,
  497. },
  498. },
  499. },
  500. },
  501. "isDeprecated": false,
  502. "deprecationReason": nil,
  503. },
  504. },
  505. "inputFields": nil,
  506. "interfaces": []interface{}{},
  507. "enumValues": nil,
  508. "possibleTypes": nil,
  509. })
  510. // Type type
  511. res = append(res, map[string]interface{}{
  512. "kind": "OBJECT",
  513. "name": "__Type",
  514. "description": "The fundamental unit of the GraphQL Schema.",
  515. "fields": []interface{}{
  516. map[string]interface{}{
  517. "name": "kind",
  518. "description": nil,
  519. "args": []interface{}{},
  520. "type": map[string]interface{}{
  521. "kind": "NON_NULL",
  522. "name": nil,
  523. "ofType": map[string]interface{}{
  524. "kind": "ENUM",
  525. "name": "__TypeKind",
  526. "ofType": nil,
  527. },
  528. },
  529. "isDeprecated": false,
  530. "deprecationReason": nil,
  531. },
  532. map[string]interface{}{
  533. "name": "name",
  534. "description": nil,
  535. "args": []interface{}{},
  536. "type": map[string]interface{}{
  537. "kind": "SCALAR",
  538. "name": "String",
  539. "ofType": nil,
  540. },
  541. "isDeprecated": false,
  542. "deprecationReason": nil,
  543. },
  544. map[string]interface{}{
  545. "name": "description",
  546. "description": nil,
  547. "args": []interface{}{},
  548. "type": map[string]interface{}{
  549. "kind": "SCALAR",
  550. "name": "String",
  551. "ofType": nil,
  552. },
  553. "isDeprecated": false,
  554. "deprecationReason": nil,
  555. },
  556. map[string]interface{}{
  557. "name": "fields",
  558. "description": nil,
  559. "args": []interface{}{
  560. map[string]interface{}{
  561. "name": "includeDeprecated",
  562. "description": nil,
  563. "type": map[string]interface{}{
  564. "kind": "SCALAR",
  565. "name": "Boolean",
  566. "ofType": nil,
  567. },
  568. "defaultValue": "false",
  569. },
  570. },
  571. "type": map[string]interface{}{
  572. "kind": "LIST",
  573. "name": nil,
  574. "ofType": map[string]interface{}{
  575. "kind": "NON_NULL",
  576. "name": nil,
  577. "ofType": map[string]interface{}{
  578. "kind": "OBJECT",
  579. "name": "__Field",
  580. "ofType": nil,
  581. },
  582. },
  583. },
  584. "isDeprecated": false,
  585. "deprecationReason": nil,
  586. },
  587. map[string]interface{}{
  588. "name": "interfaces",
  589. "description": nil,
  590. "args": []interface{}{},
  591. "type": map[string]interface{}{
  592. "kind": "LIST",
  593. "name": nil,
  594. "ofType": map[string]interface{}{
  595. "kind": "NON_NULL",
  596. "name": nil,
  597. "ofType": map[string]interface{}{
  598. "kind": "OBJECT",
  599. "name": "__Type",
  600. "ofType": nil,
  601. },
  602. },
  603. },
  604. "isDeprecated": false,
  605. "deprecationReason": nil,
  606. },
  607. map[string]interface{}{
  608. "name": "possibleTypes",
  609. "description": nil,
  610. "args": []interface{}{},
  611. "type": map[string]interface{}{
  612. "kind": "LIST",
  613. "name": nil,
  614. "ofType": map[string]interface{}{
  615. "kind": "NON_NULL",
  616. "name": nil,
  617. "ofType": map[string]interface{}{
  618. "kind": "OBJECT",
  619. "name": "__Type",
  620. "ofType": nil,
  621. },
  622. },
  623. },
  624. "isDeprecated": false,
  625. "deprecationReason": nil,
  626. },
  627. map[string]interface{}{
  628. "name": "enumValues",
  629. "description": nil,
  630. "args": []interface{}{
  631. map[string]interface{}{
  632. "name": "includeDeprecated",
  633. "description": nil,
  634. "type": map[string]interface{}{
  635. "kind": "SCALAR",
  636. "name": "Boolean",
  637. "ofType": nil,
  638. },
  639. "defaultValue": "false",
  640. },
  641. },
  642. "type": map[string]interface{}{
  643. "kind": "LIST",
  644. "name": nil,
  645. "ofType": map[string]interface{}{
  646. "kind": "NON_NULL",
  647. "name": nil,
  648. "ofType": map[string]interface{}{
  649. "kind": "OBJECT",
  650. "name": "__EnumValue",
  651. "ofType": nil,
  652. },
  653. },
  654. },
  655. "isDeprecated": false,
  656. "deprecationReason": nil,
  657. },
  658. map[string]interface{}{
  659. "name": "inputFields",
  660. "description": nil,
  661. "args": []interface{}{},
  662. "type": map[string]interface{}{
  663. "kind": "LIST",
  664. "name": nil,
  665. "ofType": map[string]interface{}{
  666. "kind": "NON_NULL",
  667. "name": nil,
  668. "ofType": map[string]interface{}{
  669. "kind": "OBJECT",
  670. "name": "__InputValue",
  671. "ofType": nil,
  672. },
  673. },
  674. },
  675. "isDeprecated": false,
  676. "deprecationReason": nil,
  677. },
  678. map[string]interface{}{
  679. "name": "ofType",
  680. "description": nil,
  681. "args": []interface{}{},
  682. "type": map[string]interface{}{
  683. "kind": "OBJECT",
  684. "name": "__Type",
  685. "ofType": nil,
  686. },
  687. "isDeprecated": false,
  688. "deprecationReason": nil,
  689. },
  690. },
  691. "inputFields": nil,
  692. "interfaces": []interface{}{},
  693. "enumValues": nil,
  694. "possibleTypes": nil,
  695. })
  696. // Default types
  697. res = append(res, []interface{}{
  698. map[string]interface{}{
  699. "kind": "SCALAR",
  700. "name": "String",
  701. "description": "The `String` scalar type represents textual data, represented as UTF-8 character sequences.",
  702. "fields": nil,
  703. "inputFields": nil,
  704. "interfaces": nil,
  705. "enumValues": nil,
  706. "possibleTypes": nil,
  707. },
  708. map[string]interface{}{
  709. "kind": "SCALAR",
  710. "name": "Boolean",
  711. "description": "The `Boolean` scalar type represents `true` or `false`.",
  712. "fields": nil,
  713. "inputFields": nil,
  714. "interfaces": nil,
  715. "enumValues": nil,
  716. "possibleTypes": nil,
  717. },
  718. map[string]interface{}{
  719. "kind": "SCALAR",
  720. "name": "Float",
  721. "description": "The `Float` scalar type represents signed double-precision fractional values.",
  722. "fields": nil,
  723. "inputFields": nil,
  724. "interfaces": nil,
  725. "enumValues": nil,
  726. "possibleTypes": nil,
  727. },
  728. map[string]interface{}{
  729. "kind": "SCALAR",
  730. "name": "Int",
  731. "description": "The `Int` scalar type represents non-fractional signed whole numeric values.",
  732. "fields": nil,
  733. "inputFields": nil,
  734. "interfaces": nil,
  735. "enumValues": nil,
  736. "possibleTypes": nil,
  737. },
  738. map[string]interface{}{
  739. "kind": "OBJECT",
  740. "name": "__InputValue",
  741. "description": "Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.",
  742. "fields": []interface{}{
  743. map[string]interface{}{
  744. "name": "name",
  745. "description": nil,
  746. "args": []interface{}{},
  747. "type": map[string]interface{}{
  748. "kind": "NON_NULL",
  749. "name": nil,
  750. "ofType": map[string]interface{}{
  751. "kind": "SCALAR",
  752. "name": "String",
  753. "ofType": nil,
  754. },
  755. },
  756. "isDeprecated": false,
  757. "deprecationReason": nil,
  758. },
  759. map[string]interface{}{
  760. "name": "description",
  761. "description": nil,
  762. "args": []interface{}{},
  763. "type": map[string]interface{}{
  764. "kind": "SCALAR",
  765. "name": "String",
  766. "ofType": nil,
  767. },
  768. "isDeprecated": false,
  769. "deprecationReason": nil,
  770. },
  771. map[string]interface{}{
  772. "name": "type",
  773. "description": nil,
  774. "args": []interface{}{},
  775. "type": map[string]interface{}{
  776. "kind": "NON_NULL",
  777. "name": nil,
  778. "ofType": map[string]interface{}{
  779. "kind": "OBJECT",
  780. "name": "__Type",
  781. "ofType": nil,
  782. },
  783. },
  784. "isDeprecated": false,
  785. "deprecationReason": nil,
  786. },
  787. map[string]interface{}{
  788. "name": "defaultValue",
  789. "description": "A GraphQL-formatted string representing the default value for this input value.",
  790. "args": []interface{}{},
  791. "type": map[string]interface{}{
  792. "kind": "SCALAR",
  793. "name": "String",
  794. "ofType": nil,
  795. },
  796. "isDeprecated": false,
  797. "deprecationReason": nil,
  798. },
  799. },
  800. "inputFields": nil,
  801. "interfaces": []interface{}{},
  802. "enumValues": nil,
  803. "possibleTypes": nil,
  804. },
  805. map[string]interface{}{
  806. "kind": "OBJECT",
  807. "name": "__EnumValue",
  808. "description": "One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. Enum values are returned in a JSON response as strings.",
  809. "fields": []interface{}{
  810. map[string]interface{}{
  811. "name": "name",
  812. "description": nil,
  813. "args": []interface{}{},
  814. "type": map[string]interface{}{
  815. "kind": "NON_NULL",
  816. "name": nil,
  817. "ofType": map[string]interface{}{
  818. "kind": "SCALAR",
  819. "name": "String",
  820. "ofType": nil,
  821. },
  822. },
  823. "isDeprecated": false,
  824. "deprecationReason": nil,
  825. },
  826. map[string]interface{}{
  827. "name": "description",
  828. "description": nil,
  829. "args": []interface{}{},
  830. "type": map[string]interface{}{
  831. "kind": "SCALAR",
  832. "name": "String",
  833. "ofType": nil,
  834. },
  835. "isDeprecated": false,
  836. "deprecationReason": nil,
  837. },
  838. map[string]interface{}{
  839. "name": "isDeprecated",
  840. "description": nil,
  841. "args": []interface{}{},
  842. "type": map[string]interface{}{
  843. "kind": "NON_NULL",
  844. "name": nil,
  845. "ofType": map[string]interface{}{
  846. "kind": "SCALAR",
  847. "name": "Boolean",
  848. "ofType": nil,
  849. },
  850. },
  851. "isDeprecated": false,
  852. "deprecationReason": nil,
  853. },
  854. map[string]interface{}{
  855. "name": "deprecationReason",
  856. "description": nil,
  857. "args": []interface{}{},
  858. "type": map[string]interface{}{
  859. "kind": "SCALAR",
  860. "name": "String",
  861. "ofType": nil,
  862. },
  863. "isDeprecated": false,
  864. "deprecationReason": nil,
  865. },
  866. },
  867. "inputFields": nil,
  868. "interfaces": []interface{}{},
  869. "enumValues": nil,
  870. "possibleTypes": nil,
  871. },
  872. map[string]interface{}{
  873. "kind": "ENUM",
  874. "name": "__TypeKind",
  875. "description": "An enum describing what kind of type a given `__Type` is.",
  876. "fields": nil,
  877. "inputFields": nil,
  878. "interfaces": nil,
  879. "enumValues": []interface{}{
  880. map[string]interface{}{
  881. "name": "SCALAR",
  882. "description": "Indicates this type is a scalar.",
  883. "isDeprecated": false,
  884. "deprecationReason": nil,
  885. },
  886. map[string]interface{}{
  887. "name": "OBJECT",
  888. "description": "Indicates this type is an object. `fields` and `interfaces` are valid fields.",
  889. "isDeprecated": false,
  890. "deprecationReason": nil,
  891. },
  892. map[string]interface{}{
  893. "name": "INTERFACE",
  894. "description": "Indicates this type is an interface. `fields` and `possibleTypes` are valid fields.",
  895. "isDeprecated": false,
  896. "deprecationReason": nil,
  897. },
  898. map[string]interface{}{
  899. "name": "UNION",
  900. "description": "Indicates this type is a union. `possibleTypes` is a valid field.",
  901. "isDeprecated": false,
  902. "deprecationReason": nil,
  903. },
  904. map[string]interface{}{
  905. "name": "ENUM",
  906. "description": "Indicates this type is an enum. `enumValues` is a valid field.",
  907. "isDeprecated": false,
  908. "deprecationReason": nil,
  909. },
  910. map[string]interface{}{
  911. "name": "INPUT_OBJECT",
  912. "description": "Indicates this type is an input object. `inputFields` is a valid field.",
  913. "isDeprecated": false,
  914. "deprecationReason": nil,
  915. },
  916. map[string]interface{}{
  917. "name": "LIST",
  918. "description": "Indicates this type is a list. `ofType` is a valid field.",
  919. "isDeprecated": false,
  920. "deprecationReason": nil,
  921. },
  922. map[string]interface{}{
  923. "name": "NON_NULL",
  924. "description": "Indicates this type is a non-null. `ofType` is a valid field.",
  925. "isDeprecated": false,
  926. "deprecationReason": nil,
  927. },
  928. },
  929. "possibleTypes": nil,
  930. },
  931. map[string]interface{}{
  932. "kind": "OBJECT",
  933. "name": "__Field",
  934. "description": "Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.",
  935. "fields": []interface{}{
  936. map[string]interface{}{
  937. "name": "name",
  938. "description": nil,
  939. "args": []interface{}{},
  940. "type": map[string]interface{}{
  941. "kind": "NON_NULL",
  942. "name": nil,
  943. "ofType": map[string]interface{}{
  944. "kind": "SCALAR",
  945. "name": "String",
  946. "ofType": nil,
  947. },
  948. },
  949. "isDeprecated": false,
  950. "deprecationReason": nil,
  951. },
  952. map[string]interface{}{
  953. "name": "description",
  954. "description": nil,
  955. "args": []interface{}{},
  956. "type": map[string]interface{}{
  957. "kind": "SCALAR",
  958. "name": "String",
  959. "ofType": nil,
  960. },
  961. "isDeprecated": false,
  962. "deprecationReason": nil,
  963. },
  964. map[string]interface{}{
  965. "name": "args",
  966. "description": nil,
  967. "args": []interface{}{},
  968. "type": map[string]interface{}{
  969. "kind": "NON_NULL",
  970. "name": nil,
  971. "ofType": map[string]interface{}{
  972. "kind": "LIST",
  973. "name": nil,
  974. "ofType": map[string]interface{}{
  975. "kind": "NON_NULL",
  976. "name": nil,
  977. "ofType": map[string]interface{}{
  978. "kind": "OBJECT",
  979. "name": "__InputValue",
  980. "ofType": nil,
  981. },
  982. },
  983. },
  984. },
  985. "isDeprecated": false,
  986. "deprecationReason": nil,
  987. },
  988. map[string]interface{}{
  989. "name": "type",
  990. "description": nil,
  991. "args": []interface{}{},
  992. "type": map[string]interface{}{
  993. "kind": "NON_NULL",
  994. "name": nil,
  995. "ofType": map[string]interface{}{
  996. "kind": "OBJECT",
  997. "name": "__Type",
  998. "ofType": nil,
  999. },
  1000. },
  1001. "isDeprecated": false,
  1002. "deprecationReason": nil,
  1003. },
  1004. map[string]interface{}{
  1005. "name": "isDeprecated",
  1006. "description": nil,
  1007. "args": []interface{}{},
  1008. "type": map[string]interface{}{
  1009. "kind": "NON_NULL",
  1010. "name": nil,
  1011. "ofType": map[string]interface{}{
  1012. "kind": "SCALAR",
  1013. "name": "Boolean",
  1014. "ofType": nil,
  1015. },
  1016. },
  1017. "isDeprecated": false,
  1018. "deprecationReason": nil,
  1019. },
  1020. map[string]interface{}{
  1021. "name": "deprecationReason",
  1022. "description": nil,
  1023. "args": []interface{}{},
  1024. "type": map[string]interface{}{
  1025. "kind": "SCALAR",
  1026. "name": "String",
  1027. "ofType": nil,
  1028. },
  1029. "isDeprecated": false,
  1030. "deprecationReason": nil,
  1031. },
  1032. },
  1033. "inputFields": nil,
  1034. "interfaces": []interface{}{},
  1035. "enumValues": nil,
  1036. "possibleTypes": nil,
  1037. },
  1038. map[string]interface{}{
  1039. "kind": "OBJECT",
  1040. "name": "__Directive",
  1041. "description": "A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.",
  1042. "fields": []interface{}{
  1043. map[string]interface{}{
  1044. "name": "name",
  1045. "description": nil,
  1046. "args": []interface{}{},
  1047. "type": map[string]interface{}{
  1048. "kind": "NON_NULL",
  1049. "name": nil,
  1050. "ofType": map[string]interface{}{
  1051. "kind": "SCALAR",
  1052. "name": "String",
  1053. "ofType": nil,
  1054. },
  1055. },
  1056. "isDeprecated": false,
  1057. "deprecationReason": nil,
  1058. },
  1059. map[string]interface{}{
  1060. "name": "description",
  1061. "description": nil,
  1062. "args": []interface{}{},
  1063. "type": map[string]interface{}{
  1064. "kind": "SCALAR",
  1065. "name": "String",
  1066. "ofType": nil,
  1067. },
  1068. "isDeprecated": false,
  1069. "deprecationReason": nil,
  1070. },
  1071. map[string]interface{}{
  1072. "name": "locations",
  1073. "description": nil,
  1074. "args": []interface{}{},
  1075. "type": map[string]interface{}{
  1076. "kind": "NON_NULL",
  1077. "name": nil,
  1078. "ofType": map[string]interface{}{
  1079. "kind": "LIST",
  1080. "name": nil,
  1081. "ofType": map[string]interface{}{
  1082. "kind": "NON_NULL",
  1083. "name": nil,
  1084. "ofType": map[string]interface{}{
  1085. "kind": "ENUM",
  1086. "name": "__DirectiveLocation",
  1087. "ofType": nil,
  1088. },
  1089. },
  1090. },
  1091. },
  1092. "isDeprecated": false,
  1093. "deprecationReason": nil,
  1094. },
  1095. map[string]interface{}{
  1096. "name": "args",
  1097. "description": nil,
  1098. "args": []interface{}{},
  1099. "type": map[string]interface{}{
  1100. "kind": "NON_NULL",
  1101. "name": nil,
  1102. "ofType": map[string]interface{}{
  1103. "kind": "LIST",
  1104. "name": nil,
  1105. "ofType": map[string]interface{}{
  1106. "kind": "NON_NULL",
  1107. "name": nil,
  1108. "ofType": map[string]interface{}{
  1109. "kind": "OBJECT",
  1110. "name": "__InputValue",
  1111. "ofType": nil,
  1112. },
  1113. },
  1114. },
  1115. },
  1116. "isDeprecated": false,
  1117. "deprecationReason": nil,
  1118. },
  1119. },
  1120. "inputFields": nil,
  1121. "interfaces": []interface{}{},
  1122. "enumValues": nil,
  1123. "possibleTypes": nil,
  1124. },
  1125. map[string]interface{}{
  1126. "kind": "ENUM",
  1127. "name": "__DirectiveLocation",
  1128. "description": "A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.",
  1129. "fields": nil,
  1130. "inputFields": nil,
  1131. "interfaces": nil,
  1132. "enumValues": []interface{}{
  1133. map[string]interface{}{
  1134. "name": "QUERY",
  1135. "description": "Location adjacent to a query operation.",
  1136. "isDeprecated": false,
  1137. "deprecationReason": nil,
  1138. },
  1139. map[string]interface{}{
  1140. "name": "MUTATION",
  1141. "description": "Location adjacent to a mutation operation.",
  1142. "isDeprecated": false,
  1143. "deprecationReason": nil,
  1144. },
  1145. map[string]interface{}{
  1146. "name": "SUBSCRIPTION",
  1147. "description": "Location adjacent to a subscription operation.",
  1148. "isDeprecated": false,
  1149. "deprecationReason": nil,
  1150. },
  1151. map[string]interface{}{
  1152. "name": "FIELD",
  1153. "description": "Location adjacent to a field.",
  1154. "isDeprecated": false,
  1155. "deprecationReason": nil,
  1156. },
  1157. map[string]interface{}{
  1158. "name": "FRAGMENT_DEFINITION",
  1159. "description": "Location adjacent to a fragment definition.",
  1160. "isDeprecated": false,
  1161. "deprecationReason": nil,
  1162. },
  1163. map[string]interface{}{
  1164. "name": "FRAGMENT_SPREAD",
  1165. "description": "Location adjacent to a fragment spread.",
  1166. "isDeprecated": false,
  1167. "deprecationReason": nil,
  1168. },
  1169. map[string]interface{}{
  1170. "name": "INLINE_FRAGMENT",
  1171. "description": "Location adjacent to an inline fragment.",
  1172. "isDeprecated": false,
  1173. "deprecationReason": nil,
  1174. },
  1175. map[string]interface{}{
  1176. "name": "SCHEMA",
  1177. "description": "Location adjacent to a schema definition.",
  1178. "isDeprecated": false,
  1179. "deprecationReason": nil,
  1180. },
  1181. map[string]interface{}{
  1182. "name": "SCALAR",
  1183. "description": "Location adjacent to a scalar definition.",
  1184. "isDeprecated": false,
  1185. "deprecationReason": nil,
  1186. },
  1187. map[string]interface{}{
  1188. "name": "OBJECT",
  1189. "description": "Location adjacent to an object type definition.",
  1190. "isDeprecated": false,
  1191. "deprecationReason": nil,
  1192. },
  1193. map[string]interface{}{
  1194. "name": "FIELD_DEFINITION",
  1195. "description": "Location adjacent to a field definition.",
  1196. "isDeprecated": false,
  1197. "deprecationReason": nil,
  1198. },
  1199. map[string]interface{}{
  1200. "name": "ARGUMENT_DEFINITION",
  1201. "description": "Location adjacent to an argument definition.",
  1202. "isDeprecated": false,
  1203. "deprecationReason": nil,
  1204. },
  1205. map[string]interface{}{
  1206. "name": "INTERFACE",
  1207. "description": "Location adjacent to an interface definition.",
  1208. "isDeprecated": false,
  1209. "deprecationReason": nil,
  1210. },
  1211. map[string]interface{}{
  1212. "name": "UNION",
  1213. "description": "Location adjacent to a union definition.",
  1214. "isDeprecated": false,
  1215. "deprecationReason": nil,
  1216. },
  1217. map[string]interface{}{
  1218. "name": "ENUM",
  1219. "description": "Location adjacent to an enum definition.",
  1220. "isDeprecated": false,
  1221. "deprecationReason": nil,
  1222. },
  1223. map[string]interface{}{
  1224. "name": "ENUM_VALUE",
  1225. "description": "Location adjacent to an enum value definition.",
  1226. "isDeprecated": false,
  1227. "deprecationReason": nil,
  1228. },
  1229. map[string]interface{}{
  1230. "name": "INPUT_OBJECT",
  1231. "description": "Location adjacent to an input object type definition.",
  1232. "isDeprecated": false,
  1233. "deprecationReason": nil,
  1234. },
  1235. map[string]interface{}{
  1236. "name": "INPUT_FIELD_DEFINITION",
  1237. "description": "Location adjacent to an input object field definition.",
  1238. "isDeprecated": false,
  1239. "deprecationReason": nil,
  1240. },
  1241. },
  1242. "possibleTypes": nil,
  1243. },
  1244. }...)
  1245. return res
  1246. }
  1247. /*
  1248. GetDirectivesIntrospection returns the introspection for all available directives.
  1249. */
  1250. func (rt *selectionSetRuntime) GetDirectivesIntrospection() interface{} {
  1251. return []interface{}{
  1252. map[string]interface{}{
  1253. "name": "skip",
  1254. "description": "Directs the executor to skip this field or fragment when the `if` argument is true.",
  1255. "locations": []interface{}{
  1256. "FIELD",
  1257. "FRAGMENT_SPREAD",
  1258. "INLINE_FRAGMENT",
  1259. },
  1260. "args": []interface{}{
  1261. map[string]interface{}{
  1262. "name": "if",
  1263. "description": "Skipped when true.",
  1264. "type": map[string]interface{}{
  1265. "kind": "NON_NULL",
  1266. "name": nil,
  1267. "ofType": map[string]interface{}{
  1268. "kind": "SCALAR",
  1269. "name": "Boolean",
  1270. "ofType": nil,
  1271. },
  1272. },
  1273. "defaultValue": nil,
  1274. },
  1275. },
  1276. },
  1277. map[string]interface{}{
  1278. "name": "include",
  1279. "description": "Directs the executor to include this field or fragment only when the `if` argument is true.",
  1280. "locations": []interface{}{
  1281. "FIELD",
  1282. "FRAGMENT_SPREAD",
  1283. "INLINE_FRAGMENT",
  1284. },
  1285. "args": []interface{}{
  1286. map[string]interface{}{
  1287. "name": "if",
  1288. "description": "Included when true.",
  1289. "type": map[string]interface{}{
  1290. "kind": "NON_NULL",
  1291. "name": nil,
  1292. "ofType": map[string]interface{}{
  1293. "kind": "SCALAR",
  1294. "name": "Boolean",
  1295. "ofType": nil,
  1296. },
  1297. },
  1298. "defaultValue": nil,
  1299. },
  1300. },
  1301. },
  1302. }
  1303. }
  1304. /*
  1305. GetFields returns all fields of this selection set.
  1306. */
  1307. func (rt *selectionSetRuntime) GetFields() map[string]*fieldRuntime {
  1308. resMap := make(map[string]*fieldRuntime)
  1309. fieldList := append(rt.node.Children[:0:0], rt.node.Children...) // Copy into new slice
  1310. for i := 0; i < len(fieldList); i++ {
  1311. c := fieldList[i]
  1312. // Check for skip and include directive
  1313. if rt.skipField([]string{}, c) {
  1314. continue
  1315. }
  1316. if c.Name == parser.NodeField {
  1317. // Handle simple fields - we ignore aliases as they will not be honored
  1318. // when filtering the introspection data
  1319. field := c.Runtime.(*fieldRuntime)
  1320. resMap[field.Name()] = field
  1321. } else if c.Name == parser.NodeFragmentSpread || c.Name == parser.NodeInlineFragment {
  1322. var fd fragmentRuntime
  1323. if c.Name == parser.NodeFragmentSpread {
  1324. // Lookup fragment spreads
  1325. fd = rt.rtp.fragments[c.Token.Val]
  1326. } else {
  1327. // Construct inline fragments
  1328. fd = c.Runtime.(*inlineFragmentDefinitionRuntime)
  1329. }
  1330. ss := fd.SelectionSet()
  1331. fieldList = append(fieldList, ss.Children...)
  1332. }
  1333. }
  1334. return resMap
  1335. }