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

Cannot query field "entries" on type "Query" #322

Open
modulareverything opened this issue Sep 21, 2019 · 6 comments
Open

Cannot query field "entries" on type "Query" #322

modulareverything opened this issue Sep 21, 2019 · 6 comments

Comments

@modulareverything
Copy link

Following instructions in this tutorial, I have Craft setup with Gatsby and CraftQL.

The problem I have is if I use the CraftQL interface in the admin panel and run a query, I get my results. When I try and run the same query in GraphiQL I get an error:

"Cannot query field \"entries\" on type \"Query\"."

Similarly, if I run this directly in React I get the same error in the console.

Am I missing something here? Hopefully, someone can help clear this up as I'm very lost.

@narration-sd
Copy link
Contributor

It's a little confusing what you mean by the different GraphjQLs, but that problem sounds like you don't have permission set for elements and fields you need, on the token you're using for access.

I'm away from keyboard, but you should find what you need from the CP/Settings/CraftQL page.

Find your token listed there. Then look too the right - there's a link or abutting there.

This will take you to a page of detailed permissions. Select those that apply and save.

That should get your query able to work from that token...

@modulareverything
Copy link
Author

Thanks @narration-sd but I did this already. Just for the purpose of testing, I enabled everything and still run into the same trouble.

@narration-sd
Copy link
Contributor

narration-sd commented Sep 22, 2019

Ok, but this is not much information to volunteer a hand to, Crish.

'Graphiql' is a generic term -- it's the basis of most GraphQL viewers, so I don't know what you're trying to view from. From Gatsby dev, indeed it's called from ___graphql, but it does have the name GraphiQL on its title, so that's probably what you mean.

And 'React' code -- some that's independent, or something written inside Gatsby? Because the queries will be different, as you'll discover if you haven't yet. Looking over that tutorial you mention, I guess it's the code there. Which I wouldn't use in an actual Gatsby page -- should be a page query, rather than static, for reasons and some to come.

Still, this error is pretty clear. And it's also one that wouldn't be expected due to any bug in CraftQL. It's meaning is as I mentioned. No entity of the name 'entries' is available to you from the Schema which is the root of GraphQL operations. Which in turn means either that the Schema is being built from something other than Craft, or that you aren't permitted to see that entity. But from Craft, 'entries' is always available, even if you don't yet have any.

Two things occur to me. The first is that you should be using the Documentation or Schema areas of your proper GraphiQL viewer, where you can see exactly what's in the Schema-in-use: what you're permitted to see of the Schema you're connected to.

The other is that if you are confident you've set up and are using a properly permitted access token for your connection (counts just as much in React, Vue, any other code as it would in Gatsby), then maybe you're connecting to the wrong GraphQL server. One that doesn't allow you these permissions.

How that could occur is that there are now two possible GraphQL engines for Craft. One is the CraftQL plugin, and the other is the very fresh, new, and incomplete internal GraphQL. Both of these can operate on the same installation.

So my intuition is that you've permitted one, but are connecting to the other. The way you separate them is by setting a unique routing path for the one you want. I'd be sure to stick with CraftQL for Gatsby, as the internal server lacks important abilities yet for Gatsby -- I'm working with the developer on those.

So I would set CraftQL to its own unique access path, which you do by following the instructions on the CraftQL doc, the Readme on its Github page.

You just make a simple setting in a config file for this. Something like 'cqapi' instead of the plain 'api' it defaults to. Adjust to the same in your Gatsby gatsby-config.js for the plugin, then see if query results in explore and then your prototype app don't look more sensible.

Be sure to let us know if this solves the problem, as I've seen one other person get into the issue of 'which server' already, and there's an easy fix the developer could make, thanks.

@narration-sd
Copy link
Contributor

n.b. I've updated a few things at the beginning of today's reply, for clarity to your case. The suggested reason and fix remains the same...

@modulareverything
Copy link
Author

@narration-sd thanks for taking the time to explain this to me. This isn't a subject I know much about at this point.

Changing 'api' to 'cqapi' seemed to work — is this because another instance of GraphQL is using 'api' so setting it to something unique stops it from being overwritten?

@narration-sd
Copy link
Contributor

@n0k5 Great, glad you're on the air. This is a real problem that can be avoided, with you being the second person caught in a week, and I'll talk to the developer about it.

is this because another instance of GraphQL is using 'api'...

Yes. What's happening at present is that both GraphQL servers are setting up the Craft route api to channel to themselves, and the last one to do this wins. Probably Craft's internal GraphQL loads after plugins are initialized, so it wins. Setting a different route for the plugin avoids the api route,

subjects and knowing about

Well, we're all learning, all of the time -- doing this and becoming reasonably thoughtful about wherre to do this is the nature of working with software today, isn't it. This problem is what anyone would call 'obscure', and you'd only know what I explained if you'd been pretty deeply involved with the source code for GraphQL as well as using it, so don't feel badly for sure.

Best fortune on moving on, and I'll go write this up for the developer....

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