-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b5d51d
commit 8322ec3
Showing
8 changed files
with
152 additions
and
50 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,18 @@ | ||
--- | ||
"@neo4j/graphql": major | ||
--- | ||
|
||
Throws an error when the same field is updated multiple times on same update operation. | ||
|
||
For example: | ||
|
||
```graphql | ||
mutation { | ||
updateMovies(update: { tags_POP: 1, tags_PUSH: "d" }) { | ||
movies { | ||
title | ||
tags | ||
} | ||
} | ||
} | ||
``` |
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
34 changes: 34 additions & 0 deletions
34
packages/graphql/src/translate/queryAST/factory/parsers/parse-mutation-field.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,34 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
type MutationOperation = "PUSH" | "POP" | "ADD" | "SUBTRACT" | "MULTIPLY" | "DIVIDE" | "INCREMENT" | "DECREMENT"; | ||
|
||
export type MutationRegexGroups = { | ||
fieldName: string; | ||
operator: MutationOperation | undefined; | ||
}; | ||
|
||
const mutationRegEx = | ||
/(?<fieldName>[_A-Za-z]\w*?)(?:_(?<operator>PUSH|POP|ADD|SUBTRACT|MULTIPLY|DIVIDE|INCREMENT|DECREMENT))?$/; | ||
|
||
export function parseMutationField(field: string): MutationRegexGroups { | ||
const match = mutationRegEx.exec(field); | ||
|
||
return match?.groups as MutationRegexGroups; | ||
} |
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
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
82 changes: 82 additions & 0 deletions
82
packages/graphql/tests/integration/issues/5671.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,82 @@ | ||
/* | ||
* 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 { GraphQLError } from "graphql"; | ||
import type { UniqueType } from "../../utils/graphql-types"; | ||
import { TestHelper } from "../../utils/tests-helper"; | ||
|
||
describe("https://github.com/neo4j/graphql/issues/5671", () => { | ||
let Movie: UniqueType; | ||
|
||
const testHelper = new TestHelper(); | ||
|
||
beforeEach(async () => { | ||
Movie = testHelper.createUniqueType("Movie"); | ||
|
||
const typeDefs = /* GraphQL */ ` | ||
type ${Movie} @node { | ||
title: String! | ||
tags: [String!]! | ||
rating: Int | ||
} | ||
`; | ||
await testHelper.initNeo4jGraphQL({ | ||
typeDefs, | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
await testHelper.close(); | ||
}); | ||
|
||
test("should fail to update an array in the same update", async () => { | ||
const mutation = /* GraphQL */ ` | ||
mutation { | ||
${Movie.operations.update}(update: { tags_POP: 1, tags_PUSH: "d" }) { | ||
${Movie.plural} { | ||
title | ||
tags | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const result = await testHelper.executeGraphQL(mutation); | ||
expect(result.errors).toEqual([ | ||
new GraphQLError(`Conflicting modification of [[tags_POP]], [[tags_PUSH]] on type ${Movie}`), | ||
]); | ||
}); | ||
|
||
test("should fail to update an int in the same update", async () => { | ||
const mutation = /* GraphQL */ ` | ||
mutation UpdateMovies { | ||
${Movie.operations.update}(update: { rating_INCREMENT: 5, rating_DECREMENT: 2 }) { | ||
${Movie.plural} { | ||
title | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const result = await testHelper.executeGraphQL(mutation); | ||
expect(result.errors).toEqual([ | ||
new GraphQLError(`Conflicting modification of [[rating_INCREMENT]], [[rating_DECREMENT]] on type ${Movie}`), | ||
]); | ||
}); | ||
}); |
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