0
0

GraphQL error: Variable 'hoge' has coerced Null value for NonNull type 'hoge!'

Posted at

環境

  • NodeJS
  • ローカル環境
  • AWSAppSyncClient利用

事象

AWSAppSyncClient.mutate実行時に掲題のエラーが出る。

原因

GraphQLのmutation queryの引数名が一致していなかった。

対応

  • input, conditionの文言は変えないで統一
    • graphql側のinput, conditionという引数名は統一
    • NodeJS(呼び出し側)のinput, conditionも統一

対応後のイメージ


type Mutation {
  updateHoge(input: UpdateHogeInput!, 
  condition: ModelHogeConditionInput): Hoge 
  @aws_api_key @aws_iam @aws_cognito_user_pools
}
const updateHoge =/* GraphQL */ `mutation Hoge(
    $condition: ModelHogeConditionInput
    $input: UpdateHogeInput!
){
    updateHoge(condition: $condition,
        input: $input){
        id
    }
}
`
async function disableHoge(updateHogeInput: UpdateHogeInput, updateTargetFieldValue:any) {
    return await client.mutate<Hoge>({
        mutation: gql(updateHoge),
        variables: {
            condition: {
                hogehoge: {eq: updateHogeInput.hogehoge} as ModelStringInput
            },
            input: {
                ...updateHogeInput,
                updateTargetField: updateTargetFieldValue
            }
        }
    })
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0