From 2047389979e4f15f5b29a7fbe2164dff58af8fca Mon Sep 17 00:00:00 2001 From: Thomas Wiss Date: Thu, 3 Aug 2023 16:11:07 +0200 Subject: [PATCH 1/4] fix: remove unnecessary readonly (#3735) --- packages/introspector/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/introspector/README.md b/packages/introspector/README.md index fd1e8aa14a..2ac1ac101e 100644 --- a/packages/introspector/README.md +++ b/packages/introspector/README.md @@ -105,7 +105,7 @@ const driver = neo4j.driver("neo4j://localhost:7687", neo4j.auth.basic("neo4j", const sessionFactory = () => driver.session({ defaultAccessMode: neo4j.session.READ }); async function main() { - const genericStruct = await toGenericStruct(sessionFactory, readonly); + const genericStruct = await toGenericStruct(sessionFactory); // Programmatically transform to what you need. } From fed3a96d9cb148c030c1b1e0891072d7e94caab9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 3 Aug 2023 21:44:04 +0000 Subject: [PATCH 2/4] chore(deps): update dependency eslint-config-prettier to v8.10.0 --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 63ebb7e48c..5e9f426a0e 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "concurrently": "8.2.0", "dotenv": "16.3.1", "eslint": "8.46.0", - "eslint-config-prettier": "8.9.0", + "eslint-config-prettier": "8.10.0", "eslint-formatter-summary": "1.1.0", "eslint-import-resolver-typescript": "3.5.5", "eslint-plugin-eslint-comments": "3.2.0", diff --git a/yarn.lock b/yarn.lock index 36bfedd6e4..45be86e23a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12867,14 +12867,14 @@ __metadata: languageName: node linkType: hard -"eslint-config-prettier@npm:8.9.0": - version: 8.9.0 - resolution: "eslint-config-prettier@npm:8.9.0" +"eslint-config-prettier@npm:8.10.0": + version: 8.10.0 + resolution: "eslint-config-prettier@npm:8.10.0" peerDependencies: eslint: ">=7.0.0" bin: eslint-config-prettier: bin/cli.js - checksum: a675d0dabd76b700ef2d062b5ec6a634e105a8e8c070f95281fd2ccb614527fac60b4c758132058c50f0521fd19313f1f5be45ce9ebf081f2e5f77ae6eb7d8db + checksum: 153266badd477e49b0759816246b2132f1dbdb6c7f313ca60a9af5822fd1071c2bc5684a3720d78b725452bbac04bb130878b2513aea5e72b1b792de5a69fec8 languageName: node linkType: hard @@ -19388,7 +19388,7 @@ __metadata: concurrently: 8.2.0 dotenv: 16.3.1 eslint: 8.46.0 - eslint-config-prettier: 8.9.0 + eslint-config-prettier: 8.10.0 eslint-formatter-summary: 1.1.0 eslint-import-resolver-typescript: 3.5.5 eslint-plugin-eslint-comments: 3.2.0 From 623c8f3a6281e9535f74725c2546901bc05e178e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 4 Aug 2023 00:37:29 +0000 Subject: [PATCH 3/4] chore(deps): update dependency jest-extended to v4.0.1 --- packages/graphql/package.json | 3 +- yarn.lock | 62 ++++++----------------------------- 2 files changed, 11 insertions(+), 54 deletions(-) diff --git a/packages/graphql/package.json b/packages/graphql/package.json index 170a3ba51f..d91b4b4bab 100644 --- a/packages/graphql/package.json +++ b/packages/graphql/package.json @@ -68,8 +68,7 @@ "graphql-ws": "5.14.0", "is-uuid": "1.0.2", "jest": "29.6.2", - "jest-extended": "4.0.0", - "jwks-rsa": "^3.0.1", + "jest-extended": "4.0.1", "koa": "2.14.2", "koa-jwt": "4.0.4", "koa-router": "12.0.0", diff --git a/yarn.lock b/yarn.lock index 45be86e23a..9f9ae91782 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3611,9 +3611,8 @@ __metadata: graphql-ws: 5.14.0 is-uuid: 1.0.2 jest: 29.6.2 - jest-extended: 4.0.0 + jest-extended: 4.0.1 jose: ^4.13.1 - jwks-rsa: ^3.0.1 koa: 2.14.2 koa-jwt: 4.0.4 koa-router: 12.0.0 @@ -7191,7 +7190,7 @@ __metadata: languageName: node linkType: hard -"@types/express@npm:*, @types/express@npm:^4.17.13, @types/express@npm:^4.17.14": +"@types/express@npm:*, @types/express@npm:^4.17.13": version: 4.17.17 resolution: "@types/express@npm:4.17.17" dependencies: @@ -7334,7 +7333,7 @@ __metadata: languageName: node linkType: hard -"@types/jsonwebtoken@npm:9.0.2, @types/jsonwebtoken@npm:^9.0.0": +"@types/jsonwebtoken@npm:9.0.2": version: 9.0.2 resolution: "@types/jsonwebtoken@npm:9.0.2" dependencies: @@ -16713,9 +16712,9 @@ __metadata: languageName: node linkType: hard -"jest-extended@npm:4.0.0": - version: 4.0.0 - resolution: "jest-extended@npm:4.0.0" +"jest-extended@npm:4.0.1": + version: 4.0.1 + resolution: "jest-extended@npm:4.0.1" dependencies: jest-diff: ^29.0.0 jest-get-type: ^29.0.0 @@ -16724,7 +16723,7 @@ __metadata: peerDependenciesMeta: jest: optional: true - checksum: 2fd77a4fcda131a93c6f4a60a955c81fa332abad73d68f58d82fd9548672aa2c4f4ff64d4b44ae561caca3d592707eb0cc237d5da3138d8c568f40a1d8f81751 + checksum: a5d6a9153c7b7fe48602bb3381f46bbbbb034bc2722497d0fde6b0eac81b8fbda1e69fb59ca72ec545fea7959e065a96500620a1cf0aba77a719455ff5f93da8 languageName: node linkType: hard @@ -17036,7 +17035,7 @@ __metadata: languageName: node linkType: hard -"jose@npm:^4.10.4, jose@npm:^4.13.1": +"jose@npm:^4.13.1": version: 4.14.4 resolution: "jose@npm:4.14.4" checksum: 2d820a91a8fd97c05d8bc8eedc373b944a0cd7f5fe41063086da233d0473c73fb523912a9f026ea870782bd221f4a515f441a2d3af4de48c6f2c76dac5082377 @@ -17336,20 +17335,6 @@ __metadata: languageName: node linkType: hard -"jwks-rsa@npm:^3.0.1": - version: 3.0.1 - resolution: "jwks-rsa@npm:3.0.1" - dependencies: - "@types/express": ^4.17.14 - "@types/jsonwebtoken": ^9.0.0 - debug: ^4.3.4 - jose: ^4.10.4 - limiter: ^1.1.5 - lru-memoizer: ^2.1.4 - checksum: 943bf7792d23761c1e9d1f4d1b67e967ea5b38968583a87a7c862f6df0b9c4a5a34a97fa82efcd375776476664b2916df757aafab69013ab05d3e1fa9fbc1363 - languageName: node - linkType: hard - "jws@npm:^3.2.2": version: 3.2.2 resolution: "jws@npm:3.2.2" @@ -17689,13 +17674,6 @@ __metadata: languageName: node linkType: hard -"limiter@npm:^1.1.5": - version: 1.1.5 - resolution: "limiter@npm:1.1.5" - checksum: 2d51d3a8bef131aada820b76530f8223380a0079aa0fffdfd3ec47ac2f65763225cb4c62a2f22347f4898c5eeb248edfec991c4a4f5b608dfca0aaa37ac48071 - languageName: node - linkType: hard - "lines-and-columns@npm:^1.1.6": version: 1.2.4 resolution: "lines-and-columns@npm:1.2.4" @@ -18202,26 +18180,6 @@ __metadata: languageName: node linkType: hard -"lru-cache@npm:~4.0.0": - version: 4.0.2 - resolution: "lru-cache@npm:4.0.2" - dependencies: - pseudomap: ^1.0.1 - yallist: ^2.0.0 - checksum: 1f615ef23f3316c0935533df2a14f66050502ffd0841726ea3dbaceac09a1bb80cd0c1f8799a881c4d13fe2cdebbd7919668a54eae4ec97caf66141e56b5c3bb - languageName: node - linkType: hard - -"lru-memoizer@npm:^2.1.4": - version: 2.2.0 - resolution: "lru-memoizer@npm:2.2.0" - dependencies: - lodash.clonedeep: ^4.5.0 - lru-cache: ~4.0.0 - checksum: 555f672b3ff6b4fec63792ca1cda7b585fc54f5e8f0b73166e6d513cc4103032cd69f5d40b32700807c9ca94671728e9108a3fe0803fc3f1b08716946c5a6098 - languageName: node - linkType: hard - "macos-release@npm:^2.5.0": version: 2.5.1 resolution: "macos-release@npm:2.5.1" @@ -21488,7 +21446,7 @@ __metadata: languageName: node linkType: hard -"pseudomap@npm:^1.0.1, pseudomap@npm:^1.0.2": +"pseudomap@npm:^1.0.2": version: 1.0.2 resolution: "pseudomap@npm:1.0.2" checksum: 856c0aae0ff2ad60881168334448e898ad7a0e45fe7386d114b150084254c01e200c957cf378378025df4e052c7890c5bd933939b0e0d2ecfcc1dc2f0b2991f5 @@ -26373,7 +26331,7 @@ __metadata: languageName: node linkType: hard -"yallist@npm:^2.0.0, yallist@npm:^2.1.2": +"yallist@npm:^2.1.2": version: 2.1.2 resolution: "yallist@npm:2.1.2" checksum: 9ba99409209f485b6fcb970330908a6d41fa1c933f75e08250316cce19383179a6b70a7e0721b89672ebb6199cc377bf3e432f55100da6a7d6e11902b0a642cb From e879a1792cf009759fa94a5964ac7b3b3f9b207f Mon Sep 17 00:00:00 2001 From: Darrell Warde Date: Fri, 4 Aug 2023 15:29:37 +0100 Subject: [PATCH 4/4] Introspector to produce `@mutation` instead of `@exclude` --- .changeset/rotten-avocados-knock.md | 5 ++ .../neo4j-graphql/directives/Exclude.ts | 47 ------------------- .../src/transforms/neo4j-graphql/graphql.ts | 18 +++---- .../tests/integration/graphql/nodes.test.ts | 8 ++-- 4 files changed, 17 insertions(+), 61 deletions(-) create mode 100644 .changeset/rotten-avocados-knock.md delete mode 100644 packages/introspector/src/transforms/neo4j-graphql/directives/Exclude.ts diff --git a/.changeset/rotten-avocados-knock.md b/.changeset/rotten-avocados-knock.md new file mode 100644 index 0000000000..11f797811a --- /dev/null +++ b/.changeset/rotten-avocados-knock.md @@ -0,0 +1,5 @@ +--- +"@neo4j/introspector": patch +--- + +Introspector now produces `@mutation` directive instead on `@exclude` when readonly diff --git a/packages/introspector/src/transforms/neo4j-graphql/directives/Exclude.ts b/packages/introspector/src/transforms/neo4j-graphql/directives/Exclude.ts deleted file mode 100644 index 0dc7680273..0000000000 --- a/packages/introspector/src/transforms/neo4j-graphql/directives/Exclude.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) "Neo4j" - * Neo4j Sweden AB [http://neo4j.com] - * - * This file is part of Neo4j. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import type { Directive, ExcludeOperation } from "../types"; - -export class ExcludeDirective implements Directive { - operations: ExcludeOperation[] = []; - addOperation(operation: ExcludeOperation): void { - if (!this.operations.includes(operation)) { - this.operations.push(operation); - } - } - - removeOperation(operation: ExcludeOperation): void { - this.operations = this.operations.filter((o) => o !== operation); - } - - toString(): string { - const parts: string[] = []; - if (this.operations.length) { - parts.push("("); - parts.push("operations: "); - parts.push("["); - parts.push(this.operations.join(", ")); - parts.push("]"); - parts.push(")"); - } - - return `@exclude${parts.join("")}`; - } -} diff --git a/packages/introspector/src/transforms/neo4j-graphql/graphql.ts b/packages/introspector/src/transforms/neo4j-graphql/graphql.ts index d0af08a9b8..7b720700ce 100644 --- a/packages/introspector/src/transforms/neo4j-graphql/graphql.ts +++ b/packages/introspector/src/transforms/neo4j-graphql/graphql.ts @@ -25,7 +25,6 @@ import { GraphQLNode } from "./GraphQLNode"; import generateRelationshipPropsName from "./utils/generate-relationship-props-name"; import { RelationshipPropertiesDirective } from "./directives/RelationshipProperties"; import createRelationshipFields from "./utils/create-relationship-fields"; -import { ExcludeDirective } from "./directives/Exclude"; import generateGraphQLSafeName from "./utils/generate-graphql-safe-name"; import nodeKey from "../../utils/node-key"; @@ -35,15 +34,19 @@ type GraphQLNodeMap = { export default function graphqlFormatter(neo4jStruct: Neo4jStruct, readonly = false): string { const { nodes, relationships } = neo4jStruct; - const bareNodes = transformNodes(nodes, readonly); + const bareNodes = transformNodes(nodes); const withRelationships = hydrateWithRelationships(bareNodes, relationships); const sorted = Object.keys(withRelationships).sort((a, b) => { return withRelationships[a].typeName > withRelationships[b].typeName ? 1 : -1; }); - return sorted.map((typeName) => withRelationships[typeName].toString()).join("\n\n"); + const sortedWithRelationships = sorted.map((typeName) => withRelationships[typeName].toString()); + if (readonly) { + sortedWithRelationships.push("extend schema @mutation(operations: [])"); + } + return sortedWithRelationships.join("\n\n"); } -function transformNodes(nodes: NodeMap, readonly: boolean): GraphQLNodeMap { +function transformNodes(nodes: NodeMap): GraphQLNodeMap { const out = {}; const takenTypeNames: string[] = []; Object.keys(nodes).forEach((nodeType) => { @@ -68,13 +71,6 @@ function transformNodes(nodes: NodeMap, readonly: boolean): GraphQLNodeMap { if (nodeDirective.toString().length) { node.addDirective(nodeDirective); } - if (readonly) { - const excludeDirective = new ExcludeDirective(); - excludeDirective.addOperation("CREATE"); - excludeDirective.addOperation("DELETE"); - excludeDirective.addOperation("UPDATE"); - node.addDirective(excludeDirective); - } const fields = createNodeFields(neo4jNode.properties, node.typeName); fields.forEach((f) => node.addField(f)); diff --git a/packages/introspector/tests/integration/graphql/nodes.test.ts b/packages/introspector/tests/integration/graphql/nodes.test.ts index 3a75d9bb50..db748bf817 100644 --- a/packages/introspector/tests/integration/graphql/nodes.test.ts +++ b/packages/introspector/tests/integration/graphql/nodes.test.ts @@ -376,13 +376,15 @@ describe("GraphQL - Infer Schema nodes basic tests", () => { const typeDefs = await toGraphQLTypeDefs(sessionFactory(bm), true); expect(typeDefs).toMatchInlineSnapshot(` - "type TestLabel @exclude(operations: [CREATE, DELETE, UPDATE]) { + "type TestLabel { strProp: String! } - type TestLabel2 @node(labels: [\\"TestLabel2\\", \\"TestLabel3\\"]) @exclude(operations: [CREATE, DELETE, UPDATE]) { + type TestLabel2 @node(labels: [\\"TestLabel2\\", \\"TestLabel3\\"]) { singleProp: BigInt! - }" + } + + extend schema @mutation(operations: [])" `); const neoSchema = new Neo4jGraphQL({ typeDefs, driver });