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

gatsby-source-graphql breaks after upgrading Gatsby from v2.1 to v2.2: GraphQLError: Unknown type #12717

Closed
grubersjoe opened this issue Mar 21, 2019 · 10 comments · Fixed by #12721

Comments

@grubersjoe
Copy link

grubersjoe commented Mar 21, 2019

Description

After upgrading from Gatsby v2.1.31 to v2.2.3 my project fails to compile all of a sudden, because the gatsby-source-graphql plugin throws the following error. I'm using this plugin to query data from the GitHub GraphQL API (v4). No source code has been changed, and I checked in the online explorer of GitHub's API: the query is still valid. I suppose the origin of this issue might lie in the new schema customization API introduced in v2.2.

After downgrading to Gatsby v2.1 everything works again (also with latest version of gatsby-source-graphql = 2.0.15).

yarn run v1.15.2
$ gatsby develop
success open and validate gatsby-configs — 0.014 s
success load plugins — 0.307 s
success onPreInit — 0.678 s
info One or more of your plugins have changed since the last time you ran Gatsby. As
a precaution, we're deleting your site's cache to ensure there's not any stale
data
success initialize cache — 0.011 s
success copy gatsby files — 0.016 s
success onPreBootstrap — 0.009 s
success source and transform nodes — 2.587 s
success building schema — 1.040 s
error gatsby-node.js returned an error


  GraphQLError: Unknown type "GitHub_Blob". Did you mean "GitHub_Blame", "GitHub_Node", "GitHub_URI", "GitHub_App", or "GitHub_HTML"?
  
  - debuggability.js:313 Promise._execute
    [grubersjoe.de-current]/[bluebird]/js/release/debuggability.js:313:9
  
  - promise.js:483 Promise._resolveFromExecutor
    [grubersjoe.de-current]/[bluebird]/js/release/promise.js:483:18
  
  - promise.js:79 new Promise
    [grubersjoe.de-current]/[bluebird]/js/release/promise.js:79:10
  
  - index.js:358 graphqlRunner
    [grubersjoe.de-current]/[gatsby]/dist/bootstrap/index.js:358:14
  
  - gatsby-node.js:16 Object.exports.createPages
    /home/jogu/git/_private/grubersjoe.de-current/gatsby-node.js:16:10
  
  - api-runner-node.js:202 runAPI
    [grubersjoe.de-current]/[gatsby]/dist/utils/api-runner-node.js:202:37
  
  - api-runner-node.js:340 resolve
    [grubersjoe.de-current]/[gatsby]/dist/utils/api-runner-node.js:340:19
  
  - debuggability.js:313 Promise._execute
    [grubersjoe.de-current]/[bluebird]/js/release/debuggability.js:313:9
  

success createPages — 0.086 s
success createPagesStatefully — 0.044 s
success onPreExtractQueries — 0.001 s
success update schema — 0.077 s
error GraphQL Error Unknown type "GitHub_Blob". Did you mean "GitHub_Blame", "GitHub_Node", "GitHub_URI", "GitHub_App", or "GitHub_HTML"?

  file: <path>/Projects.tsx

  60 |                             name
  61 |                             email
  62 |                           }
  63 |                         }
  64 |                       }
  65 |                     }
  66 |                   }
  67 |                 }
  68 |               }
  69 |               readme: object(expression: "master:README.md") {
> 70 |                 ... on GitHub_Blob {
     |                        ^
  71 |                   text
  72 |                 }
  73 |               }
  74 |             }
  75 |           }
  76 |         }
  77 |       }
  78 |     }
  79 |   }
  80 | 

success extract queries from components — 0.099 s
⠁ (node:8313) DeprecationWarning: Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.
success run graphql queries — 0.014 s — 7/7 532.23 queries/second
success write out page data — 0.013 s
success write out redirect data — 0.002 s
success onPostBootstrap — 0.180 s

info bootstrap finished - 6.752145856 s


With `useBuiltIns` option, required direct setting of `corejs` option

Done in 8.32s.

Steps to reproduce

The source code of my website is public, so you can simply clone the repo out and run below command: https://github.com/grubersjoe/grubersjoe.de

A GitHub access token is required with the following permissions to authenticate:

  • read:org
  • read:user Read all user profile data
  • user:email Access user email addresses (read-only)
  • user:follow Follow and unfollow users
GITHUB_TOKEN=<token> yarn dev

An example query, which fails:

{
  github {
    viewer {
      repositories(first: 10, privacy: PUBLIC) {
        edges {
          node {
            name
            readme: object(expression: "master:README.md") {
              ... on GitHub_Blob {
                text
              }
            }
          }
        }
      }
    }
  }
}

Expected result

The project should compile without complaining GraphQL Error Unknown type "GitHub_Blob". Blob is a valid object: https://developer.github.com/v4/object/blob/. All objects processed by the source plugin are prefixed with GitHub_, as configured in gatsby-config.js (typeName):

 plugins: [
    {
      resolve: 'gatsby-source-graphql',
      options: {
        fieldName: 'github',
        typeName: 'GitHub',
        createLink: () => createHttpLink({
          uri: 'https://api.github.com/graphql',
          headers: {
            Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
          },
          fetch,
        }),
      },
    },
    // ...

Actual result

The plugin is unable to correctly resolve the GraphQL schema, thus breaking the build. See above output.

Environment


  System:
    OS: Linux 5.0 Arch Linux undefined
    CPU: (4) x64 Intel(R) Core(TM) i5-4210M CPU @ 2.60GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 11.12.0 - /usr/bin/node
    Yarn: 1.15.2 - /usr/bin/yarn
    npm: 6.9.0 - /usr/bin/npm
  Languages:
    Python: 3.7.2 - /usr/bin/python
  Browsers:
    Firefox: 66.0
  npmPackages:
    gatsby: ^2.0.52 => 2.2.3 
    gatsby-image: ^2.0.20 => 2.0.34 
    gatsby-plugin-feed: ^2.0.11 => 2.0.15 
    gatsby-plugin-google-analytics: ^2.0.9 => 2.0.17 
    gatsby-plugin-manifest: ^2.0.13 => 2.0.24 
    gatsby-plugin-offline: ^2.0.15 => 2.0.25 
    gatsby-plugin-react-helmet: ^3.0.2 => 3.0.10 
    gatsby-plugin-sharp: ^2.0.13 => 2.0.30 
    gatsby-plugin-sitemap: ^2.0.2 => 2.0.10 
    gatsby-plugin-styled-components: ^3.0.2 => 3.0.7 
    gatsby-plugin-typescript: ^2.0.1 => 2.0.11 
    gatsby-remark-copy-linked-files: ^2.0.8 => 2.0.11 
    gatsby-remark-external-links: ^0.0.4 => 0.0.4 
    gatsby-remark-images: ^3.0.1 => 3.0.10 
    gatsby-remark-prismjs: ^3.2.0 => 3.2.6 
    gatsby-remark-responsive-iframe: ^2.0.8 => 2.1.1 
    gatsby-remark-smartypants: ^2.0.7 => 2.0.9 
    gatsby-source-filesystem: ^2.0.8 => 2.0.27 
    gatsby-source-graphql: ^2.0.6 => 2.0.15 
    gatsby-transformer-remark: ^2.2.0 => 2.3.7 
    gatsby-transformer-sharp: ^2.1.8 => 2.1.17 
@grubersjoe grubersjoe changed the title gatsby-source-graphql breaks after upgrading Gatsby from v2.1 to v2.2: unknown type gatsby-source-graphql breaks after upgrading Gatsby from v2.1 to v2.2: GraphQLError: Unknown type Mar 21, 2019
@stefanprobst
Copy link
Contributor

Thanks for the detailed report! Could you try if #12720 fixes the issue for you? Thanks a lot!

@freiksenet
Copy link
Contributor

Sorry about that, it should be fixed in #12721.

@DSchau
Copy link
Contributor

DSchau commented Mar 21, 2019

I get a different error than you--could you maybe push a branch where we can reproduce your exact issue?

I did yarn add [email protected] and then GITHUB_TOKEN=hunter2 yarn build and I receive:

Error: Schema must contain unique named types but contains multiple types named "Query".

Of course--can validate that it works in gatsby@~2.1.0--so this definitely seems like a regression.

@stefanprobst
Copy link
Contributor

@DSchau The error you are seeing was fixed in [email protected] with #12668

@DSchau
Copy link
Contributor

DSchau commented Mar 21, 2019

@stefanprobst 🎉 yup yup.

With [email protected] I get:

GraphQLError: Unknown type "GitHub_Blob". Did you mean "GitHub_Blame", "GitHub_Node", "GitHub_URI", "GitHub_App", or "GitHub_HTML"?

with [email protected] I get:

Error: GitHub.relay cannot convert to OutputType the following string: 'Query'

@grubersjoe
Copy link
Author

I'm seeing the same error. So I fear this is still broken 😅.

@stefanprobst
Copy link
Contributor

yes, so sorry, this is indeed not yet fully fixed (but almost 😉). Btw GitHub.relay is the weirdest field I have ever seen, even the field description says it's a hack.

@sidharthachatterjee
Copy link
Contributor

Published in [email protected]

@robthompsonweb
Copy link

Have run into the same issue the last few days as well - @2.2.7 just fixed it

@grubersjoe
Copy link
Author

grubersjoe commented Mar 22, 2019

Thank you for the quick fix. It works now :).

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

Successfully merging a pull request may close this issue.

6 participants