Skip to content

Commit

Permalink
Merge pull request #335 from darrellwarde/bugfix/cypher-primitive-arrays
Browse files Browse the repository at this point in the history
Fix primitive arrays being returned from custom Cypher fields
  • Loading branch information
darrellwarde authored Jul 20, 2021
2 parents 9dd1d9b + 6ebfe79 commit 782504a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ function createProjectionAndParams({
projectionStr ? `| ${param} ${projectionStr}` : ""
}`;

if (cypherField.typeMeta.array) {
res.projection.push(`${key}: [${apocStr}]`);
if (isPrimitive || isEnum) {
res.projection.push(`${key}: ${apocStr}`);

return res;
}

if (isPrimitive || isEnum) {
res.projection.push(`${key}: ${apocStr}`);
if (cypherField.typeMeta.array) {
res.projection.push(`${key}: [${apocStr}]`);

return res;
}
Expand Down
57 changes: 57 additions & 0 deletions packages/graphql/tests/integration/custom-resolvers.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,62 @@ describe("Custom Resolvers", () => {
await session.close();
}
});

test("should return an array of primitive values from a cypher directive (field level)", async () => {
const id = generate({
charset: "alphabetic",
});
const string1 = generate({
charset: "alphabetic",
});
const string2 = generate({
charset: "alphabetic",
});
const string3 = generate({
charset: "alphabetic",
});

const typeDefs = `
type Type {
id: ID
strings: [String] @cypher(statement: """
RETURN ['${string1}', '${string2}', '${string3}']
""")
}
`;

const query = `
query {
types(where: { id: "${id}" }) {
id
strings
}
}
`;

const session = driver.session();

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

try {
await session.run(`
CREATE (:Type {id: "${id}"})
`);

const gqlResult = await graphql({
schema: neoSchema.schema,
source: query,
contextValue: { driver },
});

expect(gqlResult.errors).toBeFalsy();

expect((gqlResult.data as any).types[0]).toEqual({ id, strings: [string1, string2, string3] });
} finally {
await session.close();
}
});
});
});

0 comments on commit 782504a

Please sign in to comment.