Neo4j-graphql-js: Generate ID if not provided in create mutation

Created on 12 Jul 2018  路  3Comments  路  Source: neo4j-graphql/neo4j-graphql-js

Use apoc.create.uuid in the generated create mutations so the user does not need to specify an id at creation time.

If an ID param is provided, then a generated uuid should not be used.

Most helpful comment

Use @autogenerate directive on ID field in typedef to indicate field should be autogenerated. If @autogenerate is found on an ID field it will not be included as an argument in the create mutation but will be set automatically at creat time.

All 3 comments

Use @autogenerate directive on ID field in typedef to indicate field should be autogenerated. If @autogenerate is found on an ID field it will not be included as an argument in the create mutation but will be set automatically at creat time.

@johnymontana thanks! That sounds like a big step forward! If I could just ask a few questions...

  1. When do you plan to commit this change? (I see that it's not in the latest.)
  2. Is this a UUID, meaning that I could expect uniqueness to be maintained even across types? (e.g. given types X and Y, every autogenerated X.id would be different than every Y.id?)
  3. Am I correct that you don't currently have implemented "If an ID param is provided, then a generated uuid should not be used."?

Regarding that last question, I just want to point out that, since we currently don't have nested updates, our front end will have to wait for the generated id for every creation mutation before requesting anything else that uses that generated id. For instance, given types X and Y, we can't have a single mutation function that uses an id for a CreateX and also for AddXY.

[As I've said elsewhere, I think that the biggest improvement to the package would be to allow for nested mutations. At a minimum, nested creation which supported the calls to Add would profoundly simplify the front end!]

Instead of using directives to drive this we keep the id field nullable and if a value for it is not provided in the mutation then one is generated using apoc.create.uuid, if the id value is provided then no UUID is generated.

Was this page helpful?
0 / 5 - 0 ratings