我的突变方案:
mutation edit($id: Int!) {
user_edit(id:$id) {
user_name
}
}
查询变量如下
{
"id": 1
}
我将它与 laravel-graphql 一起使用。这是我的定义user_edit
class UserEdit extends Mutation
{
protected $attributes = [
'name' => 'UserEdit',
'description' => 'A mutation'
];
public function type()
{
return GraphQL::type('UserInfo');
}
public function args()
{
return [
'id' => [
'type' => Type::int(),
],
];
}
public function resolve($root, $args, $context, ResolveInfo $info)
{
var_dump($args);exit;
$data = User::find($args['id']);
return $data;
}
}
我使用我的查询字符串来请求 graphql 服务器,然后服务器返回我的错误
{
"data": null,
"errors": [
{
"message": "Variable \"$edit1\" of required type \"Int!\" was not provided.",
"locations": [
{
"line": 1,
"column": 11
}
]
}
]
}
我尝试了很多东西并阅读了 github 上的文档 [ https://github.com/Folkloreatelier/laravel-graphql#creating-a-mutation][1]
并阅读了graphql网站的文档,并以多种方式更改了我的args定义样式,但都失败了,奇怪的是我可以获取args但使用静态变量,如follow
mutation edit{
user_edit(id:1) {
user_name
}
}
然后它起作用了!我试图胡思乱想,但对此一无所知。我想我真的需要帮助