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 on type "Query" #89

Open
averysmithproductions opened this issue Apr 21, 2023 · 1 comment
Open

Cannot query field on type "Query" #89

averysmithproductions opened this issue Apr 21, 2023 · 1 comment

Comments

@averysmithproductions
Copy link

averysmithproductions commented Apr 21, 2023

I have used the https://github.com/vladar/gatsby-graphql-toolkit-examples/tree/master/craft-cms example and seem to run into an issue...

in the craft-cms graphiql editor, the following graphql query:

query {
  globalSet {
    id
  }
}

returns this data:

{
  "data": {
    "globalSet": {
      "id": "70"
    }
  }
}

But in gatsby, using the gatsby-graphql-toolkit to create the data layer, the same query

const query = useStaticQuery(graphql`
  query {
    globalSet {
      id
    }
  }
`);

results in the following error:

There was an error in your GraphQL query:

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

If you don't expect "globalSet" to exist on the type "Query" it is most likely a
 typo. However, if you expect "globalSet" 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 "globalSet" 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/components/molecules/autocomplete/autocomplete.jsx:157:9

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

I have gone through the Troubleshooting instructions and believe that there is an issue with the schema customization logic, which is why I'm filing this issue.

I hope there is someone who can assist! Been trying to resolve this for a couple of weeks.

Using:
Gatsby 5.8.0
Gatsby Graphql Source Toolkit 2.0.4

@tetsuoreynolds
Copy link

tetsuoreynolds commented May 1, 2023

In that example, line 25 sets the Gatsby data prefix so you should see it in Gatsby GraphQL Inspector under "Craft_globalSet".

If you see it in GraphQLI, update the Static Query with the name-spaced prefix reference:
const query = useStaticQuery(graphql` query { Craft_globalSet { id } } `);

If you don't see it in GraphQLI there's probably something wrong with your source GraphQL processing and you should check the printed TypeDefs file.

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