postInstall.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // A script to be executed post query-node install, that may include workarounds in Hydra node_modules
  2. import fs from 'fs'
  3. import path from 'path'
  4. // FIXME: Temporarly remove broken sanitizeNullCharacter call
  5. const subscribersJsPath = path.resolve(
  6. __dirname,
  7. '../../../node_modules/@joystream/hydra-processor/lib/db/subscribers.js'
  8. )
  9. const subscribersJsContent = fs.readFileSync(subscribersJsPath).toString()
  10. fs.writeFileSync(
  11. subscribersJsPath,
  12. subscribersJsContent.replace(/sanitizeNullCharacter\(entity, field\);/g, '//sanitizeNullCharacter(entity, field)')
  13. )
  14. // FIXME: Temporarly replace broken relations resolution in @joystream/warthog
  15. const dataLoaderJsPath = path.resolve(
  16. __dirname,
  17. '../../../node_modules/@joystream/warthog/dist/middleware/DataLoaderMiddleware.js'
  18. )
  19. const dataLoaderJsContent = fs.readFileSync(dataLoaderJsPath).toString()
  20. const dataLoaderJsContentLines = dataLoaderJsContent.split('\n')
  21. dataLoaderJsContentLines.splice(
  22. dataLoaderJsContentLines.findIndex((l) => l.match(/return context\.connection\.relationIdLoader/)),
  23. 0,
  24. `return Promise.all(
  25. entities.map(entity => context.connection.relationLoader.load(relation, entity))
  26. ).then(function (results) {
  27. return results.map(function (related) {
  28. return (relation.isManyToOne || relation.isOneToOne) ? related[0] : related
  29. })
  30. })
  31. `
  32. )
  33. fs.writeFileSync(dataLoaderJsPath, dataLoaderJsContentLines.join('\n'))