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

Referencing non-existant Gatsby Types supresses develop and build errors #38531

Open
2 tasks done
T-Fletcher opened this issue Sep 8, 2023 · 0 comments
Open
2 tasks done
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby

Comments

@T-Fletcher
Copy link

T-Fletcher commented Sep 8, 2023

Preliminary Checks

Description

My setup is apparently pretty unique, so I'm unsure if this issue is present in the latest version of Gatsby;

I have a gatsbyjs front end that pulls in data from a single Drupal 9 instance, which filters the exposed data via the Gatsby Endpoints module.

As it serves to multiple websites with different content, there are GraphQL queries in the front end that refer to content only present on some sites. When building a site that doesn't contain at least one instance of each piece of content, the builds fail. I'm currently handling this with the gatsby-schema-snapshot plugin to get around this.

I found featuring any queries on non-existent Types causes any Gatsby errors to be hidden in the build output.

gatsby-develop can proceed past this error, but gatsby-build fails and builds cannot complete, making it a blocker.

Reproduction Link

no repo, sorry

Steps to Reproduce

  1. Spin up a fresh Gatsby v3.15 site
  2. Create a component that includes a GraphQL fragment referencing a non-existent Type e.g.
import React from 'react';
import { graphql } from 'gatsby';

export const ErrorParagraph = ({ node }) => {
  return `<p>Error text</p>`;
};

export const fragment = graphql`
  fragment ParagraphError on paragraph__error {
    id
  }
`;
  1. Run gatsby develop --verbose

Expected Result

The build logs should show the errors arising from the non-existent Type during the "waitingPendingQueries" stage:

...
verbose Transition to "runningQueries" > "waitingPendingQueries"
verbose [typegen] Generate type definitions to .../my-project/src/__generated__/gatsby-types.ts. (language:
TypeScript)
GraphQLError [Object]: Unknown type "paragraph__error". Did you mean "paragraph__abc123"...?
          at Object.NamedType (.../my-project/node_modules/graphql/validation/rules/KnownTypeNamesRule.js:57:29)
          at Object.enter
(.../my-project/node_modules/graphql/language/visitor.js:323:29)
          at Object.enter
(.../my-project/node_modules/graphql/utilities/TypeInfo.js:370:25)
          at visit
(.../my-project/node_modules/graphql/language/visitor.js:243:26)
          at Object.validate
(.../my-project/node_modules/graphql/validation/validate.js:69:24)
          at
my-project/dist/utils/src/validate-documents.js:30:24
          at Array.map (<anonymous>)
          at Object.validateGraphQlDocuments
(.../my-project/dist/utils/src/validate-documents.js:16:37)
          at codegen
(.../my-project/dist/graphql-codegen-core/src/codegen.js:56:30)
          at my-project/node_modules/gatsby-plugin-typegen/workers/codegen.js:139:44
          at my-project/node_modules/gatsby-plugin-typegen/node_modules/async/dist/async.js:151:38
          at Object.process (.../my-project/node_modules/gatsby-plugin-typegen/node_modules/async/dist/async.js:1679:21)
          at my-project/node_modules/gatsby-plugin-typegen/node_modules/async/dist/async.js:1571:19
          at my-project/node_modules/gatsby-plugin-typegen/node_modules/async/dist/async.js:327:20
          at invokeCallback (.../my-project/node_modules/gatsby-plugin-typegen/node_modules/async/dist/async.js:182:13)
          at my-project/node_modules/gatsby-plugin-typegen/node
_modules/async/dist/async.js:174:13
    ]

Actual Result

The build logs omit the errors despite them having been thrown, giving the user no idea indication the issue is related to their code:

verbose Transition to "runningQueries" > "waitingPendingQueries"
verbose [typegen] Generate type definitions to .../my-project/src/__generated__/gatsby-types.ts. (language: TypeScript)

 ERROR 

[typegen] An error on codegen Cannot read properties of undefined (reading 'forEach')


  TypeError: Cannot read properties of undefined (reading 'forEach')
  
  - validate-documents.js:51 Object.checkValidationErrors
    .../my-project/dist/utils/src/validate-documents.js:51:14
  
  - codegen.js:63 codegen
    .../my-project/dist/graphql-codegen-core/src/codegen.js:63:9
  
  - task_queues:61 runNextTicks
    node:internal/process/task_queues:61:5
  
  - timers:499 processTimers
    node:internal/timers:499:9
  
  - codegen.js:139 
    [frontend]/[gatsby-plugin-typegen]/workers/codegen.js:139:20
  

verbose Transition to "runningQueries" > "writingRequires"

Note the actual queued errors expected can be exposed by adding console.log()s to my-project/node_modules/@graphql-tools/utils/index.cjs.js:

function checkValidationErrors(loadDocumentErrors) {
    console.log('********************* ERRORS ***********************');
    console.log(loadDocumentErrors)
    if (loadDocumentErrors.length > 0) {
        const errors = [];
        for (const loadDocumentError of loadDocumentErrors) {

Environment

System:
    OS: macOS 13.5.1
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.16.0/bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
  Languages:
    Python: 2.7.13 - /Applications/MAMP/bin/apache2/bin/python
  Browsers:
    Chrome: 116.0.5845.179
    Firefox: 117.0
    Safari: 16.6
  npmPackages:
    gatsby: ^3.15.0 => 3.15.0 
    gatsby-image: ^3.11.0 => 3.11.0 
    gatsby-plugin-gatsby-cloud: 2.8.1 => 2.8.1 
    gatsby-plugin-google-analytics: ^3.8.0 => 3.8.0 
    gatsby-plugin-google-tagmanager: 3.14.0 => 3.14.0 
    gatsby-plugin-image: ^1.14.2 => 1.15.0 
    gatsby-plugin-layout: 2.8.0 => 2.8.0 
    gatsby-plugin-manifest: ^3.13.0 => 3.15.0 
    gatsby-plugin-meta-redirect: ^1.1.1 => 1.1.1 
    gatsby-plugin-react-helmet: ^4.13.0 => 4.15.0 
    gatsby-plugin-remove-serviceworker: ^1.0.0 => 1.0.0 
    gatsby-plugin-sass: 4.8.0 => 4.8.0 
    gatsby-plugin-schema-snapshot: ^2.12.0 => 2.12.0 
    gatsby-plugin-sharp: ^3.14.3 => 3.15.0 
    gatsby-plugin-sitemap: 4.4.0 => 4.4.0 
    gatsby-plugin-typegen: 2.2.4 => 2.2.4 
    gatsby-remark-embed-video: ^3.1.1 => 3.2.1 
    gatsby-source-drupal: 4.14.1 => 4.14.1 
    gatsby-source-filesystem: ^3.13.0 => 3.15.0 
    gatsby-transformer-sharp: ^3.13.0 => 3.15.0

Config Flags

none

@T-Fletcher T-Fletcher added the type: bug An issue or pull request relating to a bug in Gatsby label Sep 8, 2023
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 8, 2023
@T-Fletcher T-Fletcher changed the title Enabling gatsby-schema-snapshot plugin supresses develop and build errors Referencing non-existant Gatsby Types supresses develop and build errors Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

1 participant