[英]Apollo - GraphQLError: Syntax Error: Expected $, found Name
I'm using GraphQL in ui/playground, with the syntax bellow, works pretty well.我在 ui/playground 中使用GraphQL ,语法如下,效果很好。
mutation {
createUnit(unit: {name: "hehehe great!!!"}) {
id,
name
}
}
My doubt is, how can I use GraphQL in Apollo Client, I found something like that:我的疑问是,如何在 Apollo Client 中使用 GraphQL,我发现了类似的内容:
mutation createUnit(unit: {name: String!}) {
createUnit(unit: {name: "looks great!!!"}) {
id,
name
}
}
But unfortunately I'm getting the error:但不幸的是我收到错误:
GraphQLError : Syntax Error: Expected $, found Name "unit" GraphQLError :语法错误:预期 $,找到名称“单位”
Make sure you have defined the type Unit
and added the createUnit
type as a mutation in the resolvers确保您已定义类型
Unit
并将createUnit
类型添加为解析器中的突变
module.exports.Mutation = {
createUnit
}
to use it in the graphql playground you just have to specify the variables you are going to use in the mutation like this要在 graphql 操场中使用它,您只需要像这样指定要在突变中使用的变量
mutation($unit: Unit){
createUnit(unit: $unit){
id
name
}
}
and in the variables add :并在变量中添加:
{
"unit": {
name: "looks great!!!"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.