diff --git a/.gitignore b/.gitignore index c042c0813d..910ba88d66 100644 --- a/.gitignore +++ b/.gitignore @@ -89,3 +89,5 @@ packages/package-tests/**/package-lock.json !.yarn/sdks !.yarn/versions .pnp.* + +tsconfig.tsbuildinfo \ No newline at end of file diff --git a/packages/graphql/src/environment.ts b/packages/graphql/src/environment.ts index d8794aea79..4ce0a636b3 100644 --- a/packages/graphql/src/environment.ts +++ b/packages/graphql/src/environment.ts @@ -17,9 +17,11 @@ * limitations under the License. */ +import * as pack from "../package.json"; + const environment = { - NPM_PACKAGE_VERSION: process.env.NPM_PACKAGE_VERSION as string, - NPM_PACKAGE_NAME: process.env.NPM_PACKAGE_NAME as string, + NPM_PACKAGE_VERSION: pack.version, + NPM_PACKAGE_NAME: pack.name, }; export default environment; diff --git a/packages/graphql/src/tsconfig.build.json b/packages/graphql/src/tsconfig.build.json index fd1ffc9e58..77dcf7d6c7 100644 --- a/packages/graphql/src/tsconfig.build.json +++ b/packages/graphql/src/tsconfig.build.json @@ -3,5 +3,8 @@ "compilerOptions": { "outDir": "../dist" }, - "exclude": ["**/*.test.ts"] + "exclude": ["**/*.test.ts"], + "references": [ + { "path": "../" } // for package.json import + ] } diff --git a/packages/graphql/src/tsconfig.json b/packages/graphql/src/tsconfig.json index cefd165b28..da081ea0e6 100644 --- a/packages/graphql/src/tsconfig.json +++ b/packages/graphql/src/tsconfig.json @@ -2,5 +2,8 @@ "extends": "../../../tsconfig.base.json", "compilerOptions": { "outDir": "../dist" - } + }, + "references": [ + { "path": "../" } // for package.json import + ] } diff --git a/packages/graphql/src/utils/execute.test.ts b/packages/graphql/src/utils/execute.test.ts index 64d64e9660..66b2ac3cff 100644 --- a/packages/graphql/src/utils/execute.test.ts +++ b/packages/graphql/src/utils/execute.test.ts @@ -21,6 +21,7 @@ import { Driver } from "neo4j-driver"; import { Neo4jGraphQL } from "../classes"; import { Context } from "../types"; import execute from "./execute"; +import environment from "../environment"; describe("execute", () => { test("should execute return records.toObject", async () => { @@ -66,6 +67,8 @@ describe("execute", () => { close: () => true, }; }, + // @ts-ignore + _config: {}, }; // @ts-ignore @@ -82,6 +85,12 @@ describe("execute", () => { }); expect(result).toEqual([{ title }]); + // @ts-ignore + expect(driver._userAgent).toEqual(`${environment.NPM_PACKAGE_NAME}/${environment.NPM_PACKAGE_VERSION}`); + // @ts-ignore + expect(driver._config.userAgent).toEqual( + `${environment.NPM_PACKAGE_NAME}/${environment.NPM_PACKAGE_VERSION}` + ); }) ); }); diff --git a/packages/graphql/src/utils/execute.ts b/packages/graphql/src/utils/execute.ts index f69c2eba63..bde33eeb6c 100644 --- a/packages/graphql/src/utils/execute.ts +++ b/packages/graphql/src/utils/execute.ts @@ -52,8 +52,16 @@ async function execute(input: { } } - // @ts-ignore: Required to set connection user agent - input.context.driver._userAgent = `${environment.NPM_PACKAGE_VERSION}/${environment.NPM_PACKAGE_NAME}`; // eslint-disable-line no-underscore-dangle + const userAgent = `${environment.NPM_PACKAGE_NAME}/${environment.NPM_PACKAGE_VERSION}`; + + // @ts-ignore: below + if (input.context.driver?._config) { + // @ts-ignore: (driver >= 4.3) + input.context.driver._config.userAgent = userAgent; // eslint-disable-line no-underscore-dangle + } + + // @ts-ignore: (driver <= 4.2) + input.context.driver._userAgent = userAgent; // eslint-disable-line no-underscore-dangle const session = input.context.driver.session(sessionParams); @@ -67,7 +75,6 @@ async function execute(input: { } try { - // input.context.neoSchema.debug(`Cypher: ${input.cypher}\nParams: ${JSON.stringify(input.params, null, 2)}`); debug( "%s", `About to execute Cypher:\nCypher:\n${input.cypher}\nParams:\n${JSON.stringify(input.params, null, 2)}` diff --git a/packages/graphql/tests/tsconfig.json b/packages/graphql/tests/tsconfig.json index 7f6af9d66e..9f31a4ae81 100644 --- a/packages/graphql/tests/tsconfig.json +++ b/packages/graphql/tests/tsconfig.json @@ -1,7 +1,8 @@ { "extends": "../../../tsconfig.base.json", "compilerOptions": { - "types": ["node", "jest"] + "types": ["node", "jest"], + "resolveJsonModule": true }, "references": [{ "path": "../src/tsconfig.json" }] } diff --git a/packages/graphql/tsconfig.json b/packages/graphql/tsconfig.json new file mode 100644 index 0000000000..8ba1689616 --- /dev/null +++ b/packages/graphql/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "rootDir": ".", + "outDir": ".", + "composite": true + }, + "files": ["package.json"] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index 3416d45b57..423b79e32f 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -10,6 +10,7 @@ "strict": true, "target": "es6", // TODO Refactor so that noImplicitAny is no longer needed - "noImplicitAny": false + "noImplicitAny": false, + "resolveJsonModule": true } }