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

[Feature request] Dependency injection for graphql implemataion #3599

Open
Tracked by #5201 ...
cometkim opened this issue Sep 27, 2021 · 2 comments
Open
Tracked by #5201 ...

[Feature request] Dependency injection for graphql implemataion #3599

cometkim opened this issue Sep 27, 2021 · 2 comments

Comments

@cometkim
Copy link

cometkim commented Sep 27, 2021

Is your feature request related to a problem? Please describe.

I want to use a custom graphql implementation. use cases

  1. I wanna use @kitten 's graphql-web-lite or something other for a lighter bundle
  2. gatsby-plugin-typegen, which is based on GCG and graphql-tools should depend on the graphql module re-exported from gatsby. Otherwise, users will get build errors due to version conflicts

Both of these can be solved today only with third-party tools such as bundlers (e.g. Webpack) or package managers (e.g. Yarn).

As usual, the JS module system cannot change its configuration by itself, so if we have base dependencies externally we configure the dependency injection by hand, instead of import impl directly.

Describe the solution you'd like

The easiest option is to accept graphql impl as an optional argument in all the functions.

const { mergeSchemas } = require('@graphql-tools/schema');

mergeSchemas({
   grapqhql: myGraphQl,
   /** ... */
});

Or a better way I think is to create a builder that allows you to customize the configuration of the function.

export function createMergeSchema({ graphql }) {
   return function mergeSchema(...) { ... }
}

export const mergeSchema = createMergeSchema({ graphql })

Describe alternatives you've considered

Transpile it and bundle the entire GCG and graphql-tools...

@kitten
Copy link

kitten commented Sep 27, 2021

Quick note here that graphql-web-lite + graphql-tools probably isn't the best example, since the former is Web-focused and hence drops support here and there for the SDL. 😅

@cometkim
Copy link
Author

Ah, i got it. Maybe it's better to find another example for SDL support. like WASM-based something?

I assume graphql-tools have broader use cases including browsers. and I would definitely put it on a service worker or cloudflare workers.

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

No branches or pull requests

2 participants