Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Merge pull request #5892 from mjfwebb/7x-connect-always-creat…" #5933

Merged
merged 3 commits into from
Jan 9, 2025
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/thick-dogs-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": major
---

When performing a `connect` operation, new relationships are always created.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe("createConnectAndParams", () => {
WITH connectedNodes, parentNodes
UNWIND parentNodes as this
UNWIND connectedNodes as this0_node
MERGE (this)-[:\`SIMILAR\`]->(this0_node)
CREATE (this)-[:\`SIMILAR\`]->(this0_node)
}
}
WITH this, this0_node
Expand All @@ -153,7 +153,7 @@ describe("createConnectAndParams", () => {
WITH connectedNodes, parentNodes
UNWIND parentNodes as this0_node
UNWIND connectedNodes as this0_node_similarMovies0_node
MERGE (this0_node)-[:\`SIMILAR\`]->(this0_node_similarMovies0_node)
CREATE (this0_node)-[:\`SIMILAR\`]->(this0_node_similarMovies0_node)
}
}
WITH this, this0_node, this0_node_similarMovies0_node
Expand Down
33 changes: 1 addition & 32 deletions packages/graphql/src/translate/create-connect-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { asArray } from "../utils/utils";
import { checkAuthentication } from "./authorization/check-authentication";
import { createAuthorizationAfterAndParams } from "./authorization/compatibility/create-authorization-after-and-params";
import { createAuthorizationBeforeAndParams } from "./authorization/compatibility/create-authorization-before-and-params";
import { createRelationshipValidationString } from "./create-relationship-validation-string";
import { createSetRelationshipProperties } from "./create-set-relationship-properties";
import { filterMetaVariable } from "./subscriptions/filter-meta-variable";
import { createWhereNodePredicate } from "./where/create-where-predicate";
Expand All @@ -59,7 +58,6 @@ function createConnectAndParams({
callbackBucket,
labelOverride,
parentNode,
includeRelationshipValidation,
isFirstLevel = true,
source,
indexPrefix,
Expand All @@ -74,7 +72,6 @@ function createConnectAndParams({
refNodes: Node[];
labelOverride?: string;
parentNode: Node;
includeRelationshipValidation?: boolean;
isFirstLevel?: boolean;
source: "CREATE" | "UPDATE" | "CONNECT";
indexPrefix?: string;
Expand All @@ -95,7 +92,6 @@ function createConnectAndParams({
const inStr = relationField.direction === "IN" ? "<-" : "-";
const outStr = relationField.direction === "OUT" ? "->" : "-";
const relTypeStr = `[${relationField.properties ? relationshipName : ""}:${relationField.type}]`;
const isOverwriteNotAllowed = connect.overwrite === false;

const subquery: string[] = [];
const labels = relatedNode.getLabelString(context);
Expand Down Expand Up @@ -174,8 +170,7 @@ function createConnectAndParams({
subquery.push("\t\t\tWITH connectedNodes, parentNodes"); //
subquery.push(`\t\t\tUNWIND parentNodes as ${parentVar}`);
subquery.push(`\t\t\tUNWIND connectedNodes as ${nodeName}`);
const connectOperator = isOverwriteNotAllowed ? "CREATE" : "MERGE";
subquery.push(`\t\t\t${connectOperator} (${parentVar})${inStr}${relTypeStr}${outStr}(${nodeName})`);
subquery.push(`\t\t\tCREATE (${parentVar})${inStr}${relTypeStr}${outStr}(${nodeName})`);

if (relationField.properties) {
const relationship = context.relationships.find(
Expand Down Expand Up @@ -215,31 +210,6 @@ function createConnectAndParams({

const innerMetaStr = "";

if (includeRelationshipValidation || isOverwriteNotAllowed) {
const relValidationStrs: string[] = [];
const matrixItems = [
[parentNode, parentVar],
[relatedNode, nodeName],
] as [Node, string][];

matrixItems.forEach((mi) => {
const relValidationStr = createRelationshipValidationString({
node: mi[0],
context,
varName: mi[1],
...(isOverwriteNotAllowed && { relationshipFieldNotOverwritable: relationField.fieldName }),
});
if (relValidationStr) {
relValidationStrs.push(relValidationStr);
}
});

if (relValidationStrs.length) {
subquery.push(`\tWITH ${[...filterMetaVariable(withVars), nodeName].join(", ")}${innerMetaStr}`);
subquery.push(relValidationStrs.join("\n"));
}
}

subquery.push(`WITH ${[...filterMetaVariable(withVars), nodeName].join(", ")}${innerMetaStr}`);

if (connect.connect) {
Expand Down Expand Up @@ -275,7 +245,6 @@ function createConnectAndParams({
refNodes: [newRefNode],
parentNode: relatedNode,
labelOverride: relField.union ? newRefNode.name : "",
includeRelationshipValidation: true,
isFirstLevel: false,
source: "CONNECT",
});
Expand Down
23 changes: 0 additions & 23 deletions packages/graphql/src/translate/create-create-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
createAuthorizationAfterAndParamsField,
} from "./authorization/compatibility/create-authorization-after-and-params";
import createConnectAndParams from "./create-connect-and-params";
import { createRelationshipValidationString } from "./create-relationship-validation-string";
import { createSetRelationshipProperties } from "./create-set-relationship-properties";
import { assertNonAmbiguousUpdate } from "./utils/assert-non-ambiguous-update";
import { addCallbackAndSetParam } from "./utils/callback-utils";
Expand Down Expand Up @@ -57,7 +56,6 @@ function createCreateAndParams({
context,
callbackBucket,
withVars,
includeRelationshipValidation,
topLevelNodeVariable,
authorizationPrefix = [0],
}: {
Expand All @@ -67,7 +65,6 @@ function createCreateAndParams({
context: Neo4jGraphQLTranslationContext;
callbackBucket: CallbackBucket;
withVars: string[];
includeRelationshipValidation?: boolean;
topLevelNodeVariable?: string;
//used to build authorization variable in auth subqueries
authorizationPrefix?: number[];
Expand Down Expand Up @@ -144,7 +141,6 @@ function createCreateAndParams({
node: refNode,
varName: nodeName,
withVars: [...withVars, nodeName],
includeRelationshipValidation: false,
topLevelNodeVariable,
authorizationPrefix: [...authorizationPrefix, reducerIndex, createIndex, refNodeIndex],
});
Expand Down Expand Up @@ -184,16 +180,6 @@ function createCreateAndParams({
}
res.meta.authorizationPredicates.push(...authorizationPredicates);
}

const relationshipValidationStr = createRelationshipValidationString({
node: refNode,
context,
varName: nodeName,
});
if (relationshipValidationStr) {
res.creates.push(`WITH *`);
res.creates.push(relationshipValidationStr);
}
});
}

Expand Down Expand Up @@ -331,15 +317,6 @@ function createCreateAndParams({
params = { ...params, ...authParams };
}

if (includeRelationshipValidation) {
const str = createRelationshipValidationString({ node, context, varName });

if (str) {
creates.push(`WITH *`);
creates.push(str);
}
}

return { create: creates.join("\n"), params, authorizationPredicates, authorizationSubqueries };
}

Expand Down

This file was deleted.

31 changes: 1 addition & 30 deletions packages/graphql/src/translate/create-update-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import createConnectAndParams from "./create-connect-and-params";
import createCreateAndParams from "./create-create-and-params";
import createDeleteAndParams from "./create-delete-and-params";
import createDisconnectAndParams from "./create-disconnect-and-params";
import { createRelationshipValidationString } from "./create-relationship-validation-string";
import { createSetRelationshipProperties } from "./create-set-relationship-properties";
import { assertNonAmbiguousUpdate } from "./utils/assert-non-ambiguous-update";
import { addCallbackAndSetParam } from "./utils/callback-utils";
Expand Down Expand Up @@ -73,7 +72,6 @@ export default function createUpdateAndParams({
context,
callbackBucket,
parameterPrefix,
includeRelationshipValidation,
}: {
parentVar: string;
updateInput: any;
Expand All @@ -84,7 +82,6 @@ export default function createUpdateAndParams({
context: Neo4jGraphQLTranslationContext;
callbackBucket: CallbackBucket;
parameterPrefix: string;
includeRelationshipValidation?: boolean;
}): [string, any] {
let hasAppliedTimeStamps = false;

Expand Down Expand Up @@ -306,7 +303,6 @@ export default function createUpdateAndParams({
parameterPrefix: `${parameterPrefix}.${key}${
relationField.union ? `.${refNode.name}` : ""
}${relationField.typeMeta.array ? `[${index}]` : ``}.update.node`,
includeRelationshipValidation: true,
});
res.params = { ...res.params, ...updateAndParams[1] };
innerUpdate.push(updateAndParams[0]);
Expand Down Expand Up @@ -429,7 +425,6 @@ export default function createUpdateAndParams({
callbackBucket,
varName: nodeName,
withVars: [...withVars, nodeName],
includeRelationshipValidation: false,
...createNodeInput,
});
subquery.push(nestedCreate);
Expand Down Expand Up @@ -465,16 +460,6 @@ export default function createUpdateAndParams({
subquery.push(
...getAuthorizationStatements(authorizationPredicates, authorizationSubqueries)
);

const relationshipValidationStr = createRelationshipValidationString({
node: refNode,
context,
varName: nodeName,
});
if (relationshipValidationStr) {
subquery.push(`WITH ${[...withVars, nodeName].join(", ")}`);
subquery.push(relationshipValidationStr);
}
});
}

Expand Down Expand Up @@ -626,11 +611,6 @@ export default function createUpdateAndParams({

const preUpdatePredicates = authorizationBeforeStrs;

const preArrayMethodValidationStr = "";
const relationshipValidationStr = includeRelationshipValidation
? createRelationshipValidationString({ node, context, varName })
: "";

if (meta.preArrayMethodValidationStrs.length) {
const nullChecks = meta.preArrayMethodValidationStrs.map((validationStr) => `${validationStr[0]} IS NULL`);
const propertyNames = meta.preArrayMethodValidationStrs.map((validationStr) => validationStr[1]);
Expand Down Expand Up @@ -670,16 +650,7 @@ export default function createUpdateAndParams({

const statements = strs;

return [
[
preUpdatePredicatesStr,
preArrayMethodValidationStr,
...statements,
authorizationAfterStr,
...(relationshipValidationStr ? [withStr, relationshipValidationStr] : []),
].join("\n"),
params,
];
return [[preUpdatePredicatesStr, ...statements, authorizationAfterStr].join("\n"), params];
}

function validateNonNullProperty(res: Res, varName: string, field: BaseField) {
Expand Down
1 change: 0 additions & 1 deletion packages/graphql/src/translate/translate-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export default async function translateCreate({
context,
varName,
withVars,
includeRelationshipValidation: true,
topLevelNodeVariable: varName,
callbackBucket,
});
Expand Down
Loading
Loading