gatsbyjs / gatsby-graphql-toolkit

79 stars 20 forks source link

Cannot query field on type "Query" #89

Open averysmithproductions opened 1 year ago

averysmithproductions commented 1 year ago

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 commented 1 year ago

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.