react apollo-client 发送graphql请求
作为nest.js+graphql的新手做一个记录,在使用Apollo- client发送graphql请求时遇到的一个小问题
gql
mutation AddSourceApi ($input:CreateSourceapiInput!){ createSourceapi(createSourceapiInput:$input){ apiName } }
useMutation
const [addApi] = useMutation(addSourceApi,{ onCompleted:res=>{ console.log(res) } })
方法调用
addApi({ variables:{ input:{ apiName:"掘金", description:"代码不止,掘金不停", sourceApi:"https://juejin.cn" } } })
问题记录
gql中 operationName (AddSourceApi)为自定义的,当是参数aaa,则variables:{aaa:{}} ,否则会报类型不正确,错误提示不是很明显