Skip to content

Commit

Permalink
Merge branch 'dev' into 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
angrykoala authored Apr 12, 2023
2 parents 7fcb3e0 + cbc1597 commit 50f3df1
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilled-dolphins-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": patch
---

Fix query by edge property on union type
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,16 @@ function createSimpleRelationshipPredicate({
const isArray = relationField.typeMeta.array;
const isRequired = relationField.typeMeta.required;

if (isArray || !isRequired) {
const isUnionField = Boolean(relationField.union);
if (isArray || !isRequired || isUnionField) {
const patternComprehension = new Cypher.PatternComprehension(matchPattern, new Cypher.Literal(1)).where(
innerOperation
);
return { predicate: Cypher.single(childNode, patternComprehension, new Cypher.Literal(true)) };
}

const matchStatement = new Cypher.Match(matchPattern);

return {
predicate: innerOperation,
preComputedSubqueries: Cypher.concat(matchStatement),
Expand Down
159 changes: 159 additions & 0 deletions packages/graphql/tests/integration/issues/3165.int.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { Driver, Session } from "neo4j-driver";
import { graphql } from "graphql";
import Neo4j from "../neo4j";
import { Neo4jGraphQL } from "../../../src";
import { UniqueType } from "../../utils/graphql-types";
import { cleanNodes } from "../../utils/clean-nodes";
import { Neo4jGraphQLAuthJWTPlugin } from "../../../../plugins/graphql-plugin-auth/src";

describe("https://github.com/neo4j/graphql/issues/3165", () => {
let driver: Driver;
let neo4j: Neo4j;
let neoSchema: Neo4jGraphQL;
let session: Session;

let Book: UniqueType;
let BookTitle_SV: UniqueType;
let BookTitle_EN: UniqueType;

beforeAll(async () => {
neo4j = new Neo4j();
driver = await neo4j.getDriver();
});

beforeEach(async () => {
session = await neo4j.getSession();

Book = new UniqueType("Book");
BookTitle_SV = new UniqueType("BookTitle_SV");
BookTitle_EN = new UniqueType("BookTitle_EN");

const typeDefs = `
type A {
name: String!
related: [Related!]! @relationship(type: "PROPERTY_OF", properties: "RelatedProperties", direction: IN)
}
type B {
name: String!
related: [Related!]! @relationship(type: "PROPERTY_OF", properties: "RelatedProperties", direction: IN)
}
union RelatedTarget = A | B
interface RelatedProperties @relationshipProperties {
prop: String!
}
type Related {
name: String!
value: String!
target: RelatedTarget!
@relationship(type: "PROPERTY_OF", properties: "RelatedProperties", direction: OUT)
}
`;

neoSchema = new Neo4jGraphQL({
typeDefs,
driver,
plugins: {
auth: new Neo4jGraphQLAuthJWTPlugin({
secret: "secret",
}),
},
});
});

afterEach(async () => {
await cleanNodes(session, [Book, BookTitle_EN, BookTitle_SV]);
await session.close();
});

afterAll(async () => {
await driver.close();
});

test("create and query by edge property over an union", async () => {
const mutation = `
mutation CreateA {
createAs(
input: {
name: "A"
related: { create: { edge: { prop: "propvalue" }, node: { name: "Related", value: "value" } } }
}
) {
as {
name
relatedConnection {
edges {
prop
node {
name
}
}
}
}
}
}
`;

const query = `
query Relateds {
relateds(
where: {
OR: [
{ targetConnection: { A: { edge: { prop: "propvalue" } } } }
{ targetConnection: { B: { edge: { prop: "propvalue" } } } }
]
}
) {
name
}
}
`;

const schema = await neoSchema.getSchema();

const mutationResult = await graphql({
schema,
source: mutation,
contextValue: neo4j.getContextValues(),
});

expect(mutationResult.errors).toBeFalsy();

const result = await graphql({
schema,
source: query,
contextValue: neo4j.getContextValues(),
});

expect(result.errors).toBeFalsy();
expect(result.data).toEqual({
relateds: [
{
name: "Related",
},
],
});
});
});

0 comments on commit 50f3df1

Please sign in to comment.