trompamusic / ce-api

The Contributor Environment API for the TROMPA project
https://trompamusic.eu
Apache License 2.0
6 stars 1 forks source link

Determine how to model one-to-many relationships #92

Open alastair opened 4 years ago

alastair commented 4 years ago

We have a few cases where we want to model a one-to-many relationship.

Using the neo4j-graphql-js library we haven't found a good way to do this. Currently we use @relation to define a many-to-many relationship.

@ChristiaanScheermeijer suggested that we could try and use Neo4j constraints. We need to see if this is a suitable solution.

https://github.com/trompamusic/ce-api/pull/90/files/123f1a4849e69dde82543d77dc224d9ac0c8cf2e#r384462860

alastair commented 3 years ago

We found that you can make a relation for a single item:

target: ThingInterface! @relation(name: "ANNOTATION_TARGET", direction: OUT)

However, in the case where a field is required and a relation, the Create mutation allows you to create an object without the field (because you need to use Add/Merge to create the relation), but if you try and do a Query that includes this field when it's not set an error will be raised. This can probably be closed if we're happy with the current solution.