-
Notifications
You must be signed in to change notification settings - Fork 152
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
Feature/unique directive #547
Feature/unique directive #547
Conversation
…rror when `@unique` used on interface field
Thanks for the documentation updates. The preview documentation has now been torn down - reopening this PR will republish it. |
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.
Looks good. A few minor comments
…compatible with all versions
Thanks for the comments @angrykoala - looks like I need to rewrite the whole thing anyway because my current solution isn't 4.1 compatible!!! 👿 |
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.
I noticed that when I create a node through the GraphQL API the Neo4j Error is propagated to the users. What do you think and would there be a possibility to throw something more generic, just to ensure that we don't leak any info about the backend?
Example Error:
{
"errors": [
{
"message": "Node(7108) already exists with label `Movie` and property `title` = 'Some Title'",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"createMovies"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"code": "Neo.ClientError.Schema.ConstraintValidationFailed",
"name": "Neo4jError",
"stacktrace": [
"Neo4jError: Node(7108) already exists with label `Movie` and property `title` = 'Some Title'",
": ",
" at captureStacktrace (C:\\code\\neo4j\\graphql\\node_modules\\neo4j-driver-core\\lib\\result.js:239:17)",
" at new Result (C:\\code\\neo4j\\graphql\\node_modules\\neo4j-driver-core\\lib\\result.js:59:23)",
" at newCompletedResult (C:\\code\\neo4j\\graphql\\node_modules\\neo4j-driver-core\\lib\\transaction.js:372:12)",
" at Object.run (C:\\code\\neo4j\\graphql\\node_modules\\neo4j-driver-core\\lib\\transaction.js:226:20)",
" at Transaction.run (C:\\code\\neo4j\\graphql\\node_modules\\neo4j-driver-core\\lib\\transaction.js:98:34)",
" at C:\\code\\neo4j\\graphql\\packages\\graphql\\src\\utils\\execute.ts:94:35",
" at TransactionExecutor._safeExecuteTransactionWork (C:\\code\\neo4j\\graphql\\node_modules\\neo4j-driver-core\\lib\\internal\\transaction-executor.js:92:26)",
" at TransactionExecutor._executeTransactionInsidePromise (C:\\code\\neo4j\\graphql\\node_modules\\neo4j-driver-core\\lib\\internal\\transaction-executor.js:83:34)",
" at C:\\code\\neo4j\\graphql\\node_modules\\neo4j-driver-core\\lib\\internal\\transaction-executor.js:40:19",
" at new Promise (<anonymous>)"
]
}
}
}
],
"data": null
}
packages/graphql/tests/integration/assert-indexes-and-constraints.int.test.ts
Show resolved
Hide resolved
packages/graphql/src/classes/utils/asserts-indexes-and-constraints.ts
Outdated
Show resolved
Hide resolved
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.
Looking nice, just minor style/legibility proposals
Description
Adds an
assertConstrains
function to theNeo4jGraphQL
class which can be used to assert unique node property constraints indicated by a new@unique
directive exist.Overview of features:
@id
and@unique
directives indicate that a unique node property constraint should exist for the property mapped to the GraphQL field.@id
has a new boolean option,unique
, which istrue
by default, which let's users disable this new behaviour.label
argument of the@node
directive, and the@alias
directive.assertConstraints
.UPDATE:
Instead of using the desired
SHOW CONSTRAINTS
(https://neo4j.com/docs/cypher-manual/4.3/constraints/examples/#administration-constraints-list-constraint), this has to useCALL db.constraints
(https://neo4j.com/docs/cypher-manual/4.1/administration/constraints/#administration-constraints-list-constraint) to maintain compatibility with 4.1.Introduced a parsing function which outputs in the same object format as
SHOW CONSTRAINTS
, and left the code forSHOW CONSTRAINTS
present underTODO
blocks so that swapping out is simple when 4.1 reaches end-of-life.Issue
#206
Checklist
The following requirements should have been met (depending on the changes in the branch):