From ad90e45ad7f0d57c69639f323dc8d2d45a54222d Mon Sep 17 00:00:00 2001 From: Mbaye THIAM Date: Fri, 5 Apr 2024 18:10:17 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20possibility=20to=20overrides?= =?UTF-8?q?=20docker=20image=20with=20plugins=20and=20transforms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 38 +++++++- package.json | 3 +- packages/directive-no-auth/src/index.ts | 14 +-- packages/graphql-mesh/.meshrc.ts | 18 +++- packages/graphql-mesh/Dockerfile | 3 +- packages/graphql-mesh/local-pkg/.gitkeep | 0 .../local-pkg/directive-no-auth-1.0.0.tgz | Bin 2167 -> 2071 bytes packages/graphql-mesh/package-lock.json | 14 +++ packages/graphql-mesh/package.json | 8 +- .../graphql-mesh/scripts/build-local-image.sh | 11 +++ packages/graphql-mesh/serve.ts | 2 +- packages/graphql-mesh/tsconfig.json | 2 +- packages/graphql-mesh/types.d.ts | 16 +-- .../graphql-mesh/utils/additionalResolvers.ts | 6 ++ packages/graphql-mesh/utils/config/index.ts | 11 ++- .../utils/directive-typedefs/index.ts | 5 - .../inject-additional-transforms/.gitignore | 8 ++ .../inject-additional-transforms/package.json | 37 +++++++ .../scripts/prepare-package-json.js | 29 ++++++ .../inject-additional-transforms/src/index.ts | 92 ++++++++++++++++++ .../tsconfig-cjs.json | 7 ++ .../tsconfig-esm.json | 7 ++ .../tsconfig.json | 31 ++++++ 23 files changed, 314 insertions(+), 48 deletions(-) delete mode 100644 packages/graphql-mesh/local-pkg/.gitkeep create mode 100755 packages/graphql-mesh/scripts/build-local-image.sh create mode 100644 packages/graphql-mesh/utils/additionalResolvers.ts create mode 100644 packages/inject-additional-transforms/.gitignore create mode 100644 packages/inject-additional-transforms/package.json create mode 100644 packages/inject-additional-transforms/scripts/prepare-package-json.js create mode 100644 packages/inject-additional-transforms/src/index.ts create mode 100644 packages/inject-additional-transforms/tsconfig-cjs.json create mode 100644 packages/inject-additional-transforms/tsconfig-esm.json create mode 100644 packages/inject-additional-transforms/tsconfig.json diff --git a/package-lock.json b/package-lock.json index 4d6cb70..b1a753e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2382,6 +2382,10 @@ "version": "2.0.4", "license": "ISC" }, + "node_modules/inject-additional-transforms": { + "resolved": "packages/inject-additional-transforms", + "link": true + }, "node_modules/is-arrayish": { "version": "0.2.1", "license": "MIT" @@ -4104,6 +4108,7 @@ "directive-spl": "file:./local-pkg/directive-spl-1.0.0.tgz", "glob": "^10.3.10", "graphql": "^16.8.1", + "inject-additional-transforms": "file:./local-pkg/inject-additional-transforms-1.0.0.tgz", "patch-package": "^8.0.0", "sucrase": "^3.35.0" }, @@ -6441,7 +6446,6 @@ "packages/graphql-mesh/node_modules/directive-headers": { "version": "1.0.0", "resolved": "file:packages/graphql-mesh/local-pkg/directive-headers-1.0.0.tgz", - "integrity": "sha512-Gc8QFPyDLvQgAl1S4FMlz20JKRNbcQg28EM6x0zY1QPT84MuRj0l96DLU7jxvURI3StVAMiPATwSrMrp7WvtZA==", "peerDependencies": { "@graphql-mesh/cache-localforage": "*", "@graphql-mesh/types": "*", @@ -6453,7 +6457,6 @@ "packages/graphql-mesh/node_modules/directive-no-auth": { "version": "1.0.0", "resolved": "file:packages/graphql-mesh/local-pkg/directive-no-auth-1.0.0.tgz", - "integrity": "sha512-yfHfdqjWoDi4seUzZ5g1Fm124ujbNz1gppXOFtuxGs4UV2dd9tn6LaszgsUnq/GMNtyoMtuqZ0c/QHPAzwSFAQ==", "peerDependencies": { "@graphql-mesh/cache-localforage": "*", "@graphql-mesh/types": "*", @@ -6465,7 +6468,6 @@ "packages/graphql-mesh/node_modules/directive-spl": { "version": "1.0.0", "resolved": "file:packages/graphql-mesh/local-pkg/directive-spl-1.0.0.tgz", - "integrity": "sha512-vepLz1dzK+1Lb/RCAHIdFz+7ckxjtTW0tfh8xm+037tOWcJXklzmuxqBGk91LmOcFxFVllmeHHgGCID4qCwM8g==", "dependencies": { "antlr4ts": "^0.5.0-alpha.4" }, @@ -6910,6 +6912,19 @@ "node": ">=8" } }, + "packages/graphql-mesh/node_modules/inject-additional-transforms": { + "version": "1.0.0", + "resolved": "file:packages/graphql-mesh/local-pkg/inject-additional-transforms-1.0.0.tgz", + "dependencies": { + "@graphql-tools/delegate": "^10.0.0" + }, + "peerDependencies": { + "@graphql-mesh/types": "*", + "@graphql-mesh/utils": "*", + "@graphql-tools/utils": "*", + "graphql": "*" + } + }, "packages/graphql-mesh/node_modules/invariant": { "version": "2.2.4", "license": "MIT", @@ -8242,6 +8257,23 @@ "dependencies": { "zen-observable": "0.8.15" } + }, + "packages/inject-additional-transforms": { + "version": "1.0.0", + "dependencies": { + "@graphql-tools/delegate": "^10.0.0" + }, + "devDependencies": { + "@types/node": "^20.11.19", + "tslib": "^2.6.2", + "typescript": "^5.2.2" + }, + "peerDependencies": { + "@graphql-mesh/types": "*", + "@graphql-mesh/utils": "*", + "@graphql-tools/utils": "*", + "graphql": "*" + } } } } diff --git a/package.json b/package.json index a4d1c7d..568a019 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "clean:modules": "npm exec --workspaces -- npx rimraf node_modules && npx rimraf node_modules", "generate:mesh:lock": "cd packages/graphql-mesh && npm i --package-lock-only --workspaces=false", "postinstall": "npm run postinstall -w graphql-mesh && patch-package && npm run generate:mesh:lock", - "preinstall": "concurrently \"npm run pack -w directive-spl\" \"npm run pack -w directive-headers\" \"npm run pack -w directive-no-auth\"", + "build:local:packages": "concurrently \"npm run pack -w directive-spl\" \"npm run pack -w directive-headers\" \"npm run pack -w directive-no-auth\" \"npm run pack -w inject-additional-transforms\"", + "preinstall": "npm run build:local:packages", "start": "npm start -w graphql-mesh" }, "devDependencies": { diff --git a/packages/directive-no-auth/src/index.ts b/packages/directive-no-auth/src/index.ts index 2c9b28c..51d4808 100644 --- a/packages/directive-no-auth/src/index.ts +++ b/packages/directive-no-auth/src/index.ts @@ -11,10 +11,11 @@ export default class NoAuthDirectiveTransform implements MeshTransform { const originalResolver = fieldConfig.resolve != null ? fieldConfig.resolve : defaultFieldResolver - const resolver = async (next: any , _source: any, _args: any, context: any, info: any) => { + const resolver = async (next: any, _source: any, _args: any, context: any, info: any) => { const { directives } = info.fieldNodes[0] - const upperDirective = directives.find((directive: { name: { value: string } }) => directive.name.value === 'upper') - const noAuthDirective = directives.find((directive: { name: { value: string } }) => directive.name.value === 'noAuth') + const noAuthDirective = directives.find( + (directive: { name: { value: string } }) => directive.name.value === 'noAuth' + ) /** * In order to set headers for the request, we need override authorization headers @@ -25,13 +26,6 @@ export default class NoAuthDirectiveTransform implements MeshTransform { } let result = await next(context) - - if (upperDirective) { - if (typeof result === 'string') { - result = result.toUpperCase() - } - } - return result } diff --git a/packages/graphql-mesh/.meshrc.ts b/packages/graphql-mesh/.meshrc.ts index b4e6f72..21ada87 100644 --- a/packages/graphql-mesh/.meshrc.ts +++ b/packages/graphql-mesh/.meshrc.ts @@ -1,21 +1,29 @@ -import type { Config } from '@graphql-mesh/types/typings/config' +import { YamlConfig } from '@graphql-mesh/types' import ConfigFromSwaggers from './utils/ConfigFromSwaggers' const configFromSwaggers = new ConfigFromSwaggers() -const { defaultConfig, additionalResolvers, additionalTypeDefs, sources } = +const { defaultConfig, additionalTypeDefs, sources } = configFromSwaggers.getMeshConfigFromSwaggers() -const config = { +const config = { ...defaultConfig, transforms: [ { 'directive-spl': {} }, { 'directive-headers': {} }, { 'directive-no-auth': {} }, + { + 'inject-additional-transforms': { + additionalTransforms: defaultConfig.additionalTransforms || [] + } + }, ...(defaultConfig.transforms || []) ], sources: [...sources], - additionalTypeDefs: [...(defaultConfig.additionalTypeDefs || []), ...additionalTypeDefs], - additionalResolvers: [...(defaultConfig.additionalResolvers || []), additionalResolvers] + additionalTypeDefs: [defaultConfig.additionalTypeDefs || '', ...additionalTypeDefs], + additionalResolvers: [ + ...(defaultConfig.additionalResolvers || []), + './utils/additionalResolvers.ts' + ] } export default config diff --git a/packages/graphql-mesh/Dockerfile b/packages/graphql-mesh/Dockerfile index d1881b6..276d6f2 100644 --- a/packages/graphql-mesh/Dockerfile +++ b/packages/graphql-mesh/Dockerfile @@ -5,7 +5,6 @@ WORKDIR /build COPY package*.json ./ ADD local-pkg ./local-pkg ADD patches ./patches -ADD ../../patches ./patches RUN npm ci --omit=dev --omit=optional --omit=peer RUN rm -rf node_modules/uWebSockets.js/*.node RUN cd node_modules/typescript/lib && rm -rf cs de es fr it ja ko pl pt-br ru tr zh-cn zh-tw @@ -30,5 +29,7 @@ ENV TS_NODE_TRANSPILE_ONLY=true # swaggers sources VOLUME /app/sources VOLUME /app/config.yaml +VOLUME /app/transforms +VOLUME /app/plugins CMD [ "npm", "run", "serve" ] diff --git a/packages/graphql-mesh/local-pkg/.gitkeep b/packages/graphql-mesh/local-pkg/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/packages/graphql-mesh/local-pkg/directive-no-auth-1.0.0.tgz b/packages/graphql-mesh/local-pkg/directive-no-auth-1.0.0.tgz index 62673a03267a1909cb20927ce13aa2990bd05712..7667a245939a4a01a5cce39d88f317b6148ba765 100644 GIT binary patch literal 2071 zcmV+y2^@l|N8}BBw3Cfv_tB3oA|+&4$nIe$w!n@KX~s?aqIFb3!`x>xMr;| z8RL)EHQRcuX504R!2ztI+qS*mJ?z5Pe)rIBw+|2P1K6_LoulqPY}s2IXc^-^-LmaR z2-3D~DE|K@&Bz!A#%UOE!`VK&y2b&w#&{AY_yr{?ru&LV7> za0fSjl;Iw5nqiplI@6nK)7gjUvJHKp_(K*_+%PoJD7Z2nMy$&7lV)miLL%0Z z98w_i8H48pWqdXWDGqpegMX!d!X|{qaJLNrAhpsg;Dk1IHBB@=3z?OWH`Gs|FI{zH z-(3FkT+4Yd!?E9B@^4X|VxG|i8n&6cY{h=6*mpI*xxg>lyPWgXPg6{vhRN7EbAK6n zzg`}XhR+5UJ!niq9F0AaOv33d^#8l0p@;|w4X0t^N3Sp=(G8~1hX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!tBHkglq4mQ6+J3 z&^X|nSAvIm)Q^g;38tQRBVvk~2laYH2}h6+GfzOVx_86G&Qq=_8O-L7$Y3^KmErt! z4s|*K=^gy|BZSc$Xc9uEb(QGdFhL|^3`Rr6(1<9GT#DgIE`B?=}8syLGH8b zeXNf$i~UeO#~MZ>Js6r}HfsdLbAx*HajIoG9^<S(=BgT=@%E(+w#3RN!M$2gB)*_7Q26H7xJ=dGzx^Q;GY^ZLZ?KX7&BYmhfLz-4At9;Iy8W zS4vGj{kzl`ifjeE3S&=JJ`5X+6!d5JE`5br3ol zSO^Wf1ARI`s4Xr!1N{u4TU)=k5xTdn5kg(ZdX1c+{uZG#{RE*CeT2|RcMw9>2$8{r zcO7elf`OxBgs`}lYPe+R=;sKXb19_zHbNKrP%)hG-q3o7oI6`eeY6p}l-+j-y^}r8 zBztcWdMhu5;M7LWZ%WhDMrdm5C&-Cx$tNUI)1%C5r|`4Hw>0{bjS#VAq*EIWn?q^p zHA1gtCY~eoT>3Loah-5Y?Uv zOsjQoi`f_c3a9c!3R*fB=LL82(R>|<0T&^+z*h=DCgGVf%liZA&{?)gL@y6+HHRlN z6}*_VauA^{hlG^Sl;%K6m)ATZG0qSnUsbX6){GQ5%z1Nca*?4JA;N5gn4Jkp5P4Rp*5c>sA!Uvt z)`H2)ZwO103QJa4vci%Tmi#`kWCb7p`1v0{Y~RZJAM>!g^8a6l&2IJnce~$zp70~) z*Dsd7<6QUQCuXz!8_ksuKJydqum0ZCpGN_n<1l7RM&yya{MNGv9|#Gs8(NQi=h-WV tv%hq0J=yX3-}m|NuigJGvwHtq?f+{3SFLJQtJ { +export const getConfig = (): YamlConfig.Config => { logger.info('Loading config file') - let config: Config + let config: YamlConfig.Config // Load yaml config file try { const configPath = resolve('./config.yaml') @@ -39,7 +39,10 @@ export const getConfig = (): Config => { * @param config * @returns */ -export const getSourceOpenapiEnpoint = (source: string, config: Config): string | undefined => { +export const getSourceOpenapiEnpoint = ( + source: string, + config: YamlConfig.Config +): string | undefined => { const data = config.sources?.find((item) => item?.handler?.openapi?.source?.includes(source.split('/').pop()) ) diff --git a/packages/graphql-mesh/utils/directive-typedefs/index.ts b/packages/graphql-mesh/utils/directive-typedefs/index.ts index 6eeeef3..6c92b9a 100644 --- a/packages/graphql-mesh/utils/directive-typedefs/index.ts +++ b/packages/graphql-mesh/utils/directive-typedefs/index.ts @@ -9,11 +9,6 @@ export const directiveTypeDefs = /* GraphQL */ ` """ directive @noAuth on FIELD - """ - This directive is used to convert the result to uppercase. - """ - directive @upper on FIELD - type LinkItem { rel: String href: String diff --git a/packages/inject-additional-transforms/.gitignore b/packages/inject-additional-transforms/.gitignore new file mode 100644 index 0000000..7e47726 --- /dev/null +++ b/packages/inject-additional-transforms/.gitignore @@ -0,0 +1,8 @@ +# Logs +logs +*.log +npm-debug.log* + +node_modules +_build +.DS_Store diff --git a/packages/inject-additional-transforms/package.json b/packages/inject-additional-transforms/package.json new file mode 100644 index 0000000..35ec370 --- /dev/null +++ b/packages/inject-additional-transforms/package.json @@ -0,0 +1,37 @@ +{ + "name": "inject-additional-transforms", + "version": "1.0.0", + "type": "module", + "main": "_build/cjs/index.js", + "module": "_build/esm/index.js", + "types": "_build/esm/index.d.ts", + "exports": { + ".": { + "import": "./_build/esm/index.js", + "require": "./_build/cjs/index.js" + } + }, + "files": [ + "_build/**/*" + ], + "scripts": { + "build:cjs": "tsc --project tsconfig-cjs.json", + "build:esm": "tsc --project tsconfig-esm.json", + "build": "rm -rf _build && npm run build:esm && npm run build:cjs && node ./scripts/prepare-package-json", + "pack": "npm run build && npm pack --pack-destination ../graphql-mesh/local-pkg" + }, + "devDependencies": { + "@types/node": "^20.11.19", + "tslib": "^2.6.2", + "typescript": "^5.2.2" + }, + "peerDependencies": { + "@graphql-mesh/types": "*", + "@graphql-tools/utils": "*", + "@graphql-mesh/utils": "*", + "graphql": "*" + }, + "dependencies": { + "@graphql-tools/delegate": "^10.0.0" + } +} diff --git a/packages/inject-additional-transforms/scripts/prepare-package-json.js b/packages/inject-additional-transforms/scripts/prepare-package-json.js new file mode 100644 index 0000000..1fc7cc5 --- /dev/null +++ b/packages/inject-additional-transforms/scripts/prepare-package-json.js @@ -0,0 +1,29 @@ +import fs from 'fs' +import path from 'path' + +const buildDir = './_build' +function createModulePackageJson() { + fs.readdir(buildDir, function (err, dirs) { + if (err) { + throw err + } + dirs.forEach(function (dir) { + if (dir === 'cjs') { + var packageJsonFile = path.join(buildDir, dir, '/package.json') + if (!fs.existsSync(packageJsonFile)) { + fs.writeFile( + packageJsonFile, + new Uint8Array(Buffer.from('{"type": "commonjs"}')), + function (err) { + if (err) { + throw err + } + } + ) + } + } + }) + }) +} + +createModulePackageJson() diff --git a/packages/inject-additional-transforms/src/index.ts b/packages/inject-additional-transforms/src/index.ts new file mode 100644 index 0000000..54f4ee6 --- /dev/null +++ b/packages/inject-additional-transforms/src/index.ts @@ -0,0 +1,92 @@ +import { GraphQLSchema } from 'graphql' +import { MeshTransform } from '@graphql-mesh/types' +import { DelegationContext, SubschemaConfig, Transform } from '@graphql-tools/delegate' +import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils' +import { + applyRequestTransforms, + applyResultTransforms, + applySchemaTransforms +} from '@graphql-mesh/utils' +import * as pathModule from 'path' + +/** + * Import module from path + * @param path {string} + * @returns module {Promise} + */ +function importModule(path: string): Transform | null { + try { + return require(path) + } catch (error) { + console.error(`Can't import module located at ${path}`, error) + } + return null +} + +export default class InjectAdditionalTransforms implements MeshTransform { + noWrap = true + private baseDir: string + private transforms: Transform[] = [] + private additionalTransforms = [] + + constructor({ config, baseDir }: { config: any; baseDir: string }) { + this.baseDir = baseDir + this.additionalTransforms = Array.isArray(config) ? config : config.additionalTransforms ?? [] + this.additionalTransforms.forEach((transform) => { + const [path, config] = Object.entries(transform)?.[0] as [string, unknown] + try { + if (path) { + const absotutePath = pathModule.join(this.baseDir, path) + const module: any = importModule(absotutePath) + if (module) { + this.transforms.push(new module.default(config ?? {})) + } + } + } catch (error) { + console.error(`Could not instanciate additionnalTransformer located at ${path}`, error) + } + }) + } + + transformSchema( + originalWrappingSchema: GraphQLSchema, + subschemaConfig: SubschemaConfig, + transformedSchema?: GraphQLSchema + ) { + if (!transformedSchema) { + transformedSchema = originalWrappingSchema + } + return applySchemaTransforms( + originalWrappingSchema, + subschemaConfig, + transformedSchema, + this.transforms + ) + } + + transformRequest( + originalRequest: ExecutionRequest, + delegationContext: DelegationContext, + transformationContext: Record + ) { + return applyRequestTransforms( + originalRequest, + delegationContext, + transformationContext, + this.transforms + ) + } + + transformResult( + originalResult: ExecutionResult, + delegationContext: DelegationContext, + transformationContext: any + ) { + return applyResultTransforms( + originalResult, + delegationContext, + transformationContext, + this.transforms + ) + } +} diff --git a/packages/inject-additional-transforms/tsconfig-cjs.json b/packages/inject-additional-transforms/tsconfig-cjs.json new file mode 100644 index 0000000..b17b7ab --- /dev/null +++ b/packages/inject-additional-transforms/tsconfig-cjs.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "./_build/cjs/" + } +} diff --git a/packages/inject-additional-transforms/tsconfig-esm.json b/packages/inject-additional-transforms/tsconfig-esm.json new file mode 100644 index 0000000..963cb1f --- /dev/null +++ b/packages/inject-additional-transforms/tsconfig-esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "esnext", + "outDir": "./_build/esm/" + } +} diff --git a/packages/inject-additional-transforms/tsconfig.json b/packages/inject-additional-transforms/tsconfig.json new file mode 100644 index 0000000..6f4277d --- /dev/null +++ b/packages/inject-additional-transforms/tsconfig.json @@ -0,0 +1,31 @@ +{ + "module": "es2020", + "exclude": ["node_modules", "**/*.test.ts"], + "include": ["src/**/*"], + "compilerOptions": { + "allowJs": false, + "allowSyntheticDefaultImports": true, + "baseUrl": ".", + "declaration": true, + "experimentalDecorators": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "importHelpers": true, + "isolatedModules": false, + "lib": ["ESNext"], + "moduleResolution": "node", + "noEmit": false, + "noImplicitAny": true, + "noImplicitThis": true, + "noUnusedParameters": true, + "paths": { + "src/*": ["src/*"], + "typings": ["src/typings.ts"] + }, + "resolveJsonModule": true, + "strict": true, + "skipLibCheck": true, + "sourceMap": true, + "target": "es2020" + } +}