I'm trying to create a 'User' that has an array of 'lists'. When I try to first create the user, I wanted to have an empty 'lists' array so that I can add to it later.
Here's my schema:
type User @model {
id: String!
email: String!
lists: [List] @connection(name: "UserLists")
}
type List @model {
id: ID!
name: String!
owner: User! @connection(name: "UserLists")
}
Here's the createUser mutation function:
export const createUser = /* GraphQL */ `
mutation CreateUser(
$input: CreateUserInput!
$condition: ModelUserConditionInput
) {
createUser(input: $input, condition: $condition) {
id
email
lists {
items {
id
name
createdAt
updatedAt
}
nextToken
}
createdAt
updatedAt
}
}
`;
Here's the call I'm trying to make:
let input = {
input: {
email: 'test@test.com',
id: 'ab953afe',
lists: [],
},
};
await API.graphql(graphqlOperation(createUser, input));
And I'm getting this error:
"The variables input contains a field name 'lists' … defined for input object type 'CreateUserInput' "
I am able to create a new user if I omit anything for 'lists'.
Any ideas why I'm seeing this error and how I should be doing this?
just remove list: []
from input
const input = {
input: {
email: 'test@test.com',
id: 'ab953afe',
},
};
await API.graphql(graphqlOperation(createUser, input));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.