我正在使用AWS Amplify通过在schema.graphql中定义SDL来创建模式。我有两种相关类型:用户和地址。我可以使用单个突变创建一个带有地址的用户吗?
schema.graphql
ALTER TABLE table_name
MODIFY COLUMN column_name datatype(MAX);
使用此SDL,Amplify会生成预定义的查询,变异和订阅以及schema.json。按照SDL的要求,我得到了一个突变:mutations.js中的createUserAndAddress
type User @model @auth(rules: [{allow: owner}]) {
id: ID!
name: String!
mobile: String
email: String
verified: Boolean
address: [Address!]! @connection(name: "UserAddress")
}
type Address @model @auth(rules: [{allow: owner}]) {
id: ID!
line1: String
line2: String
city: String
state: String
country: String
phone: String!
user: User! @connection(name: "UserAddress")
}
input UserInputCustom {
id: ID
name: String
mobile: String
email: String
verified: Boolean
}
input AddressInputCustom {
id: ID
line1: String
line2: String
city: String
state: String
country: String
phone: String
}
type Mutation {
createUserAndAddress(input1: UserInputCustom!, input2: AddressInputCustom): User
}
现在,当我进入AWS AppSync控制台的“查询”部分时,我将创建一个如下所示的变体:
export const createUserAndAddress = `mutation CreateUserAndAddress(
$input1: UserInputCustom!
$input2: AddressInputCustom
) {
createUserAndAddress(input1: $input1, input2: $input2) {
id
name
mobile
email
verified
address {
items {
id
line1
line2
city
state
country
phone
}
nextToken
}
}
}
`;
我得到的返回值为 { “数据”:{ “ createUserAndAddress”:null } }
我哪里出错了?不能通过一次调用来突变两种类型吗?
我将在Vue中使用Vue-Appolo进行graphql操作。只需使用AWS控制台检查突变是否有效。