You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apollo Client GraphQL查询变量类型错误:必填ID未提供

Fix for "Variable $id of required type ID! was not provided" Error

Hey there, I see exactly what's going wrong here! That error pops up because you're passing a raw string to the variables parameter in your Apollo mutation, but Apollo expects an object with key-value pairs that map to your GraphQL mutation variables.

The Root Cause

Your GraphQL mutation defines a required variable $id: ID!, but in your Vuex Action, you're passing id.toString() directly as the variables value. This is just a plain string, so Apollo can't associate it with the $id variable your mutation is looking for—hence the "variable not provided" error.

The Fix

Update the variables parameter to be an object where the key matches the variable name from your mutation (id), and the value is your formatted ID string:

deleteCustomer(vuexContext, id){
  return apollo
    .mutate({
      mutation: DELETE_CUSTOMER,
      variables: { id: id.toString() } // Wrap the ID in an object with the correct key
    })
    .then(()=>{
      vuexContext.commit('deleteCustomer', id.toString());
    })
    .catch((err) => {
      throw err;
    });
}

Why This Works

GraphQL uses the keys in the variables object to match up with the variables defined in your mutation. By passing { id: id.toString() }, you're explicitly telling Apollo: "Hey, use this string value for the $id variable in my mutation." This clears up the confusion and lets the mutation run as expected.

内容的提问来源于stack exchange,提问作者junaid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:10:43