Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with Variables on POST request #303

Open
timack opened this issue Aug 12, 2019 · 0 comments
Open

Error with Variables on POST request #303

timack opened this issue Aug 12, 2019 · 0 comments

Comments

@timack
Copy link

timack commented Aug 12, 2019

I'm using a React App on the front end to communicate with the CraftQL API endpoint, I'm also using the graphql.js library to make the requests.

I'm getting this error:

Argument 1 passed to GraphQL\Validator\Rules\QueryComplexity::setRawVariableValues() must be of the type array or null, string given, called in /var/www/vendor/webonyx/graphql-php/src/GraphQL.php on line 137

The request is set up on the front end as follows:

    var getEntries = graph(`query fetchSection($section:[SectionsEnum]) {
      entries(section:$section) {
        ... on Blog{
          id
          title
          body {
            content
          }
          blogCategory {
            title
          }
          blogTags {
            title
          }
        }
      }
    }
    `)

    getEntries({
      section: 'blog'
    })

The issue seems to be that that the POST variables data is not json_decoded like the GET variables in ApiController.php:

        if (Craft::$app->request->isPost && $query=Craft::$app->request->post('variables')) {
            $variables = $query;
        }
        else if (Craft::$app->request->isGet && $query=Craft::$app->request->get('variables')) {
            $variables = json_decode($query, true);
        }

Should be:

        if (Craft::$app->request->isPost && $query=Craft::$app->request->post('variables')) {
            $variables = json_decode($query, true);
        }
        else if (Craft::$app->request->isGet && $query=Craft::$app->request->get('variables')) {
            $variables = json_decode($query, true);
        }

Related #71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant