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

v2: GraphQL peers and type packages. #4711

Closed
jquense opened this issue Mar 26, 2018 · 4 comments
Closed

v2: GraphQL peers and type packages. #4711

jquense opened this issue Mar 26, 2018 · 4 comments
Assignees
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@jquense
Copy link
Contributor

jquense commented Mar 26, 2018

I think we need to come up with a better strategy for the duplicate graphql issues. The main one is well known, regardless of version mismatch graphql will not run if there are multiple copies, which is dumb. The concern on the horizon (especially with theming) is that any custom types, inadvertently have this problem as well. case in point, both gatsby-transformer-remark and gatsby-transformer-react-docgen use graphql-type-json, but if the package isn't deduped that will break, with gql complaining of an existing type named 'JSON' already.

The only sort of approach i can think that might help here is to do what we do with webpack and provide the graphql object to plugins as well as a set of custom scalars like JSON. That may not super scalable tho :/

@jquense jquense added type: question or discussion Issue discussing or asking a question about Gatsby API/Plugins labels Mar 26, 2018
@KyleAMathews
Copy link
Contributor

I think this makes sense — it should be scalablish — people wanting new ones can just PR in the new field type — same as React did for years with DOM property support.

@pieh
Copy link
Contributor

pieh commented Apr 26, 2018

What is the best way to pass graphql module?

We do pass graphql as a function to run queries in createPages/createPagesStatefully node hooks, so either pass graphql module under different field or export it from gatsby package?

@pieh
Copy link
Contributor

pieh commented May 11, 2018

I started looking into doing this and noticed that gatsby-plugin-remark tests rely on importing from graphql ( https://github.com/gatsbyjs/gatsby/blob/v2/packages/gatsby-transformer-remark/src/__tests__/extend-node.js ). It would also require some refactoring in gatsby-transformer-sharp/gatsby-transformer-sqip.

Right now I'm leaning towards exporting graphql (with added JSON type and any other custom type I will notice in plugins) from gatsby, so plugins can do

-const { GraphQLString } = require(`graphql`)
+const { GraphQLString } = require(`gatsby/graphql`)

Didn't try it yet but it shouldn't conflict with runtime stuff gatsby "export" using webpack alias - https://github.com/gatsbyjs/gatsby/blob/v2/packages/gatsby/src/utils/webpack.config.js#L343

Thoughts on this approach?

@m-allanson
Copy link
Contributor

Done in #5415

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

4 participants