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

Schema is cached after first run #1

dimitrykislichenko opened this Issue Sep 22, 2016 · 6 comments


None yet
6 participants
Copy link

dimitrykislichenko commented Sep 22, 2016

Hi @zvictor,

Thank you for your work, that's a nice plugin and works great, but I think I've spotted a problem. A schema files are cached after first run and will not updated unless you remove ~/.babel.json file.


This comment has been minimized.

Copy link

zvictor commented Sep 22, 2016


I think you are right. The plugin gets the content of the imported file and inline it in the importing one, but Babel is not aware of this dependency. Therefore, you need to change the importing file in order to see your changes in the imported file spread. I tried many ways to overcome this, unsuccessfully.

The only workaround I found was disabling babel cache (BABEL_DISABLE_CACHE=1) and making sure that my task runner was watching for changes in the inlined file as well. You can see it working here.

I thought I had added this to the documentation, but it seems that I forgot. I am sorry for that.
If you have any idea of how we can improve this issue, please let us know.


This comment has been minimized.

Copy link

jaydenseric commented Dec 11, 2016

All these issues go away when using a webpack loader instead to achieve the same thing... I got importing .qraphql files as template strings for Apollo working with With webpack watching, changes to the imported .graphql files results in automatic recompiles just fine.

In your server webpack config, add:

  test: /\.(graphql|gql)$/,
  exclude: /node_modules/,
  loader: 'template-string-loader'

To import a .graphql file:

import graphql from './types.graphql'
const types = graphql()

You have to run the import as a function to get the template string, as the library caters for passing arguments into the template.

First impressions; it doesn't sit well that .graphql files are processed on import very differently in the server code vs client code ( loader)... Perhaps when I try to get stuff working isomorphically this will cause issues, and it is easy to forget this behavior when moving around the codebase.


This comment has been minimized.

Copy link

HaveF commented Dec 22, 2016

@zvictor Thanks for your plugin. And I also puzzled by this problem, I do suppose this should be a default option --- when *.graphql file changes, the program restart. At first, I thought it is some bug in my code, after failed many times, I read the doc of this plugin, and find the answer...
nodemon's watch and babel's cache must be configured

@jaydenseric Thanks for your thoughts about the import. Could you tell me more the detail of graphql-tag loader user case. I do not understand the different between them, it seems grahpql-tag is import *.graphql as GraphQL ASTs. Is it only used in client? Confused... I also want to find some thing to work isomorphically

@stubailo what do you think about this issue, and how to use grahpql-tag loader in your project? Only use it as client part?


This comment has been minimized.

Copy link

stubailo commented Dec 22, 2016

Hey, I didn't contribute the Webpack loader to the package so I don't know if there is a good way to use it on the server. On the server there aren't any common build systems except Meteor that can be integrated with, so perhaps the best option is to use a require hook?


This comment has been minimized.

Copy link

HaveF commented Dec 22, 2016

@stubailo thanks for your reply 😊

@heldr Hi, Helder Santana, I found you create grahpql-tag loader, thanks for your work. @jaydenseric and I meet the import problem when working isomorphically.

The current problem is

  1. import *.graphql file may confused people

a. If you want to import *.graphql file on the server, you have to use this babel plugin, and set nodemon's watch and babel's cache, or use template-string-loader as @jaydenseric showed above.

b. If you want to import *.graphql file on the client, use the loader you created, actually, the import result is Graphql ASTs

  1. Could it possible to use just one tool to handle import problem?

The possible solution

  1. Use some conventions, in jimkyndemeyer/js-graphql-intellij-plugin, *.graphqls is schema, and *.graphql is for query (on the client).
    what do you think?

  2. have no idea


This comment has been minimized.

Copy link

Koleok commented Jun 27, 2017

I ended up running this chained in with my build command, which basically comes from babel-register/lib/cache.js 😱

const homeOrTmp = require('home-or-tmp');
const path = require('path');

const cachePath =
  process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, '.babel.json');

require('rimraf')(cachePath, err =>
  console.log(`graphql schema was${err ? ' not' : ''} cleared`)

Seems pretty crude but I have not had any success setting the BABEL_DISABLE_CACHE=1 and just need some way to have new schema changes actually deploy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment