Skip to content

Errors: Must provide an operation. #1

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

Closed
mminglis opened this issue Feb 4, 2017 · 4 comments
Closed

Errors: Must provide an operation. #1

mminglis opened this issue Feb 4, 2017 · 4 comments

Comments

@mminglis
Copy link

mminglis commented Feb 4, 2017

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.

@dadish
Copy link
Owner

dadish commented Feb 5, 2017

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);
  }
);

@mminglis
Copy link
Author

mminglis commented Feb 5, 2017

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.

@dadish
Copy link
Owner

dadish commented Feb 5, 2017

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.

with_query

Second request reaches your template, but there is no query in it.

without_query

Is this your case?

@mminglis
Copy link
Author

mminglis commented Feb 5, 2017

Right you are, I thought I double checked that testing earlier. Thanks for your help! Looking forward to exploring more now.

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

2 participants