selectionset_test.go 20 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  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. "encoding/json"
  13. "testing"
  14. )
  15. func TestSortingAndLimiting(t *testing.T) {
  16. gm, _ := songGraphGroups()
  17. query := map[string]interface{}{
  18. "operationName": nil,
  19. "query": `
  20. {
  21. Song(ascending:"key") {
  22. key
  23. name
  24. }
  25. }
  26. `,
  27. "variables": nil,
  28. }
  29. if rerr := checkResult(`
  30. {
  31. "data": {
  32. "Song": [
  33. {
  34. "key": "Aria1",
  35. "name": "Aria1"
  36. },
  37. {
  38. "key": "Aria2",
  39. "name": "Aria2"
  40. },
  41. {
  42. "key": "Aria3",
  43. "name": "Aria3"
  44. },
  45. {
  46. "key": "Aria4",
  47. "name": "Aria4"
  48. },
  49. {
  50. "key": "DeadSong2",
  51. "name": "DeadSong2"
  52. },
  53. {
  54. "key": "FightSong4",
  55. "name": "FightSong4"
  56. },
  57. {
  58. "key": "LoveSong3",
  59. "name": "LoveSong3"
  60. },
  61. {
  62. "key": "MyOnlySong3",
  63. "name": "MyOnlySong3"
  64. },
  65. {
  66. "key": "StrangeSong1",
  67. "name": "StrangeSong1"
  68. }
  69. ]
  70. }
  71. }`[1:], query, gm); rerr != nil {
  72. t.Error(rerr)
  73. return
  74. }
  75. query = map[string]interface{}{
  76. "operationName": nil,
  77. "query": `
  78. {
  79. Song(ascending:"name", last: 3) {
  80. key
  81. name
  82. }
  83. }
  84. `,
  85. "variables": nil,
  86. }
  87. if rerr := checkResult(`
  88. {
  89. "data": {
  90. "Song": [
  91. {
  92. "key": "LoveSong3",
  93. "name": "LoveSong3"
  94. },
  95. {
  96. "key": "MyOnlySong3",
  97. "name": "MyOnlySong3"
  98. },
  99. {
  100. "key": "StrangeSong1",
  101. "name": "StrangeSong1"
  102. }
  103. ]
  104. }
  105. }`[1:], query, gm); rerr != nil {
  106. t.Error(rerr)
  107. return
  108. }
  109. query = map[string]interface{}{
  110. "operationName": nil,
  111. "query": `
  112. {
  113. Song(descending:"name", last: 3) {
  114. key
  115. name
  116. }
  117. }
  118. `,
  119. "variables": nil,
  120. }
  121. if rerr := checkResult(`
  122. {
  123. "data": {
  124. "Song": [
  125. {
  126. "key": "Aria3",
  127. "name": "Aria3"
  128. },
  129. {
  130. "key": "Aria2",
  131. "name": "Aria2"
  132. },
  133. {
  134. "key": "Aria1",
  135. "name": "Aria1"
  136. }
  137. ]
  138. }
  139. }`[1:], query, gm); rerr != nil {
  140. t.Error(rerr)
  141. return
  142. }
  143. query = map[string]interface{}{
  144. "operationName": nil,
  145. "query": `
  146. {
  147. Song(ascending:"name", items: 2, last: 3) {
  148. key
  149. name
  150. }
  151. }
  152. `,
  153. "variables": nil,
  154. }
  155. if rerr := checkResult(`
  156. {
  157. "data": {
  158. "Song": [
  159. {
  160. "key": "LoveSong3",
  161. "name": "LoveSong3"
  162. },
  163. {
  164. "key": "MyOnlySong3",
  165. "name": "MyOnlySong3"
  166. }
  167. ]
  168. }
  169. }`[1:], query, gm); rerr != nil {
  170. t.Error(rerr)
  171. return
  172. }
  173. // From the last 3 we retrieve item 1 and the next
  174. query = map[string]interface{}{
  175. "operationName": nil,
  176. "query": `
  177. {
  178. Song(ascending:"name", from : 1, items: 2, last: 3) {
  179. key
  180. name
  181. }
  182. }
  183. `,
  184. "variables": nil,
  185. }
  186. if rerr := checkResult(`
  187. {
  188. "data": {
  189. "Song": [
  190. {
  191. "key": "MyOnlySong3",
  192. "name": "MyOnlySong3"
  193. },
  194. {
  195. "key": "StrangeSong1",
  196. "name": "StrangeSong1"
  197. }
  198. ]
  199. }
  200. }`[1:], query, gm); rerr != nil {
  201. t.Error(rerr)
  202. return
  203. }
  204. query = map[string]interface{}{
  205. "operationName": nil,
  206. "query": `
  207. {
  208. Song(ascending:"name", from : 100, items: 200, last: 2) {
  209. key
  210. name
  211. }
  212. }
  213. `,
  214. "variables": nil,
  215. }
  216. if rerr := checkResult(`
  217. {
  218. "data": {
  219. "Song": [
  220. {
  221. "key": "MyOnlySong3",
  222. "name": "MyOnlySong3"
  223. },
  224. {
  225. "key": "StrangeSong1",
  226. "name": "StrangeSong1"
  227. }
  228. ]
  229. }
  230. }`[1:], query, gm); rerr != nil {
  231. t.Error(rerr)
  232. return
  233. }
  234. query = map[string]interface{}{
  235. "operationName": nil,
  236. "query": `
  237. {
  238. Song(ascending:"name", descending:"key") {
  239. key
  240. name
  241. }
  242. }
  243. `,
  244. "variables": nil,
  245. }
  246. if rerr := checkResult(`
  247. {
  248. "data": {
  249. "Song": []
  250. },
  251. "errors": [
  252. {
  253. "locations": [
  254. {
  255. "column": 45,
  256. "line": 3
  257. }
  258. ],
  259. "message": "Cannot specify ascending and descending sorting",
  260. "path": [
  261. "Song"
  262. ]
  263. }
  264. ]
  265. }`[1:], query, gm); rerr != nil {
  266. t.Error(rerr)
  267. return
  268. }
  269. query = map[string]interface{}{
  270. "operationName": nil,
  271. "query": `
  272. {
  273. Song(ascending:"hans") {
  274. key
  275. name
  276. }
  277. }
  278. `,
  279. "variables": nil,
  280. }
  281. if rerr := checkResult(`
  282. {
  283. "data": {
  284. "Song": [
  285. {
  286. "key": "StrangeSong1",
  287. "name": "StrangeSong1"
  288. },
  289. {
  290. "key": "FightSong4",
  291. "name": "FightSong4"
  292. },
  293. {
  294. "key": "DeadSong2",
  295. "name": "DeadSong2"
  296. },
  297. {
  298. "key": "LoveSong3",
  299. "name": "LoveSong3"
  300. },
  301. {
  302. "key": "MyOnlySong3",
  303. "name": "MyOnlySong3"
  304. },
  305. {
  306. "key": "Aria1",
  307. "name": "Aria1"
  308. },
  309. {
  310. "key": "Aria2",
  311. "name": "Aria2"
  312. },
  313. {
  314. "key": "Aria3",
  315. "name": "Aria3"
  316. },
  317. {
  318. "key": "Aria4",
  319. "name": "Aria4"
  320. }
  321. ]
  322. }
  323. }`[1:], query, gm); rerr != nil {
  324. t.Error(rerr)
  325. return
  326. }
  327. }
  328. func TestFragments(t *testing.T) {
  329. gm, _ := songGraphGroups()
  330. // Test fragments for different return types
  331. query := map[string]interface{}{
  332. "operationName": nil,
  333. "query": `
  334. {
  335. Song(key : "StrangeSong1") {
  336. song_key : key
  337. foo : bar(traverse : ":::") {
  338. key
  339. kind
  340. ...groupFields
  341. ...authorFields @skip(if: false)
  342. }
  343. }
  344. }
  345. fragment groupFields on group {
  346. owner
  347. }
  348. fragment authorFields on Author {
  349. name
  350. }
  351. `,
  352. "variables": nil,
  353. }
  354. if rerr := checkResult(`
  355. {
  356. "data": {
  357. "Song": [
  358. {
  359. "foo": [
  360. {
  361. "key": "123",
  362. "kind": "Author",
  363. "name": "Mike"
  364. },
  365. {
  366. "key": "Best",
  367. "kind": "group",
  368. "owner": "noowner"
  369. }
  370. ],
  371. "song_key": "StrangeSong1"
  372. }
  373. ]
  374. }
  375. }`[1:], query, gm); rerr != nil {
  376. t.Error(rerr)
  377. return
  378. }
  379. // Test fragments for different return types - now using inline fragments
  380. query = map[string]interface{}{
  381. "operationName": nil,
  382. "query": `
  383. {
  384. Song(key : "StrangeSong1") {
  385. song_key : key
  386. foo : bar(traverse : ":::") {
  387. key
  388. kind
  389. ... on group @skip(if: false) {
  390. owner
  391. }
  392. ... on Author {
  393. name
  394. }
  395. }
  396. }
  397. }
  398. `,
  399. "variables": nil,
  400. }
  401. if rerr := checkResult(`
  402. {
  403. "data": {
  404. "Song": [
  405. {
  406. "foo": [
  407. {
  408. "key": "123",
  409. "kind": "Author",
  410. "name": "Mike"
  411. },
  412. {
  413. "key": "Best",
  414. "kind": "group",
  415. "owner": "noowner"
  416. }
  417. ],
  418. "song_key": "StrangeSong1"
  419. }
  420. ]
  421. }
  422. }`[1:], query, gm); rerr != nil {
  423. t.Error(rerr)
  424. return
  425. }
  426. query = map[string]interface{}{
  427. "operationName": nil,
  428. "query": `
  429. {
  430. key
  431. name1 : name
  432. ...SongKind
  433. ...foo
  434. }
  435. fragment SongKind on Song {
  436. kind
  437. name2 : name
  438. key
  439. }
  440. `,
  441. "variables": nil,
  442. }
  443. if rerr := checkResult("", query, gm); rerr == nil ||
  444. rerr.Error() != "Fatal GraphQL query error in test: Invalid construct (Fragment foo is not defined) (Line:2 Pos:2)" {
  445. t.Error(rerr)
  446. return
  447. }
  448. query = map[string]interface{}{
  449. "operationName": nil,
  450. "query": `
  451. {
  452. key
  453. name1 : name
  454. ...SongKind
  455. ...foo
  456. }
  457. fragment SongKind on Song {
  458. kind
  459. name2 : name
  460. key
  461. }
  462. fragment SongKind on Song {
  463. kind
  464. name2 : name
  465. key
  466. }
  467. `,
  468. "variables": nil,
  469. }
  470. if rerr := checkResult("", query, gm); rerr == nil ||
  471. rerr.Error() != "Fatal GraphQL query error in test: Ambiguous definition (Fragment SongKind defined multiple times) (Line:2 Pos:2)" {
  472. t.Error(rerr)
  473. return
  474. }
  475. }
  476. func TestMutation(t *testing.T) {
  477. gm, _ := songGraphGroups()
  478. query := map[string]interface{}{
  479. "operationName": nil,
  480. "query": `
  481. {
  482. Song(storeNode : {
  483. key:"newsongkey",
  484. name:"newsongname"
  485. }, key : "newsongkey") {
  486. key,
  487. name
  488. }
  489. }
  490. `,
  491. "variables": nil,
  492. }
  493. if rerr := checkResult(`
  494. {
  495. "data": {
  496. "Song": []
  497. },
  498. "errors": [
  499. {
  500. "locations": [
  501. {
  502. "column": 25,
  503. "line": 6
  504. }
  505. ],
  506. "message": "Operation must be a mutation to modify data",
  507. "path": [
  508. "Song"
  509. ]
  510. }
  511. ]
  512. }`[1:], query, gm); rerr != nil {
  513. t.Error(rerr)
  514. return
  515. }
  516. query = map[string]interface{}{
  517. "operationName": nil,
  518. "query": `
  519. mutation {
  520. Song(storeNode : {
  521. key : "newsongkey",
  522. name : "newsongname"
  523. }, storeEdge : {
  524. key : "newedgekey",
  525. kind : "newedgekind"
  526. end1key : "newsongkey",
  527. end1kind : "Song",
  528. end1role : "song",
  529. end1cascading : false,
  530. end2key : "Best",
  531. end2kind : "group",
  532. end2role : "group",
  533. end2cascading : false,
  534. },key : "newsongkey") {
  535. key,
  536. name,
  537. group(traverse : ":::group") {
  538. key
  539. otherMembers(traverse : ":::Song", matches : {
  540. not_key : "newsongkey",
  541. name : "^.*Song[0-9]$"
  542. }) {
  543. key,
  544. kind,
  545. name,
  546. }
  547. }
  548. }
  549. }
  550. `,
  551. "variables": nil,
  552. }
  553. result, _ := runQuery("test", "main", query, gm, nil, true)
  554. actualResultBytes, _ := json.MarshalIndent(result, "", " ")
  555. actualResult := string(actualResultBytes)
  556. if actualResult != `{
  557. "data": {
  558. "Song": []
  559. },
  560. "errors": [
  561. {
  562. "locations": [
  563. {
  564. "column": 26,
  565. "line": 17
  566. }
  567. ],
  568. "message": "Can only perform read operations",
  569. "path": [
  570. "Song"
  571. ]
  572. }
  573. ]
  574. }` {
  575. t.Error("Unexpected result:", actualResult)
  576. return
  577. }
  578. if rerr := checkResult(`
  579. {
  580. "data": {
  581. "Song": [
  582. {
  583. "group": [
  584. {
  585. "key": "Best",
  586. "otherMembers": [
  587. {
  588. "key": "LoveSong3",
  589. "kind": "Song",
  590. "name": "LoveSong3"
  591. },
  592. {
  593. "key": "MyOnlySong3",
  594. "kind": "Song",
  595. "name": "MyOnlySong3"
  596. },
  597. {
  598. "key": "StrangeSong1",
  599. "kind": "Song",
  600. "name": "StrangeSong1"
  601. }
  602. ]
  603. }
  604. ],
  605. "key": "newsongkey",
  606. "name": "newsongname"
  607. }
  608. ]
  609. }
  610. }`[1:], query, gm); rerr != nil {
  611. t.Error(rerr)
  612. return
  613. }
  614. query = map[string]interface{}{
  615. "operationName": nil,
  616. "query": `
  617. mutation {
  618. Song(removeNode : {
  619. key : "newsongkey",
  620. }, removeEdge : {
  621. key : "newedgekey",
  622. kind : "newedgekind"
  623. },key : "newsongkey") {
  624. key,
  625. name,
  626. group(traverse : ":::group") {
  627. key
  628. otherMembers(traverse : ":::Song", matches : {
  629. not_key : "newsongkey",
  630. name : "^.*Song[0-9]$"
  631. }) {
  632. key,
  633. kind,
  634. name,
  635. }
  636. }
  637. }
  638. }
  639. `,
  640. "variables": nil,
  641. }
  642. if rerr := checkResult(`
  643. {
  644. "data": {
  645. "Song": []
  646. }
  647. }`[1:], query, gm); rerr != nil {
  648. t.Error(rerr)
  649. return
  650. }
  651. query = map[string]interface{}{
  652. "operationName": nil,
  653. "query": `
  654. mutation {
  655. Song(removeNode : {}) {
  656. key
  657. kind
  658. }
  659. }
  660. `,
  661. "variables": nil,
  662. }
  663. if rerr := checkResult(`
  664. {
  665. "data": {
  666. "Song": []
  667. }
  668. }`[1:], query, gm); rerr != nil {
  669. t.Error(rerr)
  670. return
  671. }
  672. query = map[string]interface{}{
  673. "operationName": nil,
  674. "query": `
  675. mutation {
  676. Song(storeNode : "Hans", storeEdge : "Franz", key : "Honk") {
  677. key,
  678. name,
  679. }
  680. }`,
  681. "variables": nil,
  682. }
  683. if rerr := checkResult(`{
  684. "data": {
  685. "Song": []
  686. },
  687. "errors": [
  688. {
  689. "locations": [
  690. {
  691. "column": 64,
  692. "line": 3
  693. }
  694. ],
  695. "message": "Object required for node attributes and values",
  696. "path": [
  697. "Song"
  698. ]
  699. },
  700. {
  701. "locations": [
  702. {
  703. "column": 64,
  704. "line": 3
  705. }
  706. ],
  707. "message": "Object required for edge attributes and values",
  708. "path": [
  709. "Song"
  710. ]
  711. }
  712. ]
  713. }`, query, gm); rerr != nil {
  714. t.Error(rerr)
  715. return
  716. }
  717. query = map[string]interface{}{
  718. "operationName": nil,
  719. "query": `
  720. mutation {
  721. Song(removeNode : "Hans", removeEdge : "Franz", key : "Honk") {
  722. key,
  723. name,
  724. }
  725. }`,
  726. "variables": nil,
  727. }
  728. if rerr := checkResult(`{
  729. "data": {
  730. "Song": []
  731. },
  732. "errors": [
  733. {
  734. "locations": [
  735. {
  736. "column": 66,
  737. "line": 3
  738. }
  739. ],
  740. "message": "Object required for node key and kind",
  741. "path": [
  742. "Song"
  743. ]
  744. },
  745. {
  746. "locations": [
  747. {
  748. "column": 66,
  749. "line": 3
  750. }
  751. ],
  752. "message": "Object required for edge key and kind",
  753. "path": [
  754. "Song"
  755. ]
  756. }
  757. ]
  758. }`, query, gm); rerr != nil {
  759. t.Error(rerr)
  760. return
  761. }
  762. }
  763. func TestTraversals(t *testing.T) {
  764. gm, _ := songGraphGroups()
  765. query := map[string]interface{}{
  766. "operationName": nil,
  767. "query": `
  768. {
  769. Song(key : "StrangeSong1") {
  770. song_key : key
  771. foo : bar(traverse : ":::") {
  772. key
  773. kind
  774. Name : name
  775. }
  776. }
  777. }
  778. `,
  779. "variables": nil,
  780. }
  781. if rerr := checkResult(`
  782. {
  783. "data": {
  784. "Song": [
  785. {
  786. "foo": [
  787. {
  788. "Name": "Mike",
  789. "key": "123",
  790. "kind": "Author"
  791. },
  792. {
  793. "Name": null,
  794. "key": "Best",
  795. "kind": "group"
  796. }
  797. ],
  798. "song_key": "StrangeSong1"
  799. }
  800. ]
  801. }
  802. }`[1:], query, gm); rerr != nil {
  803. t.Error(rerr)
  804. return
  805. }
  806. query = map[string]interface{}{
  807. "operationName": nil,
  808. "query": `
  809. {
  810. Song(key : "StrangeSong1") {
  811. song_key : key
  812. foo : bar(traverse : ":::Author") {
  813. kind() {}
  814. }
  815. }
  816. }
  817. `,
  818. "variables": nil,
  819. }
  820. if rerr := checkResult(`
  821. {
  822. "data": {
  823. "Song": [
  824. {
  825. "foo": [
  826. {
  827. "kind": "Author"
  828. }
  829. ],
  830. "song_key": "StrangeSong1"
  831. }
  832. ]
  833. },
  834. "errors": [
  835. {
  836. "locations": [
  837. {
  838. "column": 9,
  839. "line": 6
  840. }
  841. ],
  842. "message": "Traversal argument is missing",
  843. "path": [
  844. "Song",
  845. ":::Author"
  846. ]
  847. }
  848. ]
  849. }`[1:], query, gm); rerr != nil {
  850. t.Error(rerr)
  851. return
  852. }
  853. }
  854. func TestListQueries(t *testing.T) {
  855. gm, _ := songGraphGroups()
  856. query := map[string]interface{}{
  857. "operationName": "foo",
  858. "query": `
  859. {
  860. Song {
  861. key
  862. }
  863. }
  864. `,
  865. "variables": nil,
  866. }
  867. _, err := runQuery("test", "main", query, gm, nil, false)
  868. if err == nil || err.Error() != "Fatal GraphQL operation error in test: Missing operation (Operation foo not found) (Line:2 Pos:2)" {
  869. t.Error("Unexpected result:", err)
  870. return
  871. }
  872. query = map[string]interface{}{
  873. "operationName": nil,
  874. "query": `
  875. fragment friendFields on User {
  876. id
  877. name
  878. profilePic(size: 50)
  879. }
  880. `,
  881. "variables": nil,
  882. }
  883. res, err := runQuery("test", "main", query, gm, nil, false)
  884. if err == nil || err.Error() != "Fatal GraphQL operation error in test: Missing operation (No executable expression found) (Line:2 Pos:2)" {
  885. t.Error("Unexpected result:", res, err)
  886. return
  887. }
  888. query = map[string]interface{}{
  889. "operationName": nil,
  890. "query": `
  891. {
  892. Song1 : Song {
  893. song_key : key
  894. song_key1 : key
  895. song_key1 : name # This is illegal and will be ignored
  896. song_key1 : key
  897. name
  898. name
  899. }
  900. group {
  901. key
  902. },
  903. }
  904. `,
  905. "variables": nil,
  906. }
  907. if rerr := checkResult(`
  908. {
  909. "data": {
  910. "Song1": [
  911. {
  912. "name": "StrangeSong1",
  913. "song_key": "StrangeSong1",
  914. "song_key1": "StrangeSong1"
  915. },
  916. {
  917. "name": "FightSong4",
  918. "song_key": "FightSong4",
  919. "song_key1": "FightSong4"
  920. },
  921. {
  922. "name": "DeadSong2",
  923. "song_key": "DeadSong2",
  924. "song_key1": "DeadSong2"
  925. },
  926. {
  927. "name": "LoveSong3",
  928. "song_key": "LoveSong3",
  929. "song_key1": "LoveSong3"
  930. },
  931. {
  932. "name": "MyOnlySong3",
  933. "song_key": "MyOnlySong3",
  934. "song_key1": "MyOnlySong3"
  935. },
  936. {
  937. "name": "Aria1",
  938. "song_key": "Aria1",
  939. "song_key1": "Aria1"
  940. },
  941. {
  942. "name": "Aria2",
  943. "song_key": "Aria2",
  944. "song_key1": "Aria2"
  945. },
  946. {
  947. "name": "Aria3",
  948. "song_key": "Aria3",
  949. "song_key1": "Aria3"
  950. },
  951. {
  952. "name": "Aria4",
  953. "song_key": "Aria4",
  954. "song_key1": "Aria4"
  955. }
  956. ],
  957. "group": [
  958. {
  959. "key": "Best"
  960. }
  961. ]
  962. },
  963. "errors": [
  964. {
  965. "locations": [
  966. {
  967. "column": 17,
  968. "line": 3
  969. }
  970. ],
  971. "message": "Field identifier song_key1 used multiple times",
  972. "path": [
  973. "Song1"
  974. ]
  975. },
  976. {
  977. "locations": [
  978. {
  979. "column": 17,
  980. "line": 3
  981. }
  982. ],
  983. "message": "Field identifier name used multiple times",
  984. "path": [
  985. "Song1"
  986. ]
  987. }
  988. ]
  989. }`[1:], query, gm); rerr != nil {
  990. t.Error(rerr)
  991. return
  992. }
  993. query = map[string]interface{}{
  994. "operationName": nil,
  995. "query": `
  996. {
  997. Song(key : "StrangeSong1") {
  998. song_key : key
  999. name
  1000. }
  1001. }
  1002. `,
  1003. "variables": nil,
  1004. }
  1005. if rerr := checkResult(`
  1006. {
  1007. "data": {
  1008. "Song": [
  1009. {
  1010. "name": "StrangeSong1",
  1011. "song_key": "StrangeSong1"
  1012. }
  1013. ]
  1014. }
  1015. }`[1:], query, gm); rerr != nil {
  1016. t.Error(rerr)
  1017. return
  1018. }
  1019. query = map[string]interface{}{
  1020. "operationName": nil,
  1021. "query": `
  1022. {
  1023. Song(matches : { name : "Aria[2-4]", not_name : "Aria4", foo : "a[" }) {
  1024. song_key : key
  1025. }
  1026. }
  1027. `,
  1028. "variables": nil,
  1029. }
  1030. if rerr := checkResult(`
  1031. {
  1032. "data": {
  1033. "Song": [
  1034. {
  1035. "song_key": "Aria2"
  1036. },
  1037. {
  1038. "song_key": "Aria3"
  1039. }
  1040. ]
  1041. },
  1042. "errors": [
  1043. {
  1044. "locations": [
  1045. {
  1046. "column": 79,
  1047. "line": 3
  1048. }
  1049. ],
  1050. "message": "Regex a[ did not compile: error parsing regexp: missing closing ]: `[1:]+"`[`"+`",
  1051. "path": [
  1052. "Song"
  1053. ]
  1054. }
  1055. ]
  1056. }`, query, gm); rerr != nil {
  1057. t.Error(rerr)
  1058. return
  1059. }
  1060. query = map[string]interface{}{
  1061. "operationName": nil,
  1062. "query": `
  1063. {
  1064. Song(matches : { name1 : "test" }) {
  1065. song_key : key
  1066. }
  1067. }
  1068. `,
  1069. "variables": nil,
  1070. }
  1071. if rerr := checkResult(`{
  1072. "data": {
  1073. "Song": []
  1074. }
  1075. }`, query, gm); rerr != nil {
  1076. t.Error(rerr)
  1077. return
  1078. }
  1079. query = map[string]interface{}{
  1080. "operationName": nil,
  1081. "query": `
  1082. {
  1083. Song(matches : [ "name1", "test" ]) {
  1084. }
  1085. }
  1086. `,
  1087. "variables": nil,
  1088. }
  1089. if rerr := checkResult(`{
  1090. "data": {
  1091. "Song": [
  1092. {},
  1093. {},
  1094. {},
  1095. {},
  1096. {},
  1097. {},
  1098. {},
  1099. {},
  1100. {}
  1101. ]
  1102. },
  1103. "errors": [
  1104. {
  1105. "locations": [
  1106. {
  1107. "column": 45,
  1108. "line": 3
  1109. }
  1110. ],
  1111. "message": "Matches expression is not a map",
  1112. "path": [
  1113. "Song"
  1114. ]
  1115. }
  1116. ]
  1117. }`, query, gm); rerr != nil {
  1118. t.Error(rerr)
  1119. return
  1120. }
  1121. query = map[string]interface{}{
  1122. "operationName": nil,
  1123. "query": `
  1124. fragment Song on Song {
  1125. key
  1126. name1 : name
  1127. ...SongKind
  1128. }
  1129. query b { # This should be executed
  1130. Song {
  1131. key
  1132. ...Song
  1133. }
  1134. }
  1135. query a {
  1136. Song1 {
  1137. key1
  1138. }
  1139. }
  1140. fragment SongKind on Song {
  1141. kind
  1142. name2 : name
  1143. key
  1144. }
  1145. `,
  1146. "variables": nil,
  1147. }
  1148. if rerr := checkResult(`
  1149. {
  1150. "data": {
  1151. "Song": [
  1152. {
  1153. "key": "StrangeSong1",
  1154. "kind": "Song",
  1155. "name1": "StrangeSong1",
  1156. "name2": "StrangeSong1"
  1157. },
  1158. {
  1159. "key": "FightSong4",
  1160. "kind": "Song",
  1161. "name1": "FightSong4",
  1162. "name2": "FightSong4"
  1163. },
  1164. {
  1165. "key": "DeadSong2",
  1166. "kind": "Song",
  1167. "name1": "DeadSong2",
  1168. "name2": "DeadSong2"
  1169. },
  1170. {
  1171. "key": "LoveSong3",
  1172. "kind": "Song",
  1173. "name1": "LoveSong3",
  1174. "name2": "LoveSong3"
  1175. },
  1176. {
  1177. "key": "MyOnlySong3",
  1178. "kind": "Song",
  1179. "name1": "MyOnlySong3",
  1180. "name2": "MyOnlySong3"
  1181. },
  1182. {
  1183. "key": "Aria1",
  1184. "kind": "Song",
  1185. "name1": "Aria1",
  1186. "name2": "Aria1"
  1187. },
  1188. {
  1189. "key": "Aria2",
  1190. "kind": "Song",
  1191. "name1": "Aria2",
  1192. "name2": "Aria2"
  1193. },
  1194. {
  1195. "key": "Aria3",
  1196. "kind": "Song",
  1197. "name1": "Aria3",
  1198. "name2": "Aria3"
  1199. },
  1200. {
  1201. "key": "Aria4",
  1202. "kind": "Song",
  1203. "name1": "Aria4",
  1204. "name2": "Aria4"
  1205. }
  1206. ]
  1207. },
  1208. "errors": [
  1209. {
  1210. "locations": [
  1211. {
  1212. "column": 9,
  1213. "line": 8
  1214. }
  1215. ],
  1216. "message": "Field identifier key used multiple times",
  1217. "path": [
  1218. "Song"
  1219. ]
  1220. }
  1221. ]
  1222. }`[1:], query, gm); rerr != nil {
  1223. t.Error(rerr)
  1224. return
  1225. }
  1226. }