소스 검색

Hydra CLI - relationship filtering for search queries patch

Leszek Wiesner 3 년 전
부모
커밋
90f8f97ed7
3개의 변경된 파일27개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      query-node/codegen/package.json
  2. 1 0
      query-node/mappings/package.json
  3. 23 0
      query-node/mappings/scripts/postHydraCLIInstall.ts

+ 3 - 0
query-node/codegen/package.json

@@ -4,6 +4,9 @@
   "description": "Hydra codegen tools for Joystream Query Node",
   "author": "",
   "license": "ISC",
+  "scripts": {
+    "postinstall": "cd .. && yarn workspace query-node-mappings postHydraCLIInstall"
+  },
   "dependencies": {
     "@joystream/hydra-cli": "3.1.0-alpha.13",
     "@joystream/hydra-typegen": "3.1.0-alpha.13"

+ 1 - 0
query-node/mappings/package.json

@@ -12,6 +12,7 @@
     "checks": "prettier ./ --check && yarn lint",
     "format": "prettier ./ --write ",
     "postinstall": "yarn ts-node ./scripts/postInstall.ts",
+    "postHydraCLIInstall": "yarn ts-node ./scripts/postHydraCLIInstall.ts",
     "bootstrap-data:fetch:members": "yarn ts-node ./bootstrap-data/scripts/fetchMembersData.ts",
     "bootstrap-data:fetch:categories": "yarn ts-node ./bootstrap-data/scripts/fetchCategories.ts",
     "bootstrap-data:fetch:workingGroups": "yarn ts-node ./bootstrap-data/scripts/fetchWorkingGroupsData.ts",

+ 23 - 0
query-node/mappings/scripts/postHydraCLIInstall.ts

@@ -0,0 +1,23 @@
+// A script to be executed post hydra-cli install, that may include patches for Hydra CLI
+import fs from 'fs'
+import path from 'path'
+
+// FIXME: Temporary fix for missing JOIN and HAVING conditions in search queries (Hydra)
+const searchServiceTemplatePath = path.resolve(
+  __dirname,
+  '../../codegen/node_modules/@joystream/hydra-cli/lib/src/templates/textsearch/service.ts.mst'
+)
+const searchServiceTemplateContent = fs.readFileSync(searchServiceTemplatePath).toString()
+const searchServiceTemplateContentLines = searchServiceTemplateContent.split('\n')
+searchServiceTemplateContentLines.splice(
+  searchServiceTemplateContentLines.findIndex((l) => l.match(/Add new query to queryString/)) + 1,
+  1, // remove 1 line
+  `queries = queries.concat(generateSqlQuery(repositories[index].metadata.tableName, qb.createJoinExpression(), WHERE, qb.createHavingExpression()));`
+)
+searchServiceTemplateContentLines.splice(
+  searchServiceTemplateContentLines.findIndex((l) => l.match(/const generateSqlQuery = /)),
+  3, // remove 3 lines
+  `const generateSqlQuery = (table: string, joins: string, where: string, having: string) =>
+    \`SELECT '\${table}_' || "\${table}"."id" AS unique_id FROM "\${table}" \` + joins + ' ' + where + ' ' + having;`
+)
+fs.writeFileSync(searchServiceTemplatePath, searchServiceTemplateContentLines.join('\n'))