graphql icon indicating copy to clipboard operation
graphql copied to clipboard

connectOrCreate - onCreate input does not allow for nested node create/connect

Open tbwiss opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. Note: This was raised on Discord.

Given this type definition:

type Thing {
    name: String!
}

type Actor {
    name: String!
    id: ID! @id
    someField: String
    movies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT)
    somethings: [Thing!]! @relationship(type: "SOMETHING", direction: IN)
}
type Movie {
    title: String
    id: ID! @id
    actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN)
}

One cannot make a nested "create" or "connect" in the "onCreate" of "connectOrCreate" (see comment in mutation).

mutation {
  createMovies(input: [
    {
      title: "Test Movie"
      actors: {
        connectOrCreate: [  // <- Note this here
          {
            where: { node: { id: "1111111"} },
            onCreate: {
              node: { 
                name: "Jane Doe",
                someField: "Hello",
                somethings: { connect: { where: node: { id: "123123" } } }  // <- this here is not possible
              },
            },
          },
        ],
      },
    },
  ]) {
    movies {
      id
    }
  }
}

A nested "create" or "connect" is however possible for a regular "create":

mutation {
  createMovies(
    input: [
      {
        title: "Test Movie"
        actors: {
          create: [    // <- Note this here
            {
              node: {
                name: "Jane Doe"
                someField:  "Whatever"
                somethings: {   
                  create: [{ node: { name: "The something name" } }]    // <- here it is possible to create a "Thing" node
                }
              }
            }
          ]
        }
      }
    ]
  ) {
    movies {
      id
    }
  }
}

Details:

In the SDL we can see the following.

ActorCreateInput which is used in the second mutation above:

input ActorCreateInput {
  name: String!
  someField: String
  movies: ActorMoviesFieldInput
  somethings: ActorSomethingsFieldInput
}

And the ActorOnCreateInput used in the first mutation above for onCreate:

input MovieActorsConnectOrCreateFieldInputOnCreate {
  node: ActorOnCreateInput!
}

input ActorOnCreateInput {
  name: String!
  someField: String
}

movies and somethings is missing in ActorOnCreateInput.

Describe the solution you'd like Ability to create nested node even as part of connectOrCreate onCreate.

tbwiss avatar Jun 09 '22 10:06 tbwiss