verbb / navigation

A Craft CMS plugin to create navigation menus for your site.
Other
90 stars 23 forks source link

gatsby-source-craft issue: Variable "$id" is not defined #315

Closed zjr closed 1 year ago

zjr commented 1 year ago

Describe the bug

When any navigation is enabled in my schema I get an error in gatsby develop from gatsby-source-craft.

Looks like the following:

 ERROR #11330  PLUGIN

"gatsby-source-craft" threw an error while running the sourceNodes lifecycle:

Variable "$id" is not defined

   517 |     if (remoteConfigVersion !== localConfigVersion || !localContentUpdateTime) {
   518 |         reporter.info("Cached content is unavailable or outdated, sourcing _all_ nodes.");
> 519 |         await sourceAllNodes(config);
       |         ^
   520 |     }
   521 |     else {
   522 |         reporter.info(`Craft config version has not changed since last sourcing. Checking for content changes 
since "${localContentUpdateTime}".`);

Make sure that you don't have a typo somewhere and use valid arguments in sourceNodes lifecycle.
Learn more about sourceNodes here: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#sourceNodes

File: node_modules/gatsby-source-craft/gatsby-node.js:519:9

I checked it in the debugger but I don't really know what I'm looking at. I did see this odd query though:


            fragment _CraftfooterSecondary_NodeID_ on footerSecondary_Node {
                __typename
                id
                siteId
            }
            query NODE_footerSecondary_Node { node(id: $id siteId: $siteId status: null) { ... _CraftfooterSecondary_NodeID_  } }
                query LIST_footerSecondary_Node { nodes( limit: $limit, offset: $offset site: "default" ) { ... _CraftfooterSecondary_NodeID_ } }       

I say odd only because I don't know where footerSecondary_Node is coming from.

Would love to help with a minimal test case but am unfortunately not in a good spot to make one right now, sorry..

Steps to reproduce

  1. Craft CMS with Navigator & Gatsby plugins installed.
  2. Navigation enabled in GraphQL schema.
  3. Gatsby project with gatsby-source-craft.
  4. Try to run gatsby develop.

Craft CMS version

4.2.5.1

Plugin version

2.0.5

Multi-site?

No

Additional context

gatsby-source-craft v3.0.0 (latest at time of writing)

engram-design commented 1 year ago

Is there any error similar to this in your Craft logs (/storage/logs) that might pinpoint the file/line this error occurs on?

zjr commented 1 year ago

I found this in the web log, though I'm not sure how helpful it could be.

2022-09-24 13:30:47 [web.ERROR] [GraphQL\Error\Error] Cannot query field "node" on type "Query".

GraphQL (2:3)
1: query NODE_footerSecondary_Node {
2:   node(id: $id, siteId: $siteId, status: null) {
     ^
3:     remoteTypeName: __typename
 {"memory":12750032,"exception":"[object] (GraphQL\\Error\\Error(code: 0): Cannot query field \"node\" on type \"Query\". at /var/www/html/vendor/webonyx/graphql-php/src/Validator/Rules/FieldsOnCorrectType.php:57)"} 
2022-09-24 13:30:47 [web.ERROR] [GraphQL\Error\Error] Variable "$id" is not defined by operation "NODE_footerSecondary_Node".

GraphQL (2:12)
1: query NODE_footerSecondary_Node {
2:   node(id: $id, siteId: $siteId, status: null) {
              ^
3:     remoteTypeName: __typename

GraphQL (1:1)
1: query NODE_footerSecondary_Node {
   ^
2:   node(id: $id, siteId: $siteId, status: null) {
 {"memory":12750440,"exception":"[object] (GraphQL\\Error\\Error(code: 0): Variable \"$id\" is not defined by operation \"NODE_footerSecondary_Node\". at /var/www/html/vendor/webonyx/graphql-php/src/Validator/Rules/NoUndefinedVariables.php:40)"} 
2022-09-24 13:30:47 [web.ERROR] [GraphQL\Error\Error] Variable "$siteId" is not defined by operation "NODE_footerSecondary_Node".

GraphQL (2:25)
1: query NODE_footerSecondary_Node {
2:   node(id: $id, siteId: $siteId, status: null) {
                           ^
3:     remoteTypeName: __typename

GraphQL (1:1)
1: query NODE_footerSecondary_Node {
   ^
2:   node(id: $id, siteId: $siteId, status: null) {
 {"memory":12750848,"exception":"[object] (GraphQL\\Error\\Error(code: 0): Variable \"$siteId\" is not defined by operation \"NODE_footerSecondary_Node\". at /var/www/html/vendor/webonyx/graphql-php/src/Validator/Rules/NoUndefinedVariables.php:40)"} 
2022-09-24 13:30:47 [web.ERROR] [GraphQL\Error\Error] Cannot query field "nodes" on type "Query".

GraphQL (10:3)
 9: query LIST_footerSecondary_Node {
10:   nodes(limit: $limit, offset: $offset, site: "default") {
      ^
11:     remoteTypeName: __typename
 {"memory":12751256,"exception":"[object] (GraphQL\\Error\\Error(code: 0): Cannot query field \"nodes\" on type \"Query\". at /var/www/html/vendor/webonyx/graphql-php/src/Validator/Rules/FieldsOnCorrectType.php:57)"} 
2022-09-24 13:30:47 [web.ERROR] [GraphQL\Error\Error] Variable "$limit" is not defined by operation "LIST_footerSecondary_Node".

GraphQL (10:16)
 9: query LIST_footerSecondary_Node {
10:   nodes(limit: $limit, offset: $offset, site: "default") {
                   ^
11:     remoteTypeName: __typename

GraphQL (9:1)
 8: 
 9: query LIST_footerSecondary_Node {
    ^
10:   nodes(limit: $limit, offset: $offset, site: "default") {
 {"memory":12751664,"exception":"[object] (GraphQL\\Error\\Error(code: 0): Variable \"$limit\" is not defined by operation \"LIST_footerSecondary_Node\". at /var/www/html/vendor/webonyx/graphql-php/src/Validator/Rules/NoUndefinedVariables.php:40)"} 
2022-09-24 13:30:47 [web.ERROR] [GraphQL\Error\Error] Variable "$offset" is not defined by operation "LIST_footerSecondary_Node".

GraphQL (10:32)
 9: query LIST_footerSecondary_Node {
10:   nodes(limit: $limit, offset: $offset, site: "default") {
                                   ^
11:     remoteTypeName: __typename

GraphQL (9:1)
 8: 
 9: query LIST_footerSecondary_Node {
    ^
10:   nodes(limit: $limit, offset: $offset, site: "default") {
 {"memory":12752072,"exception":"[object] (GraphQL\\Error\\Error(code: 0): Variable \"$offset\" is not defined by operation \"LIST_footerSecondary_Node\". at /var/www/html/vendor/webonyx/graphql-php/src/Validator/Rules/NoUndefinedVariables.php:40)"} 
engram-design commented 1 year ago

So the 2022-09-24 13:30:47 [web.ERROR] [GraphQL\Error\Error] Cannot query field "node" on type "Query". line refers to queries using:

node(id: $id, siteId: $siteId, status: null) {
    ...
}

Instead of

navigationNode(id: $id, siteId: $siteId, status: null) {
    ...
}

Which is covered in the Craft 4 upgrade docs. Sounds like that might not have been changed?

https://verbb.io/craft-plugins/navigation/docs/get-started/upgrading-from-v1#queries

zjr commented 1 year ago

I'll look further later, but I installed Craft 4 & this version of Navigation less than a week ago, so an upgrading problem doesn't seem right?

engram-design commented 1 year ago

Ah, my mistake! I forgot to adjust these names specifically for the Gatsby integration. Should be fixed for the next release. To get the fix early, change your verbb/navigation requirement in composer.json to:

"require": {
  "verbb/navigation": "dev-craft-4 as 2.0.5",
  "...": "..."
}

Then run composer update.

engram-design commented 1 year ago

Fixed in 2.0.6

zjr commented 1 year ago

@engram-design thank you!