Search code examples
graphqlprisma-graphqlplumatic-schema

Mutation doesn't work GraphQL, Prisma, Yoga


How to add User in this example? I try to use mutation in all ways but doesn't work.

type User {
  masterId: Int
  name: String
  surname: String
  address: Address 
}

type Address {
  street: String
  flat: Int
  city: String
  country: String
}

I try something like this:

type Mutation {
  user(
    masterId: Int
    name: String
    surname: String
    address: Address
  ): User
}

and next

mutation {
  user(
    masterId: 4,
      name: "Kevin",
      surname: "Key",
        address: {
        street: "Clark Street",
        flat: 19,
        city: "Brentwood",
        country: "United Kingdom"
      }
  ) 
}

I try different versions, but I really can not find a solution


Solution

  • Try this in the playground after creating datamodel in prisma

    mutation {
      createUser(
        data: {
          name: "Kevin",
          surname: "Key"
          address: {
            create: {
              street: "Clark Street",
              flat: 19,
              city: "Brentwood",
              country: "United Kingdom"
            }
          }
        }
      ) {
        id
        name
      }
    }
    

    Note You also use connect if address object is already created, for connect just pass the Address id(Primary Key/ObjectId)