schema.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. local types = require 'types'
  2. local schema = require '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. }
  38. })
  39. local sentient = types.interface({
  40. name = 'Sentient',
  41. fields = {
  42. name = types.string.nonNull
  43. }
  44. })
  45. local alien = types.object({
  46. name = 'Alien',
  47. interfaces = sentient,
  48. fields = {
  49. name = types.string.nonNull,
  50. homePlanet = types.string
  51. }
  52. })
  53. local human = types.object({
  54. name = 'Human',
  55. fields = {
  56. name = types.string.nonNull
  57. }
  58. })
  59. local cat = types.object({
  60. name = 'Cat',
  61. fields = {
  62. name = types.string.nonNull,
  63. nickname = types.string,
  64. meowVolume = types.int
  65. }
  66. })
  67. local catOrDog = types.union({
  68. name = 'CatOrDog',
  69. types = {cat, dog}
  70. })
  71. local dogOrHuman = types.union({
  72. name = 'DogOrHuman',
  73. types = {dog, human}
  74. })
  75. local humanOrAlien = types.union({
  76. name = 'HumanOrAlien',
  77. types = {human, alien}
  78. })
  79. local query = types.object({
  80. name = 'Query',
  81. fields = {
  82. dog = {
  83. kind = dog,
  84. args = {
  85. name = {
  86. kind = types.string
  87. }
  88. }
  89. }
  90. }
  91. })
  92. return schema.create({
  93. query = query
  94. })