graphql-let icon indicating copy to clipboard operation
graphql-let copied to clipboard

Support writing configuration as webpack Loader option

Open piglovesyou opened this issue 4 years ago • 5 comments

From https://github.com/piglovesyou/graphql-let/pull/78#issue-401108869

Ideally it should also be available as a Webpack Loader option.

The problem is the command-line execution, but maybe we can get it from webpack.config.ts. Reasonable spec would be:

  • Load config by the following priority:
    1. .graphql-let.yml
      • CWD is where the .graphql-let.yml is located
    2. webpack Loader option
      • If the paths are absolute, it respects as is
      • If the paths are relative, it recognizes config.context as CWD

piglovesyou avatar Apr 09 '20 01:04 piglovesyou

Perhaps we should move to only use webpack.config.ts and should abandon .graphql-let.yml, should we? Pros:

  • Currently both .graphql-let.yml and webpack.config.ts should be configured. Becoming one is simpler.
  • Being "a webpack loader" is one of the core identities of graphql-let. It'd be more reasonable to place its options in webpack.config.ts.

piglovesyou avatar Apr 26 '20 07:04 piglovesyou

I see some people expect .graphql-let.yml to be a subset of codegen.yml. Supporting both would be more kind.

piglovesyou avatar May 17 '20 14:05 piglovesyou

Ideally it should also be available as a Webpack Loader option.

The problem is the command-line execution, but maybe we can get it from webpack.config.ts.

Would specifying a path to .graphql-let.yml also be a problem?

{
  loader: 'graphql-let/loader',
  options: {
    configFilePath: '../../.graphql-let.yml'
  }
},

Since loadConfig already accepts a path, the thing that remains is passing provided configFilePath to it, am I right?

hasparus avatar Sep 03 '20 11:09 hasparus

Hi. True, it should be like the Babel's configFile option, where babel-loader can pass all babel options OR a relative path to a config file. And yes, accepting a configFilePath option would be our first step.

The problem would be, graphql-let currently expects both .graphql-let.yml and webpackConfig.context are in process.cwd(). So the PR solving is supposed to have tests with changing these paths.

piglovesyou avatar Sep 04 '20 00:09 piglovesyou

I encountered two problems while using graphql-let in a Nx monorepo.

  1. I have two webpack configs (own for dev and Nx's for prod) with different context, so I have two copies of .graphql-let.yml. This could be fixed with options.configFile accepting a path to the config.

  2. My CI build is failing unless I commit generated files, because on CI they're generated in <root-dir>/apps/my-app-one/path/to/file.gql (production context) instead of <root-dir>/path/to/file.gql where TypeScript expects them. This could be fixed by options.configFile accepting full config or rootDir and cacheDir options in the loader... right?

Edit: I have something like this. https://github.com/hasparus/graphql-let/tree/loader-options-config-file/test/__fixtures/loader/monorepo

hasparus avatar Sep 09 '20 17:09 hasparus