Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rotten-avocados-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/introspector": patch
---

Introspector now produces `@mutation` directive instead on `@exclude` when readonly

This file was deleted.

18 changes: 7 additions & 11 deletions packages/introspector/src/transforms/neo4j-graphql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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) => {
Expand All @@ -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));
Expand Down
8 changes: 5 additions & 3 deletions packages/introspector/tests/integration/graphql/nodes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down