@platformatic/sql-graphql 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.nyc_output/{ea305ecd-1796-4c6b-a9e4-503ca63f2d42.json → 02e6172c-f2ba-40f1-9d5d-86451759372c.json} +0 -0
  2. package/.nyc_output/06e1b082-c272-4876-b72f-14a940fb4e16.json +1 -0
  3. package/.nyc_output/393706b4-dd23-4644-a301-1ae1b551d5a0.json +1 -0
  4. package/.nyc_output/49ebb061-4831-4245-aeb8-dea830e8513b.json +1 -0
  5. package/.nyc_output/4c84319f-8089-4a76-8f49-474d69c477e2.json +1 -0
  6. package/.nyc_output/64081cdd-16a1-4dac-959c-6bd9f98b458e.json +1 -0
  7. package/.nyc_output/6a1062ee-935e-4b4d-9dd7-cc70277e5916.json +1 -0
  8. package/.nyc_output/7d3bbc3d-1c87-46e8-93d7-372bb91a5784.json +1 -0
  9. package/.nyc_output/9b470ca8-a83d-4499-9830-fa4698aa8655.json +1 -0
  10. package/.nyc_output/d470f916-c2cc-4ace-9341-9893e631826b.json +1 -0
  11. package/.nyc_output/df3d5175-9faa-48e8-b218-b3b5e9709f08.json +1 -0
  12. package/.nyc_output/ee904462-d684-4118-aa0a-58d306f34e5e.json +1 -0
  13. package/.nyc_output/ef850e84-b27d-4a2f-838c-56312a338f26.json +1 -0
  14. package/.nyc_output/f699a0f3-0d25-4890-a6de-94d8cdedb7d6.json +1 -0
  15. package/.nyc_output/f782edc5-072d-48f2-9c74-f0bcd7b86010.json +1 -0
  16. package/.nyc_output/f818f3a6-33e4-4b4c-805d-69e3274bf1d1.json +1 -0
  17. package/.nyc_output/processinfo/{ea305ecd-1796-4c6b-a9e4-503ca63f2d42.json → 02e6172c-f2ba-40f1-9d5d-86451759372c.json} +1 -1
  18. package/.nyc_output/processinfo/06e1b082-c272-4876-b72f-14a940fb4e16.json +1 -0
  19. package/.nyc_output/processinfo/393706b4-dd23-4644-a301-1ae1b551d5a0.json +1 -0
  20. package/.nyc_output/processinfo/{354b1308-2042-4a6c-9cf3-07be876efbb3.json → 49ebb061-4831-4245-aeb8-dea830e8513b.json} +1 -1
  21. package/.nyc_output/processinfo/4c84319f-8089-4a76-8f49-474d69c477e2.json +1 -0
  22. package/.nyc_output/processinfo/64081cdd-16a1-4dac-959c-6bd9f98b458e.json +1 -0
  23. package/.nyc_output/processinfo/{415ccadc-7e96-410e-ae66-6ca11ce92b8c.json → 6a1062ee-935e-4b4d-9dd7-cc70277e5916.json} +1 -1
  24. package/.nyc_output/processinfo/7d3bbc3d-1c87-46e8-93d7-372bb91a5784.json +1 -0
  25. package/.nyc_output/processinfo/9b470ca8-a83d-4499-9830-fa4698aa8655.json +1 -0
  26. package/.nyc_output/processinfo/d470f916-c2cc-4ace-9341-9893e631826b.json +1 -0
  27. package/.nyc_output/processinfo/df3d5175-9faa-48e8-b218-b3b5e9709f08.json +1 -0
  28. package/.nyc_output/processinfo/ee904462-d684-4118-aa0a-58d306f34e5e.json +1 -0
  29. package/.nyc_output/processinfo/{a5752887-ebcd-4670-bc8e-8d75a3c1ae51.json → ef850e84-b27d-4a2f-838c-56312a338f26.json} +1 -1
  30. package/.nyc_output/processinfo/f699a0f3-0d25-4890-a6de-94d8cdedb7d6.json +1 -0
  31. package/.nyc_output/processinfo/f782edc5-072d-48f2-9c74-f0bcd7b86010.json +1 -0
  32. package/.nyc_output/processinfo/f818f3a6-33e4-4b4c-805d-69e3274bf1d1.json +1 -0
  33. package/.nyc_output/processinfo/index.json +1 -1
  34. package/index.js +19 -2
  35. package/lib/entity-to-type.js +1 -0
  36. package/lib/relationship.js +2 -2
  37. package/lib/subscriptions.js +89 -0
  38. package/package.json +6 -4
  39. package/test/helper.js +9 -0
  40. package/test/relations.test.js +145 -0
  41. package/test/subscription.test.js +336 -0
  42. package/.nyc_output/0ebb7c74-e9d0-4427-873f-707c97b71e3a.json +0 -1
  43. package/.nyc_output/1705f757-0633-4d57-bdd8-74da5e87c7f2.json +0 -1
  44. package/.nyc_output/18dca461-a16b-4426-8125-755b1714aa40.json +0 -1
  45. package/.nyc_output/1f6f25f8-9751-4755-94d9-99047f9e7f95.json +0 -1
  46. package/.nyc_output/25c88717-db5b-4879-a56e-cf27a8748dc0.json +0 -1
  47. package/.nyc_output/354b1308-2042-4a6c-9cf3-07be876efbb3.json +0 -1
  48. package/.nyc_output/415ccadc-7e96-410e-ae66-6ca11ce92b8c.json +0 -1
  49. package/.nyc_output/5f643acb-71a2-42a1-8e2c-3c830382e6c3.json +0 -1
  50. package/.nyc_output/7cc4fa46-505d-4868-802f-b22374f1aa0f.json +0 -1
  51. package/.nyc_output/90d66f5a-41c4-4c50-95f5-078e68e2ee4d.json +0 -1
  52. package/.nyc_output/a5752887-ebcd-4670-bc8e-8d75a3c1ae51.json +0 -1
  53. package/.nyc_output/a9d0b301-bd1a-4076-bdd5-e311adb96683.json +0 -1
  54. package/.nyc_output/cb3b5287-a592-492a-bf10-ecb456437154.json +0 -1
  55. package/.nyc_output/d13b13a2-ef5a-4e88-949e-77c62f98abd2.json +0 -1
  56. package/.nyc_output/fc62d83a-4179-44bf-9bbb-b306531568e9.json +0 -1
  57. package/.nyc_output/processinfo/0ebb7c74-e9d0-4427-873f-707c97b71e3a.json +0 -1
  58. package/.nyc_output/processinfo/1705f757-0633-4d57-bdd8-74da5e87c7f2.json +0 -1
  59. package/.nyc_output/processinfo/18dca461-a16b-4426-8125-755b1714aa40.json +0 -1
  60. package/.nyc_output/processinfo/1f6f25f8-9751-4755-94d9-99047f9e7f95.json +0 -1
  61. package/.nyc_output/processinfo/25c88717-db5b-4879-a56e-cf27a8748dc0.json +0 -1
  62. package/.nyc_output/processinfo/5f643acb-71a2-42a1-8e2c-3c830382e6c3.json +0 -1
  63. package/.nyc_output/processinfo/7cc4fa46-505d-4868-802f-b22374f1aa0f.json +0 -1
  64. package/.nyc_output/processinfo/90d66f5a-41c4-4c50-95f5-078e68e2ee4d.json +0 -1
  65. package/.nyc_output/processinfo/a9d0b301-bd1a-4076-bdd5-e311adb96683.json +0 -1
  66. package/.nyc_output/processinfo/cb3b5287-a592-492a-bf10-ecb456437154.json +0 -1
  67. package/.nyc_output/processinfo/d13b13a2-ef5a-4e88-949e-77c62f98abd2.json +0 -1
  68. package/.nyc_output/processinfo/fc62d83a-4179-44bf-9bbb-b306531568e9.json +0 -1
@@ -0,0 +1 @@
1
+ {"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","pid":85683,"argv":["/Users/matteo/.nvm/versions/node/v18.12.0/bin/node","/Users/matteo/Repositories/platformatic/packages/sql-graphql/test/simple.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-graphql","time":1667554726652,"ppid":85671,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-graphql/.nyc_output/7d3bbc3d-1c87-46e8-93d7-372bb91a5784.json","externalId":"test/simple.test.js","uuid":"7d3bbc3d-1c87-46e8-93d7-372bb91a5784","files":["/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js"]}
@@ -0,0 +1 @@
1
+ {"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","pid":85674,"argv":["/Users/matteo/.nvm/versions/node/v18.12.0/bin/node","/Users/matteo/Repositories/platformatic/packages/sql-graphql/test/federation.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-graphql","time":1667554721959,"ppid":85671,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-graphql/.nyc_output/9b470ca8-a83d-4499-9830-fa4698aa8655.json","externalId":"test/federation.test.js","uuid":"9b470ca8-a83d-4499-9830-fa4698aa8655","files":["/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js"]}
@@ -0,0 +1 @@
1
+ {"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","pid":85677,"argv":["/Users/matteo/.nvm/versions/node/v18.12.0/bin/node","/Users/matteo/Repositories/platformatic/packages/sql-graphql/test/insert.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-graphql","time":1667554723203,"ppid":85671,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-graphql/.nyc_output/d470f916-c2cc-4ace-9341-9893e631826b.json","externalId":"test/insert.test.js","uuid":"d470f916-c2cc-4ace-9341-9893e631826b","files":["/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js"]}
@@ -0,0 +1 @@
1
+ {"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","pid":85684,"argv":["/Users/matteo/.nvm/versions/node/v18.12.0/bin/node","/Users/matteo/Repositories/platformatic/packages/sql-graphql/test/sqlite.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-graphql","time":1667554727179,"ppid":85671,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-graphql/.nyc_output/df3d5175-9faa-48e8-b218-b3b5e9709f08.json","externalId":"test/sqlite.test.js","uuid":"df3d5175-9faa-48e8-b218-b3b5e9709f08","files":["/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js"]}
@@ -0,0 +1 @@
1
+ {"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","pid":85681,"argv":["/Users/matteo/.nvm/versions/node/v18.12.0/bin/node","/Users/matteo/Repositories/platformatic/packages/sql-graphql/test/order_by.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-graphql","time":1667554725833,"ppid":85671,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-graphql/.nyc_output/ee904462-d684-4118-aa0a-58d306f34e5e.json","externalId":"test/order_by.test.js","uuid":"ee904462-d684-4118-aa0a-58d306f34e5e","files":["/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js"]}
@@ -1 +1 @@
1
- {"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","pid":59594,"argv":["/Users/matteo/.nvm/versions/node/v16.17.0/bin/node","/Users/matteo/Repositories/platformatic/packages/sql-graphql/test/subscription.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-graphql","time":1666215963619,"ppid":59580,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-graphql/.nyc_output/a5752887-ebcd-4670-bc8e-8d75a3c1ae51.json","externalId":"test/subscription.test.js","uuid":"a5752887-ebcd-4670-bc8e-8d75a3c1ae51","files":["/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js"]}
1
+ {"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","pid":85685,"argv":["/Users/matteo/.nvm/versions/node/v18.12.0/bin/node","/Users/matteo/Repositories/platformatic/packages/sql-graphql/test/subscription.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-graphql","time":1667554727584,"ppid":85671,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-graphql/.nyc_output/ef850e84-b27d-4a2f-838c-56312a338f26.json","externalId":"test/subscription.test.js","uuid":"ef850e84-b27d-4a2f-838c-56312a338f26","files":["/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js"]}
@@ -0,0 +1 @@
1
+ {"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","pid":85672,"argv":["/Users/matteo/.nvm/versions/node/v18.12.0/bin/node","/Users/matteo/Repositories/platformatic/packages/sql-graphql/test/count.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-graphql","time":1667554721187,"ppid":85671,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-graphql/.nyc_output/f699a0f3-0d25-4890-a6de-94d8cdedb7d6.json","externalId":"test/count.test.js","uuid":"f699a0f3-0d25-4890-a6de-94d8cdedb7d6","files":["/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js"]}
@@ -0,0 +1 @@
1
+ {"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","pid":85679,"argv":["/Users/matteo/.nvm/versions/node/v18.12.0/bin/node","/Users/matteo/Repositories/platformatic/packages/sql-graphql/test/nested.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-graphql","time":1667554725030,"ppid":85671,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-graphql/.nyc_output/f782edc5-072d-48f2-9c74-f0bcd7b86010.json","externalId":"test/nested.test.js","uuid":"f782edc5-072d-48f2-9c74-f0bcd7b86010","files":["/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js"]}
@@ -0,0 +1 @@
1
+ {"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","pid":85676,"argv":["/Users/matteo/.nvm/versions/node/v18.12.0/bin/node","/Users/matteo/Repositories/platformatic/packages/sql-graphql/test/ignore.test.js"],"execArgv":[],"cwd":"/Users/matteo/Repositories/platformatic/packages/sql-graphql","time":1667554722826,"ppid":85671,"coverageFilename":"/Users/matteo/Repositories/platformatic/packages/sql-graphql/.nyc_output/f818f3a6-33e4-4b4c-805d-69e3274bf1d1.json","externalId":"test/ignore.test.js","uuid":"f818f3a6-33e4-4b4c-805d-69e3274bf1d1","files":["/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js","/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js"]}
@@ -1 +1 @@
1
- {"processes":{"0ebb7c74-e9d0-4427-873f-707c97b71e3a":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/federation.test.js","children":[]},"1705f757-0633-4d57-bdd8-74da5e87c7f2":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/count.test.js","children":[]},"18dca461-a16b-4426-8125-755b1714aa40":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/insert.test.js","children":[]},"1f6f25f8-9751-4755-94d9-99047f9e7f95":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/sqlite.test.js","children":[]},"25c88717-db5b-4879-a56e-cf27a8748dc0":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/where.test.js","children":[]},"354b1308-2042-4a6c-9cf3-07be876efbb3":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/no-modification-of-entity.test.js","children":[]},"415ccadc-7e96-410e-ae66-6ca11ce92b8c":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/inserted_updated_at.test.js","children":[]},"5f643acb-71a2-42a1-8e2c-3c830382e6c3":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/relations.test.js","children":[]},"7cc4fa46-505d-4868-802f-b22374f1aa0f":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/datatypes.test.js","children":[]},"90d66f5a-41c4-4c50-95f5-078e68e2ee4d":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/ignore.test.js","children":[]},"a5752887-ebcd-4670-bc8e-8d75a3c1ae51":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/subscription.test.js","children":[]},"a9d0b301-bd1a-4076-bdd5-e311adb96683":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/hooks.test.js","children":[]},"cb3b5287-a592-492a-bf10-ecb456437154":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/simple.test.js","children":[]},"d13b13a2-ef5a-4e88-949e-77c62f98abd2":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/nested.test.js","children":[]},"ea305ecd-1796-4c6b-a9e4-503ca63f2d42":{"parent":null,"children":["0ebb7c74-e9d0-4427-873f-707c97b71e3a","1705f757-0633-4d57-bdd8-74da5e87c7f2","18dca461-a16b-4426-8125-755b1714aa40","1f6f25f8-9751-4755-94d9-99047f9e7f95","25c88717-db5b-4879-a56e-cf27a8748dc0","354b1308-2042-4a6c-9cf3-07be876efbb3","415ccadc-7e96-410e-ae66-6ca11ce92b8c","5f643acb-71a2-42a1-8e2c-3c830382e6c3","7cc4fa46-505d-4868-802f-b22374f1aa0f","90d66f5a-41c4-4c50-95f5-078e68e2ee4d","a5752887-ebcd-4670-bc8e-8d75a3c1ae51","a9d0b301-bd1a-4076-bdd5-e311adb96683","cb3b5287-a592-492a-bf10-ecb456437154","d13b13a2-ef5a-4e88-949e-77c62f98abd2","fc62d83a-4179-44bf-9bbb-b306531568e9"]},"fc62d83a-4179-44bf-9bbb-b306531568e9":{"parent":"ea305ecd-1796-4c6b-a9e4-503ca63f2d42","externalId":"test/order_by.test.js","children":[]}},"files":{"/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js":["0ebb7c74-e9d0-4427-873f-707c97b71e3a","1705f757-0633-4d57-bdd8-74da5e87c7f2","18dca461-a16b-4426-8125-755b1714aa40","1f6f25f8-9751-4755-94d9-99047f9e7f95","25c88717-db5b-4879-a56e-cf27a8748dc0","354b1308-2042-4a6c-9cf3-07be876efbb3","415ccadc-7e96-410e-ae66-6ca11ce92b8c","5f643acb-71a2-42a1-8e2c-3c830382e6c3","7cc4fa46-505d-4868-802f-b22374f1aa0f","90d66f5a-41c4-4c50-95f5-078e68e2ee4d","a5752887-ebcd-4670-bc8e-8d75a3c1ae51","a9d0b301-bd1a-4076-bdd5-e311adb96683","cb3b5287-a592-492a-bf10-ecb456437154","d13b13a2-ef5a-4e88-949e-77c62f98abd2","fc62d83a-4179-44bf-9bbb-b306531568e9"],"/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js":["0ebb7c74-e9d0-4427-873f-707c97b71e3a","1705f757-0633-4d57-bdd8-74da5e87c7f2","18dca461-a16b-4426-8125-755b1714aa40","1f6f25f8-9751-4755-94d9-99047f9e7f95","25c88717-db5b-4879-a56e-cf27a8748dc0","354b1308-2042-4a6c-9cf3-07be876efbb3","415ccadc-7e96-410e-ae66-6ca11ce92b8c","5f643acb-71a2-42a1-8e2c-3c830382e6c3","7cc4fa46-505d-4868-802f-b22374f1aa0f","90d66f5a-41c4-4c50-95f5-078e68e2ee4d","a5752887-ebcd-4670-bc8e-8d75a3c1ae51","a9d0b301-bd1a-4076-bdd5-e311adb96683","cb3b5287-a592-492a-bf10-ecb456437154","d13b13a2-ef5a-4e88-949e-77c62f98abd2","fc62d83a-4179-44bf-9bbb-b306531568e9"],"/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js":["0ebb7c74-e9d0-4427-873f-707c97b71e3a","1705f757-0633-4d57-bdd8-74da5e87c7f2","18dca461-a16b-4426-8125-755b1714aa40","1f6f25f8-9751-4755-94d9-99047f9e7f95","25c88717-db5b-4879-a56e-cf27a8748dc0","354b1308-2042-4a6c-9cf3-07be876efbb3","415ccadc-7e96-410e-ae66-6ca11ce92b8c","5f643acb-71a2-42a1-8e2c-3c830382e6c3","7cc4fa46-505d-4868-802f-b22374f1aa0f","90d66f5a-41c4-4c50-95f5-078e68e2ee4d","a5752887-ebcd-4670-bc8e-8d75a3c1ae51","a9d0b301-bd1a-4076-bdd5-e311adb96683","cb3b5287-a592-492a-bf10-ecb456437154","d13b13a2-ef5a-4e88-949e-77c62f98abd2","fc62d83a-4179-44bf-9bbb-b306531568e9"],"/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js":["0ebb7c74-e9d0-4427-873f-707c97b71e3a","1705f757-0633-4d57-bdd8-74da5e87c7f2","18dca461-a16b-4426-8125-755b1714aa40","1f6f25f8-9751-4755-94d9-99047f9e7f95","25c88717-db5b-4879-a56e-cf27a8748dc0","354b1308-2042-4a6c-9cf3-07be876efbb3","415ccadc-7e96-410e-ae66-6ca11ce92b8c","5f643acb-71a2-42a1-8e2c-3c830382e6c3","7cc4fa46-505d-4868-802f-b22374f1aa0f","90d66f5a-41c4-4c50-95f5-078e68e2ee4d","a5752887-ebcd-4670-bc8e-8d75a3c1ae51","a9d0b301-bd1a-4076-bdd5-e311adb96683","cb3b5287-a592-492a-bf10-ecb456437154","d13b13a2-ef5a-4e88-949e-77c62f98abd2","fc62d83a-4179-44bf-9bbb-b306531568e9"],"/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js":["0ebb7c74-e9d0-4427-873f-707c97b71e3a","1705f757-0633-4d57-bdd8-74da5e87c7f2","18dca461-a16b-4426-8125-755b1714aa40","1f6f25f8-9751-4755-94d9-99047f9e7f95","25c88717-db5b-4879-a56e-cf27a8748dc0","354b1308-2042-4a6c-9cf3-07be876efbb3","415ccadc-7e96-410e-ae66-6ca11ce92b8c","5f643acb-71a2-42a1-8e2c-3c830382e6c3","7cc4fa46-505d-4868-802f-b22374f1aa0f","90d66f5a-41c4-4c50-95f5-078e68e2ee4d","a5752887-ebcd-4670-bc8e-8d75a3c1ae51","a9d0b301-bd1a-4076-bdd5-e311adb96683","cb3b5287-a592-492a-bf10-ecb456437154","d13b13a2-ef5a-4e88-949e-77c62f98abd2","fc62d83a-4179-44bf-9bbb-b306531568e9"]},"externalIds":{"test/federation.test.js":{"root":"0ebb7c74-e9d0-4427-873f-707c97b71e3a","children":[]},"test/count.test.js":{"root":"1705f757-0633-4d57-bdd8-74da5e87c7f2","children":[]},"test/insert.test.js":{"root":"18dca461-a16b-4426-8125-755b1714aa40","children":[]},"test/sqlite.test.js":{"root":"1f6f25f8-9751-4755-94d9-99047f9e7f95","children":[]},"test/where.test.js":{"root":"25c88717-db5b-4879-a56e-cf27a8748dc0","children":[]},"test/no-modification-of-entity.test.js":{"root":"354b1308-2042-4a6c-9cf3-07be876efbb3","children":[]},"test/inserted_updated_at.test.js":{"root":"415ccadc-7e96-410e-ae66-6ca11ce92b8c","children":[]},"test/relations.test.js":{"root":"5f643acb-71a2-42a1-8e2c-3c830382e6c3","children":[]},"test/datatypes.test.js":{"root":"7cc4fa46-505d-4868-802f-b22374f1aa0f","children":[]},"test/ignore.test.js":{"root":"90d66f5a-41c4-4c50-95f5-078e68e2ee4d","children":[]},"test/subscription.test.js":{"root":"a5752887-ebcd-4670-bc8e-8d75a3c1ae51","children":[]},"test/hooks.test.js":{"root":"a9d0b301-bd1a-4076-bdd5-e311adb96683","children":[]},"test/simple.test.js":{"root":"cb3b5287-a592-492a-bf10-ecb456437154","children":[]},"test/nested.test.js":{"root":"d13b13a2-ef5a-4e88-949e-77c62f98abd2","children":[]},"test/order_by.test.js":{"root":"fc62d83a-4179-44bf-9bbb-b306531568e9","children":[]}}}
1
+ {"processes":{"02e6172c-f2ba-40f1-9d5d-86451759372c":{"parent":null,"children":["06e1b082-c272-4876-b72f-14a940fb4e16","393706b4-dd23-4644-a301-1ae1b551d5a0","49ebb061-4831-4245-aeb8-dea830e8513b","4c84319f-8089-4a76-8f49-474d69c477e2","64081cdd-16a1-4dac-959c-6bd9f98b458e","6a1062ee-935e-4b4d-9dd7-cc70277e5916","7d3bbc3d-1c87-46e8-93d7-372bb91a5784","9b470ca8-a83d-4499-9830-fa4698aa8655","d470f916-c2cc-4ace-9341-9893e631826b","df3d5175-9faa-48e8-b218-b3b5e9709f08","ee904462-d684-4118-aa0a-58d306f34e5e","ef850e84-b27d-4a2f-838c-56312a338f26","f699a0f3-0d25-4890-a6de-94d8cdedb7d6","f782edc5-072d-48f2-9c74-f0bcd7b86010","f818f3a6-33e4-4b4c-805d-69e3274bf1d1"]},"06e1b082-c272-4876-b72f-14a940fb4e16":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/hooks.test.js","children":[]},"393706b4-dd23-4644-a301-1ae1b551d5a0":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/where.test.js","children":[]},"49ebb061-4831-4245-aeb8-dea830e8513b":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/no-modification-of-entity.test.js","children":[]},"4c84319f-8089-4a76-8f49-474d69c477e2":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/relations.test.js","children":[]},"64081cdd-16a1-4dac-959c-6bd9f98b458e":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/datatypes.test.js","children":[]},"6a1062ee-935e-4b4d-9dd7-cc70277e5916":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/inserted_updated_at.test.js","children":[]},"7d3bbc3d-1c87-46e8-93d7-372bb91a5784":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/simple.test.js","children":[]},"9b470ca8-a83d-4499-9830-fa4698aa8655":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/federation.test.js","children":[]},"d470f916-c2cc-4ace-9341-9893e631826b":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/insert.test.js","children":[]},"df3d5175-9faa-48e8-b218-b3b5e9709f08":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/sqlite.test.js","children":[]},"ee904462-d684-4118-aa0a-58d306f34e5e":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/order_by.test.js","children":[]},"ef850e84-b27d-4a2f-838c-56312a338f26":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/subscription.test.js","children":[]},"f699a0f3-0d25-4890-a6de-94d8cdedb7d6":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/count.test.js","children":[]},"f782edc5-072d-48f2-9c74-f0bcd7b86010":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/nested.test.js","children":[]},"f818f3a6-33e4-4b4c-805d-69e3274bf1d1":{"parent":"02e6172c-f2ba-40f1-9d5d-86451759372c","externalId":"test/ignore.test.js","children":[]}},"files":{"/Users/matteo/Repositories/platformatic/packages/sql-graphql/index.js":["06e1b082-c272-4876-b72f-14a940fb4e16","393706b4-dd23-4644-a301-1ae1b551d5a0","49ebb061-4831-4245-aeb8-dea830e8513b","4c84319f-8089-4a76-8f49-474d69c477e2","64081cdd-16a1-4dac-959c-6bd9f98b458e","6a1062ee-935e-4b4d-9dd7-cc70277e5916","7d3bbc3d-1c87-46e8-93d7-372bb91a5784","9b470ca8-a83d-4499-9830-fa4698aa8655","d470f916-c2cc-4ace-9341-9893e631826b","df3d5175-9faa-48e8-b218-b3b5e9709f08","ee904462-d684-4118-aa0a-58d306f34e5e","ef850e84-b27d-4a2f-838c-56312a338f26","f699a0f3-0d25-4890-a6de-94d8cdedb7d6","f782edc5-072d-48f2-9c74-f0bcd7b86010","f818f3a6-33e4-4b4c-805d-69e3274bf1d1"],"/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/entity-to-type.js":["06e1b082-c272-4876-b72f-14a940fb4e16","393706b4-dd23-4644-a301-1ae1b551d5a0","49ebb061-4831-4245-aeb8-dea830e8513b","4c84319f-8089-4a76-8f49-474d69c477e2","64081cdd-16a1-4dac-959c-6bd9f98b458e","6a1062ee-935e-4b4d-9dd7-cc70277e5916","7d3bbc3d-1c87-46e8-93d7-372bb91a5784","9b470ca8-a83d-4499-9830-fa4698aa8655","d470f916-c2cc-4ace-9341-9893e631826b","df3d5175-9faa-48e8-b218-b3b5e9709f08","ee904462-d684-4118-aa0a-58d306f34e5e","ef850e84-b27d-4a2f-838c-56312a338f26","f699a0f3-0d25-4890-a6de-94d8cdedb7d6","f782edc5-072d-48f2-9c74-f0bcd7b86010","f818f3a6-33e4-4b4c-805d-69e3274bf1d1"],"/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/utils.js":["06e1b082-c272-4876-b72f-14a940fb4e16","393706b4-dd23-4644-a301-1ae1b551d5a0","49ebb061-4831-4245-aeb8-dea830e8513b","4c84319f-8089-4a76-8f49-474d69c477e2","64081cdd-16a1-4dac-959c-6bd9f98b458e","6a1062ee-935e-4b4d-9dd7-cc70277e5916","7d3bbc3d-1c87-46e8-93d7-372bb91a5784","9b470ca8-a83d-4499-9830-fa4698aa8655","d470f916-c2cc-4ace-9341-9893e631826b","df3d5175-9faa-48e8-b218-b3b5e9709f08","ee904462-d684-4118-aa0a-58d306f34e5e","ef850e84-b27d-4a2f-838c-56312a338f26","f699a0f3-0d25-4890-a6de-94d8cdedb7d6","f782edc5-072d-48f2-9c74-f0bcd7b86010","f818f3a6-33e4-4b4c-805d-69e3274bf1d1"],"/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/relationship.js":["06e1b082-c272-4876-b72f-14a940fb4e16","393706b4-dd23-4644-a301-1ae1b551d5a0","49ebb061-4831-4245-aeb8-dea830e8513b","4c84319f-8089-4a76-8f49-474d69c477e2","64081cdd-16a1-4dac-959c-6bd9f98b458e","6a1062ee-935e-4b4d-9dd7-cc70277e5916","7d3bbc3d-1c87-46e8-93d7-372bb91a5784","9b470ca8-a83d-4499-9830-fa4698aa8655","d470f916-c2cc-4ace-9341-9893e631826b","df3d5175-9faa-48e8-b218-b3b5e9709f08","ee904462-d684-4118-aa0a-58d306f34e5e","ef850e84-b27d-4a2f-838c-56312a338f26","f699a0f3-0d25-4890-a6de-94d8cdedb7d6","f782edc5-072d-48f2-9c74-f0bcd7b86010","f818f3a6-33e4-4b4c-805d-69e3274bf1d1"],"/Users/matteo/Repositories/platformatic/packages/sql-graphql/lib/subscriptions.js":["06e1b082-c272-4876-b72f-14a940fb4e16","393706b4-dd23-4644-a301-1ae1b551d5a0","49ebb061-4831-4245-aeb8-dea830e8513b","4c84319f-8089-4a76-8f49-474d69c477e2","64081cdd-16a1-4dac-959c-6bd9f98b458e","6a1062ee-935e-4b4d-9dd7-cc70277e5916","7d3bbc3d-1c87-46e8-93d7-372bb91a5784","9b470ca8-a83d-4499-9830-fa4698aa8655","d470f916-c2cc-4ace-9341-9893e631826b","df3d5175-9faa-48e8-b218-b3b5e9709f08","ee904462-d684-4118-aa0a-58d306f34e5e","ef850e84-b27d-4a2f-838c-56312a338f26","f699a0f3-0d25-4890-a6de-94d8cdedb7d6","f782edc5-072d-48f2-9c74-f0bcd7b86010","f818f3a6-33e4-4b4c-805d-69e3274bf1d1"]},"externalIds":{"test/hooks.test.js":{"root":"06e1b082-c272-4876-b72f-14a940fb4e16","children":[]},"test/where.test.js":{"root":"393706b4-dd23-4644-a301-1ae1b551d5a0","children":[]},"test/no-modification-of-entity.test.js":{"root":"49ebb061-4831-4245-aeb8-dea830e8513b","children":[]},"test/relations.test.js":{"root":"4c84319f-8089-4a76-8f49-474d69c477e2","children":[]},"test/datatypes.test.js":{"root":"64081cdd-16a1-4dac-959c-6bd9f98b458e","children":[]},"test/inserted_updated_at.test.js":{"root":"6a1062ee-935e-4b4d-9dd7-cc70277e5916","children":[]},"test/simple.test.js":{"root":"7d3bbc3d-1c87-46e8-93d7-372bb91a5784","children":[]},"test/federation.test.js":{"root":"9b470ca8-a83d-4499-9830-fa4698aa8655","children":[]},"test/insert.test.js":{"root":"d470f916-c2cc-4ace-9341-9893e631826b","children":[]},"test/sqlite.test.js":{"root":"df3d5175-9faa-48e8-b218-b3b5e9709f08","children":[]},"test/order_by.test.js":{"root":"ee904462-d684-4118-aa0a-58d306f34e5e","children":[]},"test/subscription.test.js":{"root":"ef850e84-b27d-4a2f-838c-56312a338f26","children":[]},"test/count.test.js":{"root":"f699a0f3-0d25-4890-a6de-94d8cdedb7d6","children":[]},"test/nested.test.js":{"root":"f782edc5-072d-48f2-9c74-f0bcd7b86010","children":[]},"test/ignore.test.js":{"root":"f818f3a6-33e4-4b4c-805d-69e3274bf1d1","children":[]}}}
package/index.js CHANGED
@@ -5,6 +5,7 @@ const constructGraph = require('./lib/entity-to-type')
5
5
  const mercurius = require('mercurius')
6
6
  const graphql = require('graphql')
7
7
  const establishRelations = require('./lib/relationship')
8
+ const setupSubscriptions = require('./lib/subscriptions')
8
9
  const scalars = require('graphql-scalars')
9
10
 
10
11
  async function mapperToGraphql (app, opts) {
@@ -24,6 +25,8 @@ async function mapperToGraphql (app, opts) {
24
25
  federationReplacements,
25
26
  federationMetadata: opts.federationMetadata
26
27
  }
28
+ const metaMap = new Map()
29
+
27
30
  if (Object.keys(mapper.entities).length === 0) {
28
31
  // no schema
29
32
  queryTopFields.hello = { type: graphql.GraphQLString }
@@ -31,7 +34,6 @@ async function mapperToGraphql (app, opts) {
31
34
  hello: () => 'Hello Platformatic!'
32
35
  }
33
36
  } else {
34
- const metaMap = new Map()
35
37
  for (const entity of Object.values(mapper.entities)) {
36
38
  relations.push(...entity.relations)
37
39
  const meta = constructGraph(app, entity, graphOpts)
@@ -85,7 +87,21 @@ async function mapperToGraphql (app, opts) {
85
87
  delete resolvers.Mutation
86
88
  }
87
89
 
88
- let sdl = graphql.printSchema(new graphql.GraphQLSchema({ query, mutation }))
90
+ let subscription
91
+ if (app.platformatic.mq) {
92
+ const entitiesList = Object.keys(app.platformatic.entities)
93
+ const ignoreList = opts.subscriptionIgnore || []
94
+
95
+ if (entitiesList.length - ignoreList.length > 0) {
96
+ opts.subscription = {
97
+ emitter: app.platformatic.mq
98
+ }
99
+ // TODO support ignoring some of those
100
+ subscription = setupSubscriptions(app, metaMap, resolvers, ignoreList)
101
+ }
102
+ }
103
+
104
+ let sdl = graphql.printSchema(new graphql.GraphQLSchema({ query, mutation, subscription }))
89
105
 
90
106
  if (opts.federationMetadata) {
91
107
  for (const replacement of federationReplacements) {
@@ -108,6 +124,7 @@ async function mapperToGraphql (app, opts) {
108
124
  }
109
125
 
110
126
  opts.graphiql = opts.graphiql !== false
127
+
111
128
  await app.register(mercurius, {
112
129
  ...opts,
113
130
  schema: sdl,
@@ -229,6 +229,7 @@ function constructGraph (app, entity, opts) {
229
229
  type,
230
230
  entity,
231
231
  loadMany,
232
+ getFields,
232
233
  fields
233
234
  }
234
235
 
@@ -16,6 +16,7 @@ module.exports = function establishRelations (app, relations, resolvers, loaders
16
16
  for (const relation of relations) {
17
17
  assert(relation.table_name, 'table_name is required')
18
18
  assert(relation.foreign_table_name, 'foreign_table_name is required')
19
+ assert(relation.column_name.toLowerCase().endsWith('id'), 'The column with id reference must be ended with `id` postfix')
19
20
 
20
21
  const current = tablesTypeMap[relation.table_name]
21
22
  const foreign = tablesTypeMap[relation.foreign_table_name]
@@ -23,7 +24,6 @@ module.exports = function establishRelations (app, relations, resolvers, loaders
23
24
 
24
25
  // current to foreign
25
26
  {
26
- assert(relation.column_name.toLowerCase().endsWith('id'), 'The column with id reference must be ended with `id` postfix')
27
27
  const lowered = lowerCaseFirst(camelcase(cutOutIdEnding(relation.column_name)))
28
28
  if (!relationships[current.type] || relationships[current.type][lowered] !== false) {
29
29
  current.fields[lowered] = { type: foreign.type }
@@ -79,7 +79,7 @@ function lowerCaseFirst (str) {
79
79
 
80
80
  function cutOutIdEnding (str) {
81
81
  str = str.toString()
82
- return str.slice(0, str.toLowerCase().indexOf('id'))
82
+ return str.slice(0, str.toLowerCase().lastIndexOf('id'))
83
83
  }
84
84
 
85
85
  function findPrimaryColumnName (camelCasedFields) {
@@ -0,0 +1,89 @@
1
+ 'use strict'
2
+
3
+ const graphql = require('graphql')
4
+
5
+ function setupSubscriptions (app, metaMap, resolvers, ignores) {
6
+ const fields = {}
7
+ resolvers.Subscription = {}
8
+ for (const [field, meta] of metaMap) {
9
+ if (ignores.indexOf(field.singularName) >= 0) {
10
+ continue
11
+ }
12
+ const { type } = meta
13
+ const saved = `${field.singularName}Saved`
14
+ fields[saved] = {
15
+ type
16
+ }
17
+ resolvers.Subscription[saved] = {
18
+ subscribe: async function * (_, query, ctx, info) {
19
+ const log = ctx.reply.request.log
20
+ const { pubsub } = ctx
21
+ const entity = app.platformatic.entities[field.singularName]
22
+ const topic = await entity.getSubscriptionTopic({ action: 'save', ctx })
23
+ log.trace({ topic }, 'subscribed')
24
+ const res = await pubsub.subscribe(topic)
25
+ const primaryKey = entity.primaryKey
26
+ const fields = meta.getFields([{ info }])
27
+
28
+ for await (const msg of res) {
29
+ // TODO optimize this by not calling find() if the subscriber is only asking for the id.
30
+ try {
31
+ log.trace({ msg, entity: field.singularName }, 'graphql subscription augmenting data')
32
+ // The alternative to augmenting the data is installing a resolver for every type
33
+ // of a given entity that loads up the type via a dataloader.
34
+ const found = await entity.find({ where: { [primaryKey]: { eq: msg[primaryKey] } }, fields, ctx })
35
+ // The following could happen in case of a race condition
36
+ // testing it would be very hard, so we skip it for now
37
+ /* istanbul ignore next */
38
+ if (found.length === 0) {
39
+ log.warn({ ...msg.payload, entity: field.singularName }, 'graphql subscription could not find element')
40
+ continue
41
+ }
42
+ const toYield = { [saved]: found[0] }
43
+ log.trace({ yield: toYield, entity: field.singularName }, 'graphql subscription augmented data')
44
+ yield toYield
45
+ } catch (err) {
46
+ /* istanbul ignore next */
47
+ log.warn({ err, entity: field.singularName }, 'graphql subscription error')
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ const deleted = `${field.singularName}Deleted`
54
+ fields[deleted] = {
55
+ type: new graphql.GraphQLObjectType({
56
+ name: `${field.name}Deleted`,
57
+ fields: {
58
+ [field.primaryKey]: {
59
+ type: meta.fields[field.primaryKey].type
60
+ }
61
+ }
62
+ })
63
+ }
64
+ resolvers.Subscription[deleted] = {
65
+ subscribe: async (_, query, ctx, info) => {
66
+ const { pubsub } = ctx
67
+ const entity = app.platformatic.entities[field.singularName]
68
+ const topic = await entity.getSubscriptionTopic({ action: 'delete', ctx })
69
+ const res = await pubsub.subscribe(topic)
70
+ ctx.reply.request.log.trace({ topic }, 'subscribed')
71
+ return wrap(res, deleted)
72
+ }
73
+ }
74
+ }
75
+ const subscription = new graphql.GraphQLObjectType({
76
+ name: 'Subscription',
77
+ fields
78
+ })
79
+
80
+ return subscription
81
+ }
82
+
83
+ async function * wrap (iterator, key) {
84
+ for await (const msg of iterator) {
85
+ yield { [key]: msg }
86
+ }
87
+ }
88
+
89
+ module.exports = setupSubscriptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/sql-graphql",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Map SQL dbs to GraphQL",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -14,12 +14,14 @@
14
14
  },
15
15
  "homepage": "https://github.com/plaformatic/platformatic#readme",
16
16
  "devDependencies": {
17
- "@platformatic/sql-mapper": "0.4.0",
17
+ "@platformatic/sql-events": "0.5.0",
18
+ "@platformatic/sql-mapper": "0.5.0",
18
19
  "fastify": "^4.6.0",
19
20
  "snazzy": "^9.0.0",
20
21
  "standard": "^17.0.0",
21
22
  "tap": "^16.0.0",
22
- "tsd": "^0.24.0"
23
+ "tsd": "^0.24.0",
24
+ "ws": "^8.9.0"
23
25
  },
24
26
  "dependencies": {
25
27
  "camelcase": "^6.0.0",
@@ -28,7 +30,7 @@
28
30
  "graphql-scalars": "^1.13.1",
29
31
  "graphql-type-json": "^0.3.2",
30
32
  "inflected": "^2.1.0",
31
- "mercurius": "^11.0.0"
33
+ "mercurius": "^11.2.0"
32
34
  },
33
35
  "tsd": {
34
36
  "directory": "test/types"
package/test/helper.js CHANGED
@@ -77,4 +77,13 @@ module.exports.clear = async function (db, sql) {
77
77
  await db.query(sql`DROP TABLE authors`)
78
78
  } catch (err) {
79
79
  }
80
+
81
+ try {
82
+ await db.query(sql`DROP TABLE organizations`)
83
+ } catch (err) {
84
+ }
85
+ try {
86
+ await db.query(sql`DROP TABLE individuals`)
87
+ } catch (err) {
88
+ }
80
89
  }
@@ -239,3 +239,148 @@ test('should handle multi references', async ({ pass, teardown, same, equal }) =
239
239
  }, 'query authors response')
240
240
  }
241
241
  })
242
+
243
+ test('cut out id exactly from ending when forming a name of relation', async ({ pass, teardown, same, equal }) => {
244
+ const app = fastify()
245
+ app.register(sqlMapper, {
246
+ ...connInfo,
247
+ async onDatabaseLoad (db, sql) {
248
+ pass('onDatabaseLoad called')
249
+
250
+ await clear(db, sql)
251
+
252
+ if (isMysql) {
253
+ await db.query(sql`
254
+ CREATE TABLE individuals (
255
+ id SERIAL PRIMARY KEY,
256
+ name VARCHAR(255)
257
+ );
258
+ CREATE TABLE organizations (
259
+ id SERIAL PRIMARY KEY,
260
+ name VARCHAR(42),
261
+ individual_id BIGINT UNSIGNED,
262
+ FOREIGN KEY (individual_id) REFERENCES individuals(id) ON DELETE CASCADE
263
+ );
264
+ `)
265
+ } else if (isSQLite) {
266
+ await db.query(sql`
267
+ CREATE TABLE individuals (
268
+ id INTEGER PRIMARY KEY,
269
+ name VARCHAR(255)
270
+ );
271
+ `)
272
+ await db.query(sql`
273
+ CREATE TABLE organizations (
274
+ id INTEGER PRIMARY KEY,
275
+ name VARCHAR(42),
276
+ individual_id BIGINT UNSIGNED,
277
+ FOREIGN KEY (individual_id) REFERENCES individuals(id) ON DELETE CASCADE
278
+ );
279
+ `)
280
+ } else {
281
+ await db.query(sql`
282
+ CREATE TABLE individuals (
283
+ id SERIAL PRIMARY KEY,
284
+ name VARCHAR(42)
285
+ );
286
+ CREATE TABLE organizations (
287
+ id SERIAL PRIMARY KEY,
288
+ name VARCHAR(42),
289
+ individual_id INTEGER REFERENCES individuals(id)
290
+ );
291
+ `)
292
+ }
293
+ }
294
+ })
295
+ app.register(sqlGraphQL)
296
+ teardown(app.close.bind(app))
297
+
298
+ await app.ready()
299
+
300
+ const individuals = [{
301
+ id: 1,
302
+ name: 'Mark'
303
+ }]
304
+
305
+ const organization = [{
306
+ id: 1,
307
+ name: 'Platformatic',
308
+ individualId: 1
309
+ }]
310
+
311
+ {
312
+ const res = await app.inject({
313
+ method: 'POST',
314
+ url: '/graphql',
315
+ body: {
316
+ query: `
317
+ mutation batch($inputs : [IndividualInput]!) {
318
+ insertIndividuals(inputs: $inputs) {
319
+ id
320
+ name
321
+ }
322
+ }
323
+ `,
324
+ variables: {
325
+ inputs: individuals
326
+ }
327
+ }
328
+ })
329
+ equal(res.statusCode, 200, 'individuals status code')
330
+ }
331
+
332
+ {
333
+ const res = await app.inject({
334
+ method: 'POST',
335
+ url: '/graphql',
336
+ body: {
337
+ query: `
338
+ mutation batch($inputs : [OrganizationInput]!) {
339
+ insertOrganizations(inputs: $inputs) {
340
+ id
341
+ name
342
+ }
343
+ }
344
+ `,
345
+ variables: {
346
+ inputs: organization
347
+ }
348
+ }
349
+ })
350
+ equal(res.statusCode, 200, 'organization status code')
351
+ }
352
+
353
+ {
354
+ const res = await app.inject({
355
+ method: 'POST',
356
+ url: '/graphql',
357
+ body: {
358
+ query: `
359
+ query {
360
+ organizations {
361
+ id
362
+ name
363
+ individual {
364
+ id
365
+ name
366
+ }
367
+ }
368
+ }
369
+ `
370
+ }
371
+ })
372
+ equal(res.statusCode, 200, 'query organization')
373
+ same(res.json(), {
374
+ data: {
375
+ organizations: [{
376
+ id: 1,
377
+ name: 'Platformatic',
378
+ individual: {
379
+ id: 1,
380
+ name: 'Mark'
381
+ }
382
+ }]
383
+ }
384
+ }, 'query organization response')
385
+ }
386
+ })