Errors: Must provide an operation.
mminglis opened this issue · 4 comments
Getting:
{"errors":[{"message":"Must provide an operation."}]}when following all instructions to access qraphql on a page. The query is:
{
home {
list {
title
}
}
}Running pw version 3.0.42, most recent ProcessGraphQL, on fresh "Classic" profile.
Thank you for opening an issue!
That message says that the module is working but did receive empty query variable, or didn't receive it at all. Are you making this request via GraphiQL interface? The GraphiQL interface should be located at Setup -> GraphQL in your admin panel.
If you are making request from your own script, like jQuery, you should send a query parameter with a string in it. Should look something like this.
$.post(
'/processwire/setup/graphql/', // change this line if you changed admin path, like '/admin/setup/graphql/'
{
query: "{ home {list { title } } }"
},
function (res) {
console.log(res);
}
);Thank you for the module and taking the time to help!
I think I am just confused and perhaps have the wrong expectations.
With a template graphql containing:
$ProcessGraphQL = $modules->get('ProcessGraphQL');
echo $ProcessGraphQL->executeGraphQL();and a page /graphql I get the error mentioned above.
Initially I was expecting this to echo the query defined in the GraphiQL interface.
Your example JQuery post works fine, but changing to the public url I have defined returns the same error.
$.post(
'/graphql/',
{
query: "{ home {list { title } } }"
},
function (res) {
console.log(res);
}
);Thanks again.
I think I might know what it is. If you are requesting to /graphql instead of /graphql/ (notice the slash in the end) then you will get this error. Because ProcessWire redirects urls that do not end with / to the same urls with the /. Take a look at your network requests in browser developer tools. Here is what might be happening.
First request sends the query. But it won't reach your template file, ProcessWire returns 301.
Second request reaches your template, but there is no query in it.
Is this your case?
Right you are, I thought I double checked that testing earlier. Thanks for your help! Looking forward to exploring more now.

