Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Allow whitelist of constraints to keep #595

Open
AdrienLemaire opened this issue Mar 8, 2021 · 1 comment
Open

Allow whitelist of constraints to keep #595

AdrienLemaire opened this issue Mar 8, 2021 · 1 comment

Comments

@AdrienLemaire
Copy link
Contributor

AdrienLemaire commented Mar 8, 2021

Related: #137
Maybe related: #569

I need to assert that nodes for a type are unique by a combination of field values.
Since neo4j-graphql-js doesn't allow this at the moment (@uniqueTogether directive ?), I have a cypher script to create the constraint

// Make sure we have unique nodes
CREATE CONSTRAINT uniqueT10 IF NOT EXISTS ON (n:T10)
      ASSERT (n.date, n.name, n.result, n.m50) IS NODE KEY;

The cypher query works fine, and the constraint shows up in the neo4j desktop

But when starting my Apollo server, I get

{ address: 'localhost:11003', version: 'Neo4j/4.2.3' }
┌─────────┬─────────────┬────────────┬───────────────────────────────────────────────┬────────┬───────────┐
│ (index) │    label    │    key     │                     keys                      │ unique │  action   │
├─────────┼─────────────┼────────────┼───────────────────────────────────────────────┼────────┼───────────┤
│    2    │    'T10'    │    null    │ [ 'date', 'name', 'result', ... 1 more item ] │  true  │ 'DROPPED' │
└─────────┴─────────────┴────────────┴───────────────────────────────────────────────┴────────┴───────────┘

My type definition:

type T10 {
  date: DateTime!
  #id: ID! @id
  m50: Int!
  #month: Month! @relation(name: "DONE_ON", direction: OUT)
  name: String!  # user name. required for the noed key assert constraint
  result: Int!
  #school: School! @relation(name: "DONE_AT", direction: OUT)
  user: User! @relation(name: "SWAM", direction: IN)
}

The related assertSchema call

assertSchema({ debug: true, driver, schema });

Looking at the doc, I see a dropExisting option. Sure enough, if I set it to false, my constraint is kept. But so are constraints that I might want to see deleted when changing other types in the schema later on.

Could we add a keepWhitelist list of constraints names, so I could do the following ?

- assertSchema({ debug: true, driver, schema, dropExisting: false });
+ assertSchema({ debug: true, driver, schema, keepWhitelist: ["uniqueT10"] });
@michaeldgraham
Copy link
Collaborator

#608

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants