-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5463 from MacondoExpress/chore-b6
Move tests to v6, add error on conflicting properties
- Loading branch information
Showing
7 changed files
with
218 additions
and
198 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
45 changes: 45 additions & 0 deletions
45
packages/graphql/src/api-v6/queryIRFactory/utils/raise-on-conflicting-input.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,45 @@ | ||
/* | ||
* 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 { ConcreteEntity } from "../../../schema-model/entity/ConcreteEntity"; | ||
import type { Relationship } from "../../../schema-model/relationship/Relationship"; | ||
import { FactoryParseError } from "../factory-parse-error"; | ||
import type { GraphQLTreeCreateInput } from "../resolve-tree-parser/graphql-tree/graphql-tree"; | ||
|
||
export function raiseOnConflictingInput( | ||
input: GraphQLTreeCreateInput, // TODO: add Update types as well | ||
entityOrRel: ConcreteEntity | Relationship | ||
): void { | ||
const hash = {}; | ||
const properties = Object.keys(input); | ||
properties.forEach((property) => { | ||
const dbName = entityOrRel.findAttribute(property)?.databaseName; | ||
if (dbName === undefined) { | ||
throw new FactoryParseError(`Impossible to translate property ${property} on entity ${entityOrRel.name}`); | ||
} | ||
if (hash[dbName]) { | ||
throw new FactoryParseError( | ||
`Conflicting modification of ${[hash[dbName], property].map((n) => `[[${n}]]`).join(", ")} on type ${ | ||
entityOrRel.name | ||
}` | ||
); | ||
} | ||
hash[dbName] = property; | ||
}); | ||
} |
163 changes: 163 additions & 0 deletions
163
...ages/graphql/tests/api-v6/integration/directives/alias/conflicting-properties.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,163 @@ | ||
/* | ||
* 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("conflicting properties", () => { | ||
const testHelper = new TestHelper({ v6Api: true }); | ||
|
||
let typeMovie: UniqueType; | ||
let typeDirector: UniqueType; | ||
|
||
beforeEach(async () => { | ||
typeMovie = testHelper.createUniqueType("Movie"); | ||
typeDirector = testHelper.createUniqueType("Director"); | ||
|
||
const typeDefs = /* GraphQL */ ` | ||
type ${typeDirector} @node { | ||
name: String | ||
nameAgain: String @alias(property: "name") | ||
movies: [${typeMovie}!]! @relationship(direction: OUT, type: "DIRECTED", properties: "Directed") | ||
} | ||
type Directed @relationshipProperties { | ||
year: Int! | ||
movieYear: Int @alias(property: "year") | ||
} | ||
type ${typeMovie} @node { | ||
title: String | ||
titleAgain: String @alias(property: "title") | ||
directors: [${typeDirector}!]! @relationship(direction: IN, type: "DIRECTED", properties: "Directed") | ||
} | ||
`; | ||
|
||
await testHelper.initNeo4jGraphQL({ | ||
typeDefs, | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
await testHelper.close(); | ||
}); | ||
|
||
test("Create mutation with alias referring to existing field, include both fields as inputs", async () => { | ||
const userMutation = /* GraphQL */ ` | ||
mutation { | ||
${typeDirector.operations.create}(input: [{ node: { name: "Tim Burton", nameAgain: "Timmy Burton" }}]) { | ||
${typeDirector.plural} { | ||
name | ||
nameAgain | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const gqlResult = await testHelper.executeGraphQL(userMutation); | ||
|
||
expect(gqlResult.errors).toBeDefined(); | ||
expect(gqlResult.errors).toHaveLength(1); | ||
expect(gqlResult.errors).toEqual([ | ||
new GraphQLError(`Conflicting modification of [[name]], [[nameAgain]] on type ${typeDirector.name}`), | ||
]); | ||
expect(gqlResult?.data).toEqual({ | ||
[typeDirector.operations.create]: null, | ||
}); | ||
}); | ||
|
||
test("Create mutation with alias referring to existing field, include only field as inputs", async () => { | ||
const userMutation = /* GraphQL */ ` | ||
mutation { | ||
${typeDirector.operations.create}(input: [{ node: {name: "Tim Burton"} }]) { | ||
${typeDirector.plural} { | ||
name | ||
nameAgain | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const gqlResult = await testHelper.executeGraphQL(userMutation); | ||
|
||
expect(gqlResult.errors).toBeUndefined(); | ||
expect(gqlResult?.data).toEqual({ | ||
[typeDirector.operations.create]: { | ||
[typeDirector.plural]: [ | ||
{ | ||
name: "Tim Burton", | ||
nameAgain: "Tim Burton", | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
test("Create mutation with alias referring to existing field, include only alias field as inputs", async () => { | ||
const userMutation = /* GraphQL */ ` | ||
mutation { | ||
${typeDirector.operations.create}(input: [{ node: { nameAgain: "Tim Burton" } }]) { | ||
${typeDirector.plural} { | ||
name | ||
nameAgain | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const gqlResult = await testHelper.executeGraphQL(userMutation); | ||
|
||
expect(gqlResult.errors).toBeUndefined(); | ||
expect(gqlResult?.data).toEqual({ | ||
[typeDirector.operations.create]: { | ||
[typeDirector.plural]: [ | ||
{ | ||
name: "Tim Burton", | ||
nameAgain: "Tim Burton", | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
test("Create mutation with alias referring to existing field, include both bad and good inputs", async () => { | ||
const userMutation = /* GraphQL */ ` | ||
mutation { | ||
${typeDirector.operations.create}(input: [{ node: {name: "Tim Burton", nameAgain: "Timmy Burton"} }, { node: { name: "Someone" }}]) { | ||
${typeDirector.plural} { | ||
name | ||
nameAgain | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const gqlResult = await testHelper.executeGraphQL(userMutation); | ||
|
||
expect(gqlResult.errors).toBeDefined(); | ||
expect(gqlResult.errors).toHaveLength(1); | ||
expect(gqlResult.errors).toEqual([ | ||
new GraphQLError(`Conflicting modification of [[name]], [[nameAgain]] on type ${typeDirector.name}`), | ||
]); | ||
expect(gqlResult?.data).toEqual({ | ||
[typeDirector.operations.create]: null, | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.