neo4j-graphql-js icon indicating copy to clipboard operation
neo4j-graphql-js copied to clipboard

Using types as sub objects

Open danielsvane opened this issue 6 years ago • 3 comments

This question might be really dumb, I'm not the best at neither GraphQL nor Neo4j.

I have a schema created with makeAugmentedSchema, where there's a user that has an address field:

type Address {
  country: String
  city: String
}

type User {
  name: String
  address: Address
}

Now it tries to generate the address type as a node, which makes sense. Is it possible to just have a type as a nested object, that can be created directly in a CreateUser mutation?

danielsvane avatar Feb 01 '19 13:02 danielsvane

Would love to be able to do that

appinteractive avatar Feb 04 '19 12:02 appinteractive

We currently map GraphQL types directly to node labels in the database, which makes it easy to reason about the data model. In your case, this results in having to execute 3 mutations to create an Address, User, and connect them: CreateAddress, CreateUser, and AddAddressUser.

Combining all of this into a single mutation operation - known as a nested mutation. is on our radar, but not something that is currently supported.

In the mean time, you could add this functionality manually to your schema by creating a mutation with a @cypher schema directive and defining the logic for updating the database with a Cypher query.

johnymontana avatar Feb 04 '19 16:02 johnymontana

https://github.com/neo4j-graphql/neo4j-graphql-js/issues/608

michaeldgraham avatar May 02 '21 04:05 michaeldgraham