kamilkisiela / graphql-config

One configuration for all your GraphQL tools (supported by most tools, editors & IDEs)
https://the-guild.dev/graphql/config
MIT License
1.17k stars 94 forks source link

how to disable? #17

Closed brandonmp closed 7 years ago

brandonmp commented 7 years ago

I'm trying to configure webpack to build a subrepository I have in my react/relay project. the subrepo doesn't require a graphql endpoint, so I'd like to disable graph-config when executing the subrepo's webpack configs.

however, when calling webpack from the project's root (with its own package.json), I'm still facing build errors:

ERROR in ./add/index.js
Module build failed: Error: Couldn't find a GraphQL config. Please refer to https://github.com/graphcool/graphql-config
    at parse (/home/bmp/storage/code/wayhome/web-app/node_modules/graphql-config-parser/src/index.js:41:11)
    at Object.<anonymous> (/home/bmp/storage/code/wayhome/web-app/node_modules/babel-plugin-react-relay/lib/index.js:48:45)
    at Module._compile (module.js:573:32)
    at Object.Module._extensions..js (module.js:582:10)
    at Module.load (module.js:490:32)
    at tryModuleLoad (module.js:449:12)
    at Function.Module._load (module.js:441:3)
    at Module.require (module.js:500:17)
    at require (internal/module.js:20:19)
    at /home/bmp/storage/code/wayhome/web-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:178:20
    at Array.map (native)
    at Function.normalisePlugins (/home/bmp/storage/code/wayhome/web-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
    at OptionManager.mergeOptions (/home/bmp/storage/code/wayhome/web-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:233:36)
    at OptionManager.init (/home/bmp/storage/code/wayhome/web-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:367:12)
    at File.initOptions (/home/bmp/storage/code/wayhome/web-app/node_modules/babel-core/lib/transformation/file/index.js:216:65)
    at new File (/home/bmp/storage/code/wayhome/web-app/node_modules/babel-core/lib/transformation/file/index.js:139:24)
    at Pipeline.transform (/home/bmp/storage/code/wayhome/web-app/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at transpile (/home/bmp/storage/code/wayhome/web-app/node_modules/babel-loader/index.js:38:20)
    at Object.module.exports (/home/bmp/storage/code/wayhome/web-app/node_modules/babel-loader/index.js:131:12)
 @ multi add

I tried setting an empty object to .graphqlrc or throwing in a fake endpoint, but no dice.

How is graphql-config even hooking onto this build command? I'm not using the same webpack.config.js or package.json/node_modules as the parent repo.

subrepo's stuff:

// webpack.config.js
var path = require("path")
var rootPath = './src/backend-functions'

module.exports = {
  entry: {
    add: [`./add/index.js`],
  },
  output: {
    //path: path.join(__dirname, "js"),
    filename: "bundle.js",
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /(node_modules)/,
        loader: 'babel',
        babelrc: false,
        query: {
          presets: ['stage-0']
          //plugins: ['transform-flow-strip-types']
        }
      },
      {
        test: /\.json$/,
        loader: 'json'
      }
    ]
  }
}
//package.json
{
  "name": "web-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "start": "webpack"
  },
  "dependencies": {
    "webpack": "^1.14.0"
  }
}
brandonmp commented 7 years ago

i should add that i also using babel-plugin-react-relay as a complement to graphql-config, version 0.9.3-3

The errors pointed me to this repo, though, which is why I posted here

schickling commented 7 years ago

Hi @brandonmp. Since babel-plugin-react-relay uses graphql-config and relies on providing a configuration method. Could you describe why you don't want to put in the right data in a .graphqlrc file or similar?

brandonmp commented 7 years ago

thanks @schickling - the reason for trying to put fake data in .graphqlrc is just to prevent the graphql-config from connecting to my graphql-endpoint in certain situations. there are 2 situations I've found where I've wanted to run an NPM script in my react-relay project directory, but haven't bene able to stop graphql-config from initializing and contacting my endpoint:

  1. react-storybook development. i was traveling somewhere and wanted to work on the plane, but I found that, because graphql-config was starting even when i ran npm run storybook instead of starting my normal development server, i was unable to start it w/out removing graphl-config. it'd be nice to be able to toggle it on/off in those instances

  2. (situation I mention in OP) I have a node microservice I was trying to put in a subrepository in my react-relay project directory. it had its own package.json with no graphql-config, but it seemed that graphql-config was still starting every time i tried to run the development server.

both of these could be due to my misunderstanding of how babel-plugin-react-relay hooks into my npm scripts, so maybe there is already a solution i don't know about. is it because my .babelrc mentions babel-plugin-react-relay? or because it's in the project root's package.json ?

but if there is no way to gracefully disable it arbitrarily, it would be nice to have the option of running npm scripts in my project directory without starting babel-plugin-react-relay/graphql-config

schickling commented 7 years ago

I see. Your use case makes sense. As a fallback for these scenarios a good way would be to download the GraphQL schema as a JSON file and use the JSON configuration option.

I'm not sure if we should add an additional configuration option based on an edge case. Happy to hear other thoughts on this!

brandonmp commented 7 years ago

slightly embarrassing but i actually hadn't tried the JSON option :-/

i just configured it but it seems like it's perfect for my use-case. thanks for taking the time to point me to it @schickling

schickling commented 7 years ago

Great to hear @brandonmp. I'll close this issue for now. If someone else experiences a similar situation, feel free to ask for re-open.