Skip to content

Commit 85b3c06

Browse files
darrellwardeThomas Wissrenovate[bot]
authored
Introspector to produce @mutation instead of @exclude (#3743)
* fix: remove unnecessary readonly (#3735) * chore(deps): update dependency eslint-config-prettier to v8.10.0 * chore(deps): update dependency jest-extended to v4.0.1 * Introspector to produce `@mutation` instead of `@exclude` --------- Co-authored-by: Thomas Wiss <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent 37ced64 commit 85b3c06

File tree

4 files changed

+17
-61
lines changed

4 files changed

+17
-61
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@neo4j/introspector": patch
3+
---
4+
5+
Introspector now produces `@mutation` directive instead on `@exclude` when readonly

packages/introspector/src/transforms/neo4j-graphql/directives/Exclude.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

packages/introspector/src/transforms/neo4j-graphql/graphql.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { GraphQLNode } from "./GraphQLNode";
2525
import generateRelationshipPropsName from "./utils/generate-relationship-props-name";
2626
import { RelationshipPropertiesDirective } from "./directives/RelationshipProperties";
2727
import createRelationshipFields from "./utils/create-relationship-fields";
28-
import { ExcludeDirective } from "./directives/Exclude";
2928
import generateGraphQLSafeName from "./utils/generate-graphql-safe-name";
3029
import nodeKey from "../../utils/node-key";
3130

@@ -35,15 +34,19 @@ type GraphQLNodeMap = {
3534

3635
export default function graphqlFormatter(neo4jStruct: Neo4jStruct, readonly = false): string {
3736
const { nodes, relationships } = neo4jStruct;
38-
const bareNodes = transformNodes(nodes, readonly);
37+
const bareNodes = transformNodes(nodes);
3938
const withRelationships = hydrateWithRelationships(bareNodes, relationships);
4039
const sorted = Object.keys(withRelationships).sort((a, b) => {
4140
return withRelationships[a].typeName > withRelationships[b].typeName ? 1 : -1;
4241
});
43-
return sorted.map((typeName) => withRelationships[typeName].toString()).join("\n\n");
42+
const sortedWithRelationships = sorted.map((typeName) => withRelationships[typeName].toString());
43+
if (readonly) {
44+
sortedWithRelationships.push("extend schema @mutation(operations: [])");
45+
}
46+
return sortedWithRelationships.join("\n\n");
4447
}
4548

46-
function transformNodes(nodes: NodeMap, readonly: boolean): GraphQLNodeMap {
49+
function transformNodes(nodes: NodeMap): GraphQLNodeMap {
4750
const out = {};
4851
const takenTypeNames: string[] = [];
4952
Object.keys(nodes).forEach((nodeType) => {
@@ -68,13 +71,6 @@ function transformNodes(nodes: NodeMap, readonly: boolean): GraphQLNodeMap {
6871
if (nodeDirective.toString().length) {
6972
node.addDirective(nodeDirective);
7073
}
71-
if (readonly) {
72-
const excludeDirective = new ExcludeDirective();
73-
excludeDirective.addOperation("CREATE");
74-
excludeDirective.addOperation("DELETE");
75-
excludeDirective.addOperation("UPDATE");
76-
node.addDirective(excludeDirective);
77-
}
7874

7975
const fields = createNodeFields(neo4jNode.properties, node.typeName);
8076
fields.forEach((f) => node.addField(f));

packages/introspector/tests/integration/graphql/nodes.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,15 @@ describe("GraphQL - Infer Schema nodes basic tests", () => {
376376
const typeDefs = await toGraphQLTypeDefs(sessionFactory(bm), true);
377377

378378
expect(typeDefs).toMatchInlineSnapshot(`
379-
"type TestLabel @exclude(operations: [CREATE, DELETE, UPDATE]) {
379+
"type TestLabel {
380380
strProp: String!
381381
}
382382
383-
type TestLabel2 @node(labels: [\\"TestLabel2\\", \\"TestLabel3\\"]) @exclude(operations: [CREATE, DELETE, UPDATE]) {
383+
type TestLabel2 @node(labels: [\\"TestLabel2\\", \\"TestLabel3\\"]) {
384384
singleProp: BigInt!
385-
}"
385+
}
386+
387+
extend schema @mutation(operations: [])"
386388
`);
387389

388390
const neoSchema = new Neo4jGraphQL({ typeDefs, driver });

0 commit comments

Comments
 (0)