1

在这个例子中如何添加用户?我尝试以各种方式使用突变,但不起作用。

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

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

我尝试这样的事情:

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

接下来

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

我尝试了不同的版本,但我真的找不到解决方案

4

1 回答 1

1

在 prisma 中创建数据模型后在操场上尝试这个

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

注意 如果地址对象已经创建,您也可以使用连接,因为连接只需传递地址 id(主键/ObjectId)

于 2019-01-17T13:07:28.723 回答