andrewbranch / gatsby-remark-vscode

Gatsby plugin to provide VS Code’s syntax highlighting to Markdown code fences
MIT License
296 stars 27 forks source link

fix: import graphql schema from js #185

Closed dimitrisnl closed 2 years ago

dimitrisnl commented 2 years ago

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: https://github.com/andrewbranch/gatsby-remark-vscode/issues/174

andrewbranch commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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

dimitrisnl commented 2 years ago

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

dimitrisnl commented 2 years ago

some issues, the tests and prettier pass. Investigating.

Screen Shot 2022-02-14 at 11 04 09 PM
dimitrisnl commented 2 years ago

@andrewbranch One more time

andrewbranch commented 2 years ago

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 commented 2 years ago

Updated @andrewbranch

andrewbranch commented 2 years ago

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

dimitrisnl commented 2 years ago

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 commented 2 years ago

Closing due to inactivity