Skip to content

Remove deprecated import with from queries #6405

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
16 changes: 6 additions & 10 deletions packages/graphql/src/translate/create-connect-and-params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,30 +127,26 @@ describe("createConnectAndParams", () => {

expect(result[0]).toMatchInlineSnapshot(`
"WITH *
CALL {
CALL(*) {
WITH this
OPTIONAL MATCH (this0_node:Movie)
WHERE this0_node.title = $this0_node_param0
CALL {
WITH *
CALL(*) {
WITH collect(this0_node) as connectedNodes, collect(this) as parentNodes
CALL {
WITH connectedNodes, parentNodes
CALL(connectedNodes, parentNodes) {
UNWIND parentNodes as this
UNWIND connectedNodes as this0_node
CREATE (this)-[:\`SIMILAR\`]->(this0_node)
}
}
WITH this, this0_node
CALL {
CALL(*) {
WITH this, this0_node
OPTIONAL MATCH (this0_node_similarMovies0_node:Movie)
WHERE this0_node_similarMovies0_node.title = $this0_node_similarMovies0_node_param0
CALL {
WITH *
CALL(*) {
WITH this, collect(this0_node_similarMovies0_node) as connectedNodes, collect(this0_node) as parentNodes
CALL {
WITH connectedNodes, parentNodes
CALL(connectedNodes, parentNodes) {
UNWIND parentNodes as this0_node
UNWIND connectedNodes as this0_node_similarMovies0_node
CREATE (this0_node)-[:\`SIMILAR\`]->(this0_node_similarMovies0_node)
Expand Down
10 changes: 4 additions & 6 deletions packages/graphql/src/translate/create-connect-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ function createConnectAndParams({
Replace with subclauses https://neo4j.com/developer/kb/conditional-cypher-execution/
https://neo4j.slack.com/archives/C02PUHA7C/p1603458561099100
*/
subquery.push("\tCALL {");
subquery.push("\t\tWITH *");
subquery.push("\tCALL(*) {");
const withVarsInner = [
...withVars.filter((v) => v !== parentVar),
`collect(${nodeName}) as connectedNodes`,
Expand All @@ -170,8 +169,7 @@ function createConnectAndParams({

subquery.push(`\t\tWITH ${filterMetaVariable(withVarsInner).join(", ")}`);

subquery.push("\t\tCALL {"); //
subquery.push("\t\t\tWITH connectedNodes, parentNodes"); //
subquery.push("\t\tCALL(connectedNodes, parentNodes) {");
subquery.push(`\t\t\tUNWIND parentNodes as ${parentVar}`);
subquery.push(`\t\t\tUNWIND connectedNodes as ${nodeName}`);
subquery.push(`\t\t\tCREATE (${parentVar})${inStr}${relTypeStr}${outStr}(${nodeName})`);
Expand Down Expand Up @@ -326,7 +324,7 @@ function createConnectAndParams({
}
});
if (subqueries.length > 0) {
inner.push(subqueries.join("\n}\nCALL {\n\t"));
inner.push(subqueries.join("\n}\nCALL(*) {\n\t"));
}
} else {
const targetNode = refNodes[0];
Expand All @@ -342,7 +340,7 @@ function createConnectAndParams({
}

if (inner.length > 0) {
res.connects.push("CALL {");
res.connects.push("CALL(*) {");
res.connects.push(...inner);
res.connects.push("}");
}
Expand Down
8 changes: 2 additions & 6 deletions packages/graphql/src/translate/create-delete-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ function createDeleteAndParams({
const labels = refNode.getLabelString(context);

innerStrs.push("WITH *");
innerStrs.push("CALL {");
if (withVars) {
innerStrs.push(`WITH *`);
}
innerStrs.push("CALL(*) {");
innerStrs.push(
`OPTIONAL MATCH (${parentVar})${inStr}${relTypeStr}${outStr}(${variableName}${labels})`
);
Expand Down Expand Up @@ -211,8 +208,7 @@ function createDeleteAndParams({

const statements = [
`WITH ${relationshipVariable}, collect(DISTINCT ${variableName}) AS ${nodeToDelete}`,
"CALL {",
`\tWITH ${nodeToDelete}`,
`CALL(${nodeToDelete}) {`,
`\tUNWIND ${nodeToDelete} AS x`,
`\tDETACH DELETE x`,
`}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,22 @@ describe("createDisconnectAndParams", () => {

expect(result[0]).toMatchInlineSnapshot(`
"WITH this
CALL {
CALL(*) {
WITH this
OPTIONAL MATCH (this)-[this0_rel:\`SIMILAR\`]->(this0:Movie)
WHERE this0.title = $this0_where_Movie_this0param0
CALL {
WITH this0, this0_rel, this
WITH collect(this0) as this0, this0_rel, this
UNWIND this0 as x
CALL (this0, this0_rel, this) {
WITH collect(this0) as this0_x, this0_rel, this
UNWIND this0_x as x
DELETE this0_rel
}
CALL {
CALL(*) {
WITH this, this0
OPTIONAL MATCH (this0)-[this0_similarMovies0_rel:\`SIMILAR\`]->(this0_similarMovies0:Movie)
WHERE this0_similarMovies0.title = $this0_disconnect_similarMovies0_where_Movie_this0_similarMovies0param0
CALL {
WITH this0_similarMovies0, this0_similarMovies0_rel, this0
WITH collect(this0_similarMovies0) as this0_similarMovies0, this0_similarMovies0_rel, this0
UNWIND this0_similarMovies0 as x
CALL (this0_similarMovies0, this0_similarMovies0_rel, this0) {
WITH collect(this0_similarMovies0) as this0_similarMovies0_x, this0_similarMovies0_rel, this0
UNWIND this0_similarMovies0_x as x
DELETE this0_similarMovies0_rel
}
RETURN count(*) AS disconnect_this0_similarMovies_Movie
Expand Down
11 changes: 5 additions & 6 deletions packages/graphql/src/translate/create-disconnect-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,10 @@ function createDisconnectAndParams({
}
}

subquery.push("CALL {");
subquery.push(`CALL (${variableName}, ${relVarName}, ${parentVar}) {`);
// Trick to avoid execution on null values
subquery.push(`\tWITH ${variableName}, ${relVarName}, ${parentVar}`);
subquery.push(`\tWITH collect(${variableName}) as ${variableName}, ${relVarName}, ${parentVar}`);
subquery.push(`\tUNWIND ${variableName} as x`);
subquery.push(`\tWITH collect(${variableName}) as ${variableName}_x, ${relVarName}, ${parentVar}`);
subquery.push(`\tUNWIND ${variableName}_x as x`);

subquery.push(`\tDELETE ${relVarName}`);

Expand Down Expand Up @@ -266,7 +265,7 @@ function createDisconnectAndParams({
}
});
if (subqueries.length > 0) {
inner.push(subqueries.join("\n}\nCALL {\n\t"));
inner.push(subqueries.join("\n}\nCALL(*) {\n\t"));
}
} else {
const subquery = createSubqueryContents(refNodes[0] as Node, disconnect, index);
Expand All @@ -275,7 +274,7 @@ function createDisconnectAndParams({
}

if (inner.length > 0) {
res.disconnects.push("CALL {");
res.disconnects.push("CALL(*) {");
res.disconnects.push(...inner);
res.disconnects.push("}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function createRelationshipValidationClauses({
.with([Cypher.count(relVarnameCypher), cVariable])
.where(Cypher.apoc.util.validatePredicate(predicateCypher, errorMsg))
.return([returnVar, new Cypher.Variable()]);
return new Cypher.Call(match).importWith(varName);
return new Cypher.Call(match, [varName]);
})
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql/src/translate/create-update-and-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export default function createUpdateAndParams({

subquery.push(
`WITH ${withVars.join(", ")}`,
"CALL {",
"CALL(*) {",
indentBlock(innerUpdate.join("\n")),
"}"
);
Expand Down Expand Up @@ -483,11 +483,11 @@ export default function createUpdateAndParams({
});
if (relationField.interface) {
res.strs.push(`WITH ${withVars.join(", ")}`);
res.strs.push(`CALL {\n\t WITH ${withVars.join(", ")}\n\t`);
res.strs.push(`CALL (${withVars.join(", ")}) {\n\t`);
const subqueriesWithMetaPassedOn = subqueries.map(
(each, i) => each + `\n}\n${intermediateWithMetaStatements[i] || ""}`
);
res.strs.push(subqueriesWithMetaPassedOn.join(`\nCALL {\n\t WITH ${withVars.join(", ")}\n\t`));
res.strs.push(subqueriesWithMetaPassedOn.join(`\nCALL (${withVars.join(", ")}){\n\t`));
} else {
res.strs.push(subqueries.join("\n"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class ConnectionFilter extends Filter {
const subqueries = this.innerFilters.flatMap((f) => {
const nestedSubqueries = f
.getSubqueries(queryASTContext)
.map((sq) => new Cypher.Call(sq).importWith(queryASTContext.target));
.map((sq) => new Cypher.Call(sq, [queryASTContext.target]));
const selection = f.getSelection(queryASTContext);
const predicate = f.getPredicate(queryASTContext);
const clauses = [...selection, ...nestedSubqueries];
Expand Down Expand Up @@ -253,8 +253,7 @@ export class ConnectionFilter extends Filter {
if (predicate) {
const returnVar = new Cypher.Variable();
truthyFilters.push(returnVar);
return new Cypher.Call(sq)
.importWith(queryASTContext.target)
return new Cypher.Call(sq, [queryASTContext.target])
.with("*")
.where(predicate)
.return([Cypher.gt(Cypher.count(queryASTContext.target), new Cypher.Literal(0)), returnVar]);
Expand All @@ -274,8 +273,7 @@ export class ConnectionFilter extends Filter {
if (predicate) {
const returnVar = new Cypher.Variable();
falsyFilters.push(returnVar);
return new Cypher.Call(sq)
.importWith(queryASTContext.target)
return new Cypher.Call(sq, [queryASTContext.target])
.with("*")
.where(Cypher.not(predicate))
.return([Cypher.gt(Cypher.count(queryASTContext.target), new Cypher.Literal(0)), returnVar]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class RelationshipFilter extends Filter {
const returnVar = new Cypher.Variable();
returnVariables.push(returnVar);
const nestedSubqueries = f.getSubqueries(context).map((sq) => {
return new Cypher.Call(sq).importWith(context.target);
return new Cypher.Call(sq, [context.target]);
});

let predicate = f.getPredicate(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ export class ConnectionReadOperation extends Operation {
}

const authFilterSubqueries = this.getAuthFilterSubqueries(nestedContext).map((sq) => {
return new Cypher.Call(sq).importWith(nestedContext.target);
return new Cypher.Call(sq, [nestedContext.target]);
});

const normalFilterSubqueries = this.getFilterSubqueries(nestedContext).map((sq) => {
return new Cypher.Call(sq).importWith(nestedContext.target);
return new Cypher.Call(sq, [nestedContext.target]);
});

const filtersSubqueries = [...authFilterSubqueries, ...normalFilterSubqueries];
Expand All @@ -171,11 +171,10 @@ export class ConnectionReadOperation extends Operation {
const isTopLevel = !this.relationship;

const aggregationSubqueries = (this.aggregationField?.getSubqueries(context) ?? []).map((sq) => {
const subquery = new Cypher.Call(sq);
if (!isTopLevel) {
return subquery.importWith(context.target);
return new Cypher.Call(sq, [context.target]);
} else {
return subquery;
return new Cypher.Call(sq);
}
});

Expand Down Expand Up @@ -240,8 +239,9 @@ export class ConnectionReadOperation extends Operation {

if (aggregationSubqueries.length > 0) {
connectionClauses = new Cypher.Call( // NOTE: this call is only needed when aggregate is used
Cypher.utils.concat(connectionClauses, new Cypher.Return(edgesProjectionVar, totalCount))
).importWith("*");
Cypher.utils.concat(connectionClauses, new Cypher.Return(edgesProjectionVar, totalCount)),
"*"
);
}

return {
Expand Down Expand Up @@ -303,8 +303,9 @@ export class ConnectionReadOperation extends Operation {
paginationWith,
...postPaginationSubqueries,
new Cypher.Return([Cypher.collect(edgeProjectionMap), returnVar])
)
).importWith(edgesVar);
),
[edgesVar]
);
}

protected createProjectionMapForNode(context: QueryASTContext<Cypher.Node>): Cypher.Map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export class CypherEntityOperation extends ReadOperation {
...this.getCypherFieldsSubqueries(nestedContext)
);

const authFilterSubqueries = this.getAuthFilterSubqueries(nestedContext).map((sq) =>
new Cypher.Call(sq).importWith(nestedContext.target)
const authFilterSubqueries = this.getAuthFilterSubqueries(nestedContext).map(
(sq) => new Cypher.Call(sq, [nestedContext.target])
);

const authPredicates = this.getAuthFilterPredicate(nestedContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class DeleteOperation extends MutationOperation {
this.validateSelection(selection);
const filterSubqueries = wrapSubqueriesInCypherCalls(context, this.filters, [context.target]);
const authBeforeSubqueries = this.getAuthFilterSubqueries(context).map((c) => {
return new Cypher.Call(c).importWith(context.target);
return new Cypher.Call(c, [context.target]);
});
const predicate = this.getPredicate(context);
const validations = this.getValidations(context);
Expand Down Expand Up @@ -112,7 +112,7 @@ export class DeleteOperation extends MutationOperation {
const filterSubqueries = wrapSubqueriesInCypherCalls(context, this.filters, [context.target]);

const authBeforeSubqueries = this.getAuthFilterSubqueries(context).map((c) => {
return new Cypher.Call(c).importWith(context.target);
return new Cypher.Call(c, [context.target]);
});
const extraSelections = this.getExtraSelections(context);
const predicate = this.getPredicate(context);
Expand All @@ -124,7 +124,7 @@ export class DeleteOperation extends MutationOperation {
const unwindDeleteVar = new Cypher.Variable();
const deleteClause = new Cypher.Unwind([deleteVar, unwindDeleteVar]).detachDelete(unwindDeleteVar);

const deleteBlock = new Cypher.Call(deleteClause).importWith(deleteVar);
const deleteBlock = new Cypher.Call(deleteClause, [deleteVar]);
const nestedOperations: (Cypher.Call | Cypher.With)[] = this.getNestedDeleteSubQueries(context);
const statements = this.appendFilters(
[selection, ...extraSelections, ...filterSubqueries, ...authBeforeSubqueries],
Expand Down Expand Up @@ -187,7 +187,7 @@ export class DeleteOperation extends MutationOperation {
const nestedOperations: Cypher.Call[] = [];
for (const nestedDeleteOperation of this.nestedOperations) {
const { clauses } = nestedDeleteOperation.transpile(context);
nestedOperations.push(...clauses.map((c) => new Cypher.Call(c).importWith("*")));
nestedOperations.push(...clauses.map((c) => new Cypher.Call(c, "*")));
}
return nestedOperations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ export class ReadOperation extends Operation {
const cypherFieldSubqueries = this.getCypherFieldsSubqueries(nestedContext);
const sortSubqueries = wrapSubqueriesInCypherCalls(nestedContext, this.sortFields, [nestedContext.target]);

const authFilterSubqueries = this.getAuthFilterSubqueries(nestedContext).map((sq) =>
new Cypher.Call(sq).importWith(nestedContext.target)
const authFilterSubqueries = this.getAuthFilterSubqueries(nestedContext).map(
(sq) => new Cypher.Call(sq, [nestedContext.target])
);

const authFiltersPredicate = this.getAuthFilterPredicate(nestedContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class UnwindCreateOperation extends MutationOperation {

const nestedSubqueries = setSubqueries.flatMap((clause) => [
new Cypher.With(nestedContext.target, this.unwindVariable),
new Cypher.Call(clause).importWith(nestedContext.target, this.unwindVariable),
new Cypher.Call(clause, [nestedContext.target, this.unwindVariable]),
]);

const authorizationClauses = this.getAuthorizationClauses(nestedContext);
Expand All @@ -150,8 +150,9 @@ export class UnwindCreateOperation extends MutationOperation {
);
} else {
subQueryClause = new Cypher.Call(
Cypher.utils.concat(unwindCreateClauses, new Cypher.Return(nestedContext.target))
).importWith(this.unwindVariable);
Cypher.utils.concat(unwindCreateClauses, new Cypher.Return(nestedContext.target)),
[this.unwindVariable]
);
}
const projectionContext = new QueryASTContext({
...nestedContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ export class CompositeConnectionReadOperation extends Operation {

const union = new Cypher.Union(...nestedSubqueries);

const nestedSubquery = new Cypher.Call(new Cypher.Call(union).return([Cypher.collect(edgeVar), edgesVar]));
if (context.target) {
nestedSubquery.importWith(context.target);
}
const contextTarget = context.target ? [context.target] : [];
const nestedSubquery = new Cypher.Call(
new Cypher.Call(union).return([Cypher.collect(edgeVar), edgesVar]),
contextTarget
);

let orderSubquery: Cypher.Call | undefined;

Expand Down Expand Up @@ -97,7 +98,7 @@ export class CompositeConnectionReadOperation extends Operation {

extraWithOrder.return([Cypher.collect(edgeVar), edgesVar2]);
returnEdgesVar = edgesVar2;
orderSubquery = new Cypher.Call(extraWithOrder).importWith(edgesVar);
orderSubquery = new Cypher.Call(extraWithOrder, [edgesVar]);
}

const {
Expand Down Expand Up @@ -126,9 +127,7 @@ export class CompositeConnectionReadOperation extends Operation {
clauses: [
Cypher.utils.concat(
nestedSubquery,
...aggregateSubqueries.map((clause) =>
new Cypher.Call(clause).importWith(...filterTruthy([context.target]))
),
...aggregateSubqueries.map((clause) => new Cypher.Call(clause, filterTruthy([context.target]))),
subqueryWith,
orderSubquery,
returnClause
Expand Down
Loading
Loading