Browse Source

Merge pull request #2967 from Lezek123/giza-update-hydra

Giza Query Node: Update Hydra and remove workarounds
Mokhtar Naamani 3 years ago
parent
commit
ce8c88d539

+ 1 - 0
.env

@@ -28,6 +28,7 @@ BLOCK_HEIGHT=0
 
 GRAPHQL_SERVER_PORT=4002
 GRAPHQL_SERVER_HOST=graphql-server
+GRAPHQL_PLAYGROUND_SUBSCRIPTION_ENDPOINT=ws://localhost:8081/graphql
 
 WARTHOG_APP_PORT=4002
 WARTHOG_APP_HOST=hydra-indexer-gateway

+ 1 - 1
package.json

@@ -50,7 +50,7 @@
     "typeorm": "0.2.34",
     "pg": "^8.4.0",
     "chalk": "^4.0.0",
-    "@joystream/warthog": "2.39.0"
+    "@joystream/warthog": "2.41.2"
   },
   "devDependencies": {
     "eslint": "^7.25.0",

+ 0 - 3
query-node/build.sh

@@ -16,9 +16,6 @@ yarn clean
 yarn codegen:noinstall
 yarn typegen # if this fails try to run this command outside of yarn workspaces
 
-# Post-codegen - fixes in autogenerated files
-yarn ts-node --project ./mappings/tsconfig.json ./mappings/scripts/postCodegen.ts
-
 # We run yarn again to ensure graphql-server dependencies are installed
 # and are inline with root workspace resolutions
 yarn

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

@@ -5,7 +5,6 @@
   "author": "",
   "license": "ISC",
   "scripts": {
-    "postinstall": "cd .. && yarn workspace query-node-mappings postHydraCLIInstall"
   },
   "dependencies": {
     "@joystream/hydra-cli": "3.1.0-alpha.16",

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

@@ -11,8 +11,6 @@
     "lint": "eslint . --quiet --ext .ts",
     "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",
@@ -25,7 +23,7 @@
     "@joystream/metadata-protobuf": "^1.0.0",
     "@joystream/sumer-types": "npm:@joystream/types@^0.16.0",
     "@joystream/types": "^0.17.0",
-    "@joystream/warthog": "2.39.0",
+    "@joystream/warthog": "2.41.2",
     "@apollo/client": "^3.2.5"
   },
   "devDependencies": {

+ 0 - 20
query-node/mappings/scripts/postCodegen.ts

@@ -1,20 +0,0 @@
-// A script to be executed post hydra codegen, that may include modifications to autogenerated files
-import fs from 'fs'
-import path from 'path'
-
-// TS4 useUnknownInCatchVariables is not compatible with auto-generated code inside generated/graphql-server
-const serverTsConfigPath = path.resolve(__dirname, '../../generated/graphql-server/tsconfig.json')
-const serverTsConfig = JSON.parse(fs.readFileSync(serverTsConfigPath).toString())
-serverTsConfig.compilerOptions.useUnknownInCatchVariables = false
-fs.writeFileSync(serverTsConfigPath, JSON.stringify(serverTsConfig, undefined, 2))
-
-// Type assertions are no longer needed for createTypeUnsafe in @polkadot/api 5.9.1 (and they break the build)
-// Here we're relpacing createTypeUnsafe<Assertions>(...params) to createTypeUnsafe(...params) in all generated types:
-const generatedTypesPaths = path.resolve(__dirname, '../generated/types')
-fs.readdirSync(generatedTypesPaths).map((fileName) => {
-  if (path.extname(fileName) === '.ts') {
-    const filePath = path.join(generatedTypesPaths, fileName)
-    const fileContent = fs.readFileSync(filePath).toString()
-    fs.writeFileSync(filePath, fileContent.replace(/createTypeUnsafe<[^(]+[(]/g, 'createTypeUnsafe('))
-  }
-})

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

@@ -1,23 +0,0 @@
-// A script to be executed post hydra-cli install, that may include patches for Hydra CLI
-import path from 'path'
-import { replaceInFile } from './utils'
-
-// 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'
-)
-
-replaceInFile({
-  filePath: searchServiceTemplatePath,
-  regex: /queries = queries\.concat\(generateSqlQuery\(repositories\[index\]\.metadata\.tableName, WHERE\)\);/,
-  newContent:
-    'queries = queries.concat(generateSqlQuery(repositories[index].metadata.tableName, qb.createJoinExpression(), WHERE, qb.createHavingExpression()));',
-})
-
-replaceInFile({
-  filePath: searchServiceTemplatePath,
-  regex: /const generateSqlQuery =[\s\S]+\+ where;/,
-  newContent: `const generateSqlQuery = (table: string, joins: string, where: string, having: string) =>
-  \`SELECT '\${table}_' || "\${table}"."id" AS unique_id FROM "\${table}" \` + joins + ' ' + where + ' ' + having;`,
-})

+ 0 - 45
query-node/mappings/scripts/postInstall.ts

@@ -1,45 +0,0 @@
-// A script to be executed post query-node install, that may include workarounds in Hydra node_modules
-import path from 'path'
-import { replaceInFile } from './utils'
-
-// FIXME: Temporarly remove broken sanitizeNullCharacter call
-const subscribersJsPath = path.resolve(
-  __dirname,
-  '../../../node_modules/@joystream/hydra-processor/lib/db/subscribers.js'
-)
-replaceInFile({
-  filePath: subscribersJsPath,
-  regex: /sanitizeNullCharacter\(entity, field\);/g,
-  newContent: '//sanitizeNullCharacter(entity, field)',
-})
-
-// FIXME: Temporarly replace broken relations resolution in @joystream/warthog
-const dataLoaderJsPath = path.resolve(
-  __dirname,
-  '../../../node_modules/@joystream/warthog/dist/middleware/DataLoaderMiddleware.js'
-)
-replaceInFile({
-  filePath: dataLoaderJsPath,
-  regex: /return context\.connection\.relationIdLoader[\s\S]+return group\.related;\s+\}\);\s+\}\)/,
-  newContent: `return Promise.all(
-    entities.map(entity => context.connection.relationLoader.load(relation, entity))
-  ).then(function (results) {
-    return results.map(function (related) {
-      return (relation.isManyToOne || relation.isOneToOne) ? related[0] : related
-    })
-  })`,
-})
-
-// FIXME: Temporary fix for "table name x specified more than once"
-const baseServiceJsPath = path.resolve(__dirname, '../../../node_modules/@joystream/warthog/dist/core/BaseService.js')
-replaceInFile({
-  filePath: baseServiceJsPath,
-  regex: /function common\(parameters, localIdColumn, foreignTableName, foreignColumnMap, foreignColumnName\) \{[^}]+\}/,
-  newContent: `function common(parameters, localIdColumn, foreignTableName, foreignColumnMap, foreignColumnName) {
-    const uuid = require('uuid/v4')
-    const foreignTableAlias = uuid().replace('-', '')
-    var foreingIdColumn = "\\"" + foreignTableAlias + "\\".\\"" + foreignColumnMap[foreignColumnName] + "\\"";
-    parameters.topLevelQb.leftJoin(foreignTableName, foreignTableAlias, localIdColumn + " = " + foreingIdColumn);
-    addWhereCondition(parameters, foreignTableAlias, foreignColumnMap);
-  }`,
-})

+ 0 - 19
query-node/mappings/scripts/utils.ts

@@ -1,19 +0,0 @@
-import fs from 'fs'
-import { blake2AsHex } from '@polkadot/util-crypto'
-
-type ReplaceLinesInFileParams = {
-  filePath: string
-  regex: RegExp
-  newContent: string
-}
-
-export function replaceInFile({ filePath, regex, newContent }: ReplaceLinesInFileParams): void {
-  const paramsHash = blake2AsHex(filePath + '|' + regex.source + '|' + newContent)
-  const startMark = `/* BEGIN REPLACED CONTENT ${paramsHash} */`
-  const endMark = `/* END REPLACED CONTENT ${paramsHash} */`
-  const fileContent = fs.readFileSync(filePath).toString()
-  if (fileContent.includes(startMark)) {
-    return
-  }
-  fs.writeFileSync(filePath, fileContent.replace(regex, `${startMark}\n${newContent}\n${endMark}`))
-}

+ 11 - 11
yarn.lock

@@ -98,9 +98,9 @@
   dependencies:
     xss "^1.0.8"
 
-"@apollographql/graphql-playground-react@https://github.com/Joystream/graphql-playground/releases/download/query-templates%401.7.27/graphql-playground-react-v1.7.27.tgz":
-  version "1.7.27"
-  resolved "https://github.com/Joystream/graphql-playground/releases/download/query-templates%401.7.27/graphql-playground-react-v1.7.27.tgz#f29765a3a182204bf2bb166a3ed10c7273637af9"
+"@apollographql/graphql-playground-react@https://github.com/Joystream/graphql-playground/releases/download/joystream%401.7.28/graphql-playground-react-v1.7.28.tgz":
+  version "1.7.28"
+  resolved "https://github.com/Joystream/graphql-playground/releases/download/joystream%401.7.28/graphql-playground-react-v1.7.28.tgz#24c9c54e14ae0ba13c894738b4b87301f5801b26"
   dependencies:
     "@types/lru-cache" "^4.1.1"
     apollo-link "^1.2.13"
@@ -3110,12 +3110,12 @@
     lodash "^4.17.15"
     moment "^2.24.0"
 
-"@joystream/warthog@2.39.0", "@joystream/warthog@~2.41.2":
-  version "2.39.0"
-  resolved "https://registry.yarnpkg.com/@joystream/warthog/-/warthog-2.39.0.tgz#3587b94953aed929bff809a7ba763d495e03170c"
-  integrity sha512-gwZ8oBqcN7Xez8BfBDeDIyMhZ7VcL2paMuj0n3qOplyH+sxsBwgBemDzV6RThmAGi3GOhVVQJqOMq3w6siWqzA==
+"@joystream/warthog@2.41.2", "@joystream/warthog@~2.41.2":
+  version "2.41.2"
+  resolved "https://registry.yarnpkg.com/@joystream/warthog/-/warthog-2.41.2.tgz#6d3cf5c977320d1c77be518e848e011a9699b22d"
+  integrity sha512-1w6aT5P3xiI/HaTtqJrVj4Yp1/gxG8cGTeYgzlwr3iq8J11skwE4rLCHQucHfVueyBX49AaqWrhl+wI2ACqk4Q==
   dependencies:
-    "@apollographql/graphql-playground-react" "https://github.com/Joystream/graphql-playground/releases/download/query-templates%401.7.27/graphql-playground-react-v1.7.27.tgz"
+    "@apollographql/graphql-playground-react" "https://github.com/Joystream/graphql-playground/releases/download/joystream%401.7.28/graphql-playground-react-v1.7.28.tgz"
     "@types/app-root-path" "^1.2.4"
     "@types/bn.js" "^4.11.6"
     "@types/caller" "^1.0.0"
@@ -3172,9 +3172,9 @@
     shortid "^2.2.15"
     type-graphql "^0.17.5"
     typedi "^0.8.0"
-    typeorm "^0.2.32"
+    typeorm "0.2.37"
     typeorm-typedi-extensions "^0.4.1"
-    typescript "^3.9.7"
+    typescript "^4.4"
 
 "@jsdevtools/ono@7.1.3", "@jsdevtools/ono@^7.1.3":
   version "7.1.3"
@@ -29532,7 +29532,7 @@ typeorm-typedi-extensions@^0.4.1:
   resolved "https://registry.yarnpkg.com/typeorm-typedi-extensions/-/typeorm-typedi-extensions-0.4.1.tgz#e62e3c8f30021c9b8f258e068d38723dbd64de1d"
   integrity sha512-05hWktQ4zuXzTTUO3ao56yOezlvUuZhH2NRS//m0SOGCAJoVlfPTMHcmDaMSQy/lMfAwPWoIyn+sfK7ONzTdXQ==
 
-typeorm@0.2.34, typeorm@^0.2.25, typeorm@^0.2.32:
+typeorm@0.2.34, typeorm@0.2.37, typeorm@^0.2.25:
   version "0.2.34"
   resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.2.34.tgz#637b3cec2de54ee7f423012b813a2022c0aacc8b"
   integrity sha512-FZAeEGGdSGq7uTH3FWRQq67JjKu0mgANsSZ04j3kvDYNgy9KwBl/6RFgMVgiSgjf7Rqd7NrhC2KxVT7I80qf7w==