Skip to content

Remove apoc.doIt from custom cypher mutations #2805

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

Merged
merged 5 commits into from
Jan 30, 2023
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
2 changes: 1 addition & 1 deletion packages/graphql/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const AUTH_FORBIDDEN_ERROR = "@neo4j/graphql/FORBIDDEN";
export const AUTH_UNAUTHENTICATED_ERROR = "@neo4j/graphql/UNAUTHENTICATED";
export const MIN_VERSIONS = [{ majorMinor: "4.3", neo4j: "4.3.2" }];
export const REQUIRED_APOC_FUNCTIONS = ["apoc.util.validatePredicate", "apoc.date.convertFormat"];
export const REQUIRED_APOC_PROCEDURES = ["apoc.util.validate", "apoc.cypher.doIt"];
export const REQUIRED_APOC_PROCEDURES = ["apoc.util.validate"];
export const DEBUG_ALL = `${DEBUG_PREFIX}:*`;
export const DEBUG_AUTH = `${DEBUG_PREFIX}:auth`;
export const DEBUG_GRAPHQL = `${DEBUG_PREFIX}:graphql`;
Expand Down
6 changes: 6 additions & 0 deletions packages/graphql/src/schema/get-cypher-meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ describe("getCypherMeta", () => {
// @ts-ignore
value: { kind: "StringValue", value: "MATCH (m:Movie) RETURN m" },
},
{
// @ts-ignore
name: { value: "columnName" },
// @ts-ignore
value: { kind: "StringValue", value: "m" },
},
],
},
{
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql/src/schema/get-cypher-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { DirectiveNode, FieldDefinitionNode } from "graphql";

type CypherMeta = {
statement: string;
columnName?: string;
columnName: string;
};

export function getCypherMeta(
Expand Down Expand Up @@ -53,10 +53,10 @@ function parseStatementFlag(directive: DirectiveNode): string {
return stmtArg.value.value;
}

function parseColumnNameFlag(directive: DirectiveNode): string | undefined {
function parseColumnNameFlag(directive: DirectiveNode): string {
const stmtArg = directive.arguments?.find((x) => x.name.value === "columnName");
if (!stmtArg) {
return undefined;
throw new Error("@cypher columnName required");
}
if (stmtArg.value.kind !== "StringValue") {
throw new Error("@cypher columnName is not a string");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export function translateCypherDirectiveProjection({
const entity = context.schemaModel.entities.get(cypherField.typeMeta.name);

const isArray = Boolean(cypherField.typeMeta.array);
const expectMultipleValues = Boolean((referenceNode || entity instanceof CompositeEntity) && isArray);

const fieldFields = field.fieldsByTypeName;

Expand Down
12 changes: 7 additions & 5 deletions packages/graphql/src/translate/translate-top-level-cypher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,20 @@ export function translateTopLevelCypher({

params = { ...params, ...apocParams.params };

const apocParamsStr = `{${apocParams.strs.length ? `${apocParams.strs.join(", ")}` : ""}}`;

if (type === "Query") {
const cypherStatement = createCypherDirectiveSubquery({
field,
});
cypherStrs.push(...cypherStatement);
} else {
const columnName = field.columnName;
cypherStrs.push(`
CALL apoc.cypher.doIt("${statement}", ${apocParamsStr}) YIELD value
WITH [k in keys(value) | value[k]][0] AS this
`);
CALL {
${statement}
}
WITH ${columnName} AS this

`);
}

if (unionWhere.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export interface ConnectionField extends BaseField {
*/
export interface CypherField extends BaseField {
statement: string;
columnName?: string;
columnName: string;
isEnum: boolean;
isScalar: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ describe("Custom Resolvers", () => {

type Mutation {
test(id: ID!): ID! @cypher(statement: """
RETURN \\"${id}\\" + $id as res
RETURN "${id}" + $id as res
""", columnName: "res")
}
`;
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/tests/integration/issues/326.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("326", () => {
getSelf: [User]!
@cypher(
statement: """
MATCH (user:User { id: \\"${id}\\" })
MATCH (user:User { id: "${id}" })
RETURN user
""", columnName: "user"
)
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/tests/integration/types/float.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ describe("Float", () => {
@cypher(
statement: """
CREATE (m:Movie {id: $id, float: $float, floats: $nested.floats})
RETURN m.float
RETURN m.float as result
""",
columnName: "m.float"
columnName: "result"
)
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ query TopLevelCypherDirective {
}
}
}

mutation TopLevelMutationDirective {
getCustomUser {
name
}
}
11 changes: 11 additions & 0 deletions packages/graphql/tests/performance/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ const typeDefs = gql`
columnName: "p"
)
}

type Mutation {
getCustomUser: [Person]!
@cypher(
statement: """
MATCH (user:Person { name_INCLUDES: "Wa" })
RETURN user
"""
columnName: "user"
)
}
`;

let neoSchema: Neo4jGraphQL;
Expand Down