带有AWS Amplify的嵌套GraphQL突变

时间:2020-06-08 12:57:50

标签: graphql aws-amplify aws-amplify-sdk-js

我正在努力为正在使用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'"

0 个答案:

没有答案