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

fix: import graphql schema from js #185

Closed
wants to merge 7 commits into from

Conversation

dimitrisnl
Copy link

@dimitrisnl dimitrisnl commented Feb 12, 2022

As per the Gatsby migrations docs, we can't use fs anymore to import the GraphQL schema
https://www.gatsbyjs.com/docs/reference/release-notes/migrating-source-plugin-from-v3-to-v4/#the-new-way-4

old way

const fs = require("fs")
const path = require("path")
exports.createSchemaCustomization = ({ actions }) => {
  const { createTypes } = actions
  const typeDefs = fs.readFileSync(
    // .gql file with the SDL
    path.resolve(__dirname, "schema.gql"),
    "utf8"
  )
  createTypes(typeDefs)
}

new way

// JS file containing the SDL strings now
const typeDefs = require("./schema")
exports.createSchemaCustomization = ({ actions }) => {
  const { createTypes } = actions
  createTypes(typeDefs)
}

We do pretty much the same, so:

  1. Moved the GraphQL schema in a template literal in a js file
  2. Imported that file in the script that generates the types
  3. Moved the type declarations one folder up to avoid TS conflicts
  4. Imported the GraphQL schema from the new file in the createSchemaCustomization hook

This should now allow us to us the plugin with GatsbyV4.
Tested with npm pack and local import in my website.


Fixes: #174

@dimitrisnl dimitrisnl marked this pull request as ready for review February 12, 2022 16:41
@andrewbranch
Copy link
Owner

Thanks for looking into this! I just approved the workflow runs so you can try to get CI passing. Once it’s green I’ll take closer look.

@dimitrisnl
Copy link
Author

dimitrisnl commented Feb 14, 2022

@andrewbranch Something weird is going on, the node 12 tests doesn't run at all (seems correct), and the node 14 has a strange error

@andrewbranch
Copy link
Owner

14 quit because 12 failed—you can change all the workflow configs to test on 14/16 instead of 12/14.

@dimitrisnl
Copy link
Author

Seems to be needing approval again, can you spare a moment @andrewbranch ?

@dimitrisnl
Copy link
Author

some issues, the tests and prettier pass. Investigating.

Screen Shot 2022-02-14 at 11 04 09 PM

@dimitrisnl
Copy link
Author

@andrewbranch One more time

@andrewbranch
Copy link
Owner

I would rather not enable skipLibCheck since the repo contains hand-written .d.ts files. There’s no reason that eslint typings should be part of the compilation in the first place. Try adding "types": ["node", "jest"] to the compiler options in tsconfig.json.

@dimitrisnl
Copy link
Author

Updated @andrewbranch

tsconfig.json Outdated
@@ -18,5 +17,6 @@
],
"exclude": [
"test/graphql/site"
]
],
"types": ["node", "jest"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It goes inside compilerOptions, not at the root

@andrewbranch
Copy link
Owner

You should be able to test this stuff locally by the way—CI isn’t doing anything fancy

@dimitrisnl
Copy link
Author

Tests are not running properly locally for me.
Assumed it would be a quick win to do it here, as I already have deployed these changes in my website and I have no issues.
Screen Shot 2022-02-15 at 7 33 12 PM

@dimitrisnl
Copy link
Author

Closing due to inactivity

@dimitrisnl dimitrisnl closed this Mar 1, 2022
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 this pull request may close these issues.

Gatsby 4: Type with name "GRVSCCodeSpan" does not exists
2 participants