GraphQl Apollo-Client Usemontain带有GQL,GraphQlinputObjectType不检查输入对象字段

发布于 2025-02-07 04:53:18 字数 745 浏览 2 评论 0原文

任何人都可以帮助我了解如何验证Apollo客户端上的输入参数对象类型,我正在尝试确保通过输入对象上的其他字段失败。但是即使我传递了其他字段,它也有效(注意:我想要前端的验证,而不是在服务器上)

const mutationInput = new GraphQLObjectType({
    name: 'mutationInput',
    fields: {
        Id: String,
        statusCode: String,
    }
});

const GET_DATA = gql`
  mutation($in: ${mutationInput}!){
    getData(in: $in) {
      status
      }
    }
  }`;

//usage 
const [getData, { error,loading }] = useMutation(
    GET_DATA,
    {
       ...
     }
   )

  getData({
      variables: {
        in: {
           statusCode:"OK",
           ID:"azz12",
           extraField:"some value" //Validation needs to fail as this field is not defined on input object, but never fails on front end
         }
      }

could anyone please help me understand on how to validate the input argument object type on apollo client , i am trying to make sure that passing additional fields on the input object fails the query . But it works even if i pass additional fields (Note : I want the validation on front end and not on the server)

const mutationInput = new GraphQLObjectType({
    name: 'mutationInput',
    fields: {
        Id: String,
        statusCode: String,
    }
});

const GET_DATA = gql`
  mutation($in: ${mutationInput}!){
    getData(in: $in) {
      status
      }
    }
  }`;

//usage 
const [getData, { error,loading }] = useMutation(
    GET_DATA,
    {
       ...
     }
   )

  getData({
      variables: {
        in: {
           statusCode:"OK",
           ID:"azz12",
           extraField:"some value" //Validation needs to fail as this field is not defined on input object, but never fails on front end
         }
      }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文