schema.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. local types = require 'graphql.types'
  2. local schema = require 'graphql.schema'
  3. local dogCommand = types.enum({
  4. name = 'DogCommand',
  5. values = {
  6. SIT = true,
  7. DOWN = true,
  8. HEEL = true
  9. }
  10. })
  11. local pet = types.interface({
  12. name = 'Pet',
  13. fields = {
  14. name = types.string.nonNull,
  15. nickname = types.int
  16. }
  17. })
  18. local dog = types.object({
  19. name = 'Dog',
  20. interfaces = { pet },
  21. fields = {
  22. name = types.string,
  23. nickname = types.string,
  24. barkVolume = types.int,
  25. doesKnowCommand = {
  26. kind = types.boolean.nonNull,
  27. arguments = {
  28. dogCommand = dogCommand.nonNull
  29. }
  30. },
  31. isHouseTrained = {
  32. kind = types.boolean.nonNull,
  33. arguments = {
  34. atOtherHomes = types.boolean
  35. }
  36. },
  37. complicatedField = {
  38. kind = types.boolean,
  39. arguments = {
  40. complicatedArgument = types.inputObject({
  41. name = 'complicated',
  42. fields = {
  43. x = types.string,
  44. y = types.integer,
  45. z = types.inputObject({
  46. name = 'alsoComplicated',
  47. fields = {
  48. x = types.string,
  49. y = types.integer
  50. }
  51. })
  52. }
  53. })
  54. }
  55. }
  56. }
  57. })
  58. local sentient = types.interface({
  59. name = 'Sentient',
  60. fields = {
  61. name = types.string.nonNull
  62. }
  63. })
  64. local alien = types.object({
  65. name = 'Alien',
  66. interfaces = sentient,
  67. fields = {
  68. name = types.string.nonNull,
  69. homePlanet = types.string
  70. }
  71. })
  72. local human = types.object({
  73. name = 'Human',
  74. fields = {
  75. name = types.string.nonNull
  76. }
  77. })
  78. local cat = types.object({
  79. name = 'Cat',
  80. fields = {
  81. name = types.string.nonNull,
  82. nickname = types.string,
  83. meowVolume = types.int
  84. }
  85. })
  86. local catOrDog = types.union({
  87. name = 'CatOrDog',
  88. types = {cat, dog}
  89. })
  90. local dogOrHuman = types.union({
  91. name = 'DogOrHuman',
  92. types = {dog, human}
  93. })
  94. local humanOrAlien = types.union({
  95. name = 'HumanOrAlien',
  96. types = {human, alien}
  97. })
  98. local query = types.object({
  99. name = 'Query',
  100. fields = {
  101. dog = {
  102. kind = dog,
  103. args = {
  104. name = {
  105. kind = types.string
  106. }
  107. }
  108. },
  109. cat = cat,
  110. pet = pet,
  111. sentient = sentient,
  112. catOrDog = catOrDog,
  113. humanOrAlien = humanOrAlien
  114. }
  115. })
  116. return schema.create({
  117. query = query
  118. })