1
votes

My mutation scheme:

mutation edit($id: Int!) {
  user_edit(id:$id) {
    user_name
  }
}

query variable is follow

{
  "id": 1
}

I use this with laravel-graphql. Here is my definition of 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;
    }
}

I use my query string to request the graphql server, then server return my error

{
  "data": null,
  "errors": [
    {
      "message": "Variable \"$edit1\" of required type \"Int!\" was not provided.",
      "locations": [
        {
          "line": 1,
          "column": 11
        }
      ]
    }
  ]
}

l tried a lot things and read the document on github [https://github.com/Folkloreatelier/laravel-graphql#creating-a-mutation][1]

and read the document of graphql's website ,and change my args definition style in many ways, but all failed, and Strange is l can get args but use static variable like follow

mutation edit{
      user_edit(id:1) {
        user_name
      }
    }

and then it worked! l tried to goole but get nothing about this. l think l really need some help

2
Please post the request you are making. You could also just try making a POST request instead -- while GET requests are technically supported, POST requests are used by convention.Daniel Rearden

2 Answers

0
votes

Comparing the docs vs your code, seems in your args method, you needs to specify the arg name, like so:

public function args()
    {
        return [
            'id' => [
                'type' => Type::int(),
                'name' => 'id'
            ],
        ];
    }

Ref: https://github.com/Folkloreatelier/laravel-graphql#creating-a-query

Hope this help!

Regards

0
votes

Reason is because of lower version, if you install laravel-graphql version with '~1.0.0', go to modify config/graphql.php

// The name of the input that contain variables when you query the endpoint.
// Some library use "variables", you can change it here. "params" will stay
// the default for now but will be changed to "variables" in the next major
// release.

'variables_input_name' => 'variables', // modify here from 'params' to 'variables'