directus / gatsby-source-directus

Source plugin for pulling data into Gatsby from a Directus API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot query field "directus" on type "Query"

treboryx opened this issue · comments

reopen of #16 because it's closed and don't want it to get lost.

Following issue persists after updating everything

 ERROR #85923  GRAPHQL.VALIDATION

There was an error in your GraphQL query:

Cannot query field "directus" on type "Query".

If you don't expect "directus" to exist on the type "Query" it is most likely a typo. However, if you expect "directus" to exist there are a couple of solutions to common problems:

- If you added a new data source and/or changed something inside gatsby-node/gatsby-config, please try a restart of your development server.
- You want to optionally use your field "directus" and right now it is not used anywhere.

It is recommended to explicitly type your GraphQL schema if you want to use optional fields.

File: src\pages\index.jsx:41:5

See our docs page for more info on this error: https://gatsby.dev/creating-type-definitions

@treboryx there was an issue on previous versions that didn't pass the headers correctly and generated this message but that was fixed in the most recent release, if you've updated to the most recent, can you try deleting your .cache folder and re-run please?

@treboryx there was an issue on previous versions that didn't pass the headers correctly and generated this message but that was fixed in the most recent release, if you've updated to the most recent, can you try deleting your .cache folder and re-run please?

I tried all that before bothering you guys.

clean install, removed the .cache dir

I even re-cloned the examples repository in a new directory to test it and I get the same error.

Is it possible that it's something else?

I've run the example four times this morning and didn't repeat. (And deleted .cache each time)

  1. Are the url and credentials correct
  2. Are permissions correct on your site? If using the admin credentials then shouldn't matter but if the credentials are for another user then they'd need to be configured correctly.
  3. If you try to access the graphql using a tool like postman what does it return?

I've run the example four times this morning and didn't repeat. (And deleted .cache each time)

  1. Are the url and credentials correct
  2. Are permissions correct on your site? If using the admin credentials then shouldn't matter but if the credentials are for another user then they'd need to be configured correctly.
  3. If you try to access the graphql using a tool like postman what does it return?

Everything is the default provided by the examples repository. I have ensured that the example credentials work correctly, but the issue persists.

I also tried a GraphQL query on postman, and that seems to work.

I have recorded the whole process, from cloning to running both directus and gatsby, if it's of any help

Code_B0wwiVHkiG.mp4

@treboryx Ok, you're hitting an issue in node 18.

In your .env, replace:

GATSBY_DIRECTUS_URL=http://localhost:8055

with:

GATSBY_DIRECTUS_URL=http://127.0.0.1:8055

I'll push an update shortly that changes this to no longer mention localhost but that's your issue provided the credentials haven't been changed, etc

The examples have been updated as of directus-labs/examples#177 and merged to reflect this URL change everywhere.

Thank you, I thought I had tried this already but I may have not deleted the cache 😅

Yeah that .cache folder can be a major headache with gatsby, all the testing and work done in there lately I automatically delete it before doing anything.

So all working as expected after updating the env var and clearing cache?

Yeah that .cache folder can be a major headache with gatsby, all the testing and work done in there lately I automatically delete it before doing anything.

So all working as expected after updating the env var and clearing cache?

Yep! Everything working as expected