-
Notifications
You must be signed in to change notification settings - Fork 153
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
Backporting bug-fix for issue #5130 (filter 1to1 relationship with null) #5173
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(`"{}"`); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okaaaaaayyyy... Let's not do a changeset - I think this changelog entry is going to have to be fully manual, I don't think this will work as it is.