我正在努力为我使用 GraphQL 客户端作为 AWS Amplify API 构建的 React Native 应用程序编写嵌套的 GraphQL 突变。这是我的类型定义文件
type Game @model {
id: ID!
gameId: String!
players: [Player!]!
}
type Player @model {
id: ID!
username: String!
}
这是我尝试创建突变以创建新游戏
import API, { graphqlOperation } from '@aws-amplify/api';
const CreateGame = `
mutation ($gameId: String! $username: String!) {
createGame(input: {
gameId: $gameId,
players: [{ username: $username }]
}) {
id
gameId
players
}
}
`;
const gameObj = {
gameId: 'example_game_id',
username: 'example_username'
};
const queryResp = await API.graphql(graphqlOperation(CreateGame, gameObj));
console.log(queryResp.data);
这是我得到的错误
"Validation error of type WrongType: argument 'input' with value 'ObjectValue{objectFields=[ObjectField{name='gameId', value=VariableReference{name='gameId'}}, ObjectField{name='players', value=ArrayValue{values=[ObjectValue{objectFields=[ObjectField{name='username', value=VariableReference{name='username'}}]}]}}]}' contains a field not in 'CreateGameInput': 'players' @ 'createGame'"