lvarayut / relay-fullstack

:point_up::running: Modern Relay Starter Kit - Integrated with Relay, GraphQL, Express, ES6/ES7, JSX, Webpack, Babel, Material Design Lite, and PostCSS
https://lvarayut.github.io/relay-fullstack/
MIT License
986 stars 126 forks source link

Updating graphQL changes when you have a nested file structure #10

Closed alexhawkins closed 8 years ago

alexhawkins commented 8 years ago

My current directory structure ( see this first to understand how i have things set up ) Changes to schema.js work fine but I don't really make changes there. My current schema.js file Gaze recognizes changes in other files but the schema.js is only updated when the schema.js file is changed. I'm using:

gaze(path.join(__dirname, 'graphql/**/*.js'), (err, watcher) => {
    if (err) logger.error(chalk.bold.red('Error: Watching files in data folder'));
    watcher.on('all', async() => {
      try {
        // Close the GraphQL server, update the schema.json and schema.graphql, and start the server again
        graphQLServer.close();
        await updateSchema();
        const newSchema = requireUncached(path.join(__dirname, './graphql/schema')).default;
        startGraphQLServer(newSchema);
        // Close the Relay server, and start it again
        relayServer.listeningApp.close();
        startRelayServer();
      } catch (e) {
        logger.error(chalk.bold.red((e.stack)));
      }
    });
  });

For example, if I make a change in UserType.js (see above image for directory structure) the schema.js is not updated with the change.

Any ideas on how to handle this? I'd like everything to hot reload on any change. Currently I'm having to stop and restart the server which is pretty time consuming. Help would be much appreciated.

lvarayut commented 8 years ago

It's the problem of caching files, the first time you require the UserType.js, the file will be cached by NodeJs. So, it's always the same even though it has been changed. For a quick fix, you always have to use requireUncached() function to require files.

I have planned to move from Gaze to Nodemon very soon. This will help reloading the server without worrying about caching files.

lvarayut commented 8 years ago

Fixed by 48a533c.

alexhawkins commented 8 years ago

@lvarayut Thank you very much :)