Я использую AWS Amplify для создания схемы, определяя SDL в schema.graphql.У меня есть два связанных типа: пользователи и адрес.Могу ли я создать пользователя с адресом, используя одну мутацию?
schema.graphql
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
}
Используя этот SDL, Amplify генерирует предопределенные запросы, мутации и подписки вместе с schema.json.В соответствии с запросом в SDL, я получаю мутацию: createUserAndAddress в mutations.js
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
}
}
}
`;
Теперь, когда я захожу в AWS AppSync Console и в разделе запросов, я создаю мутацию, как показано ниже:
mutation CreateUserAndAddress {
createUserAndAddress(input1:{name:"Bala"},input2:{phone:"8745524"}) {
id
}
}
Я получаю возвращаемое значение {"data": {"createUserAndAddress": null}}
Куда мне обратиться?Разве невозможно изменить два типа с помощью одного вызова?
Я собираюсь использовать Vue-Appolo для операций graphql в Vue.Просто проверяю, работают ли мутации с помощью консоли AWS.