-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix non-existing relationships for 1 to 1 relationship. (#4762)
* reintroduce legacy support for null on relationship filter 1..1 * fix flaky test * better test name * Create eleven-laws-shout.md
- Loading branch information
1 parent
8e332d2
commit a77109e
Showing
5 changed files
with
208 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@neo4j/graphql": patch | ||
--- | ||
|
||
Fix non-existing relationships for 1 to 1 relationship. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
packages/graphql/tests/integration/issues/4667.int.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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 { graphql } from "graphql"; | ||
import { type Driver } from "neo4j-driver"; | ||
import { Neo4jGraphQL } from "../../../src"; | ||
import { cleanNodes } from "../../utils/clean-nodes"; | ||
import { UniqueType } from "../../utils/graphql-types"; | ||
import Neo4j from "../neo4j"; | ||
|
||
describe("https://github.com/neo4j/graphql/issues/4667", () => { | ||
let driver: Driver; | ||
let neo4j: Neo4j; | ||
let neoSchema: Neo4jGraphQL; | ||
|
||
let MyThing: UniqueType; | ||
let MyStuff: UniqueType; | ||
|
||
beforeAll(async () => { | ||
neo4j = new Neo4j(); | ||
driver = await neo4j.getDriver(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
MyThing = new UniqueType("MyThing"); | ||
MyStuff = new UniqueType("MyStuff"); | ||
|
||
const session = await neo4j.getSession(); | ||
try { | ||
await session.run(` | ||
CREATE (:${MyThing} {id: "A"})-[:THE_STUFF]->(b1:${MyStuff} {id: "C"}) | ||
CREATE (:${MyThing} {id: "B"}) | ||
`); | ||
} finally { | ||
await session.close(); | ||
} | ||
}); | ||
|
||
afterEach(async () => { | ||
await cleanNodes(driver, [MyThing, MyStuff]); | ||
}); | ||
|
||
afterAll(async () => { | ||
await driver.close(); | ||
}); | ||
|
||
test("when passed null as an argument of a relationship filter should check that a relationship does not exist", async () => { | ||
const typeDefs = /* GraphQL */ ` | ||
type ${MyThing} { | ||
id: ID! @id | ||
stuff: ${MyStuff} @relationship(type: "THE_STUFF", direction: OUT) | ||
} | ||
type ${MyStuff} { | ||
id: ID! @id | ||
thing: ${MyThing} @relationship(type: "THE_STUFF", direction: IN) | ||
} | ||
`; | ||
neoSchema = new Neo4jGraphQL({ | ||
typeDefs, | ||
driver, | ||
}); | ||
const query = /* GraphQL */ ` | ||
query { | ||
${MyThing.plural}(where: { stuff: null }) { | ||
id | ||
stuff { | ||
id | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const result = await graphql({ | ||
schema: await neoSchema.getSchema(), | ||
source: query, | ||
contextValue: neo4j.getContextValues(), | ||
}); | ||
|
||
expect(result.errors).toBeUndefined(); | ||
expect(result.data).toEqual({ | ||
[MyThing.plural]: expect.toIncludeSameMembers([expect.objectContaining({ id: "B" })]), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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 { Neo4jGraphQL } from "../../../src"; | ||
import { formatCypher, formatParams, translateQuery } from "../utils/tck-test-utils"; | ||
|
||
describe("https://github.com/neo4j/graphql/issues/4667", () => { | ||
test("when passed null as an argument of a relationship filter should check that a relationship does not exist", async () => { | ||
const typeDefs = /* GraphQL */ ` | ||
type MyThing { | ||
id: ID! @id | ||
stuff: MyStuff @relationship(type: "THE_STUFF", direction: OUT) | ||
} | ||
type MyStuff { | ||
id: ID! @id | ||
thing: MyThing @relationship(type: "THE_STUFF", direction: IN) | ||
} | ||
`; | ||
|
||
const neoSchema = new Neo4jGraphQL({ typeDefs }); | ||
|
||
const query = /* GraphQL */ ` | ||
query { | ||
myThings(where: { stuff: null }) { | ||
id | ||
} | ||
} | ||
`; | ||
|
||
const result = await translateQuery(neoSchema, query); | ||
|
||
expect(formatCypher(result.cypher)).toMatchInlineSnapshot(` | ||
"MATCH (this:MyThing) | ||
WHERE NOT (EXISTS { | ||
MATCH (this)-[:THE_STUFF]->(this0:MyStuff) | ||
}) | ||
RETURN this { .id } AS this" | ||
`); | ||
|
||
expect(formatParams(result.params)).toMatchInlineSnapshot(`"{}"`); | ||
}); | ||
}); |