ardatan / ardatan/graphql-tools

load babel options in `graphql-tag-pluck`

Open
#5,869 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.4k
Forks
830
Avg merge
10h 59m
Merged PRs (30d)
45

Description

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

`graphql-codegen` was silently ignoring source files and not extracting documents.
I was able to track it down to our use of the parser plugin `explicitResourceManagement`, which is declared in the babelrc.

But it turns out that `graphql-tag-pluck` hardcodes babel options based on file extensions [^1], and passes those directly to `parse()` [^2] without possibility of intervention. It ignores existing babel configuration.

[^1]: https://github.com/ardatan/graphql-tools/blob/848de826f21fddd48fac1a93f6d616df6a135c08/packages/graphql-tag-pluck/src/config.ts#L10
[^2]: https://github.com/ardatan/graphql-tools/blob/848de826f21fddd48fac1a93f6d616df6a135c08/packages/graphql-tag-pluck/src/index.ts#L248

**Describe the solution you'd like**

`graphql-tag-plug` should attempt to use `babel.loadPartialConfig` [^3], and use that if it succeeds.

[^3]: https://babeljs.io/docs/babel-core#loadoptions

**Describe alternatives you've considered**

Alternatively, allow passing a list of plugins or babel options overrides through. Note that this might require plumbing up a few levels if interfaces through `CodeFileLoader` and `graphql-codegen` itself to make sure it's properly exposed.

Contributor guide

Open the contributing guide

Research direction

Start with packages/graphql-tag-pluck/src/config.ts and packages/graphql-tag-pluck/src/index.ts, especially the hardcoded parser options and the parse() call cited in the issue. Trace how options could pass through CodeFileLoader and graphql-codegen. Done means existing Babel configuration can supply parser plugins when available, with the current extension-based behavior retained as needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, typescript
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.