在此示例中如何添加用户?我尝试以各种方式使用变异,但无效。
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"
}
)
}
我尝试了不同的版本,但是我真的找不到解决方法
答案 0 :(得分:1)
在prisma中创建数据模型后,在操场上尝试
mutation {
createUser(
data: {
name: "Kevin",
surname: "Key"
address: {
create: {
street: "Clark Street",
flat: 19,
city: "Brentwood",
country: "United Kingdom"
}
}
}
) {
id
name
}
}
注意 如果已经创建了地址对象,也可以使用connect,只需传递Address id(Primary Key / ObjectId)