ardatan / ardatan/graphql-tools

[Feature request] Dependency injection for graphql implemataion

Open
#3,599 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5.4k
Forks
828
Avg merge
10h 59m
Merged PRs (30d)
45

Description

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...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the GraphQL Tools functions that directly import or depend on graphql, especially mergeSchemas, and compare the optional-argument and builder approaches described in the issue. Done means custom implementations such as graphql-web-lite can be supplied without bundler workarounds or graphql version-conflict build errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.