New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

relay-compiler-webpack-plugin

Package Overview
Dependencies
Maintainers
3
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

relay-compiler-webpack-plugin

Automatically run the Relay Compiler from Webpack

  • 9.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

Relay Compiler Webpack Plugin

npm version Travis Build Status Github Actions Build Status

Are you running Relay Modern? Are you annoyed with constantly running the relay-compiler to generate code, especially if you're already running Webpack?

Well be annoyed no more! Simply install this plugin to automatically hook into Webpack's build process to generate these files for you.

Installation

  1. Add this to your project:
  yarn add --dev relay-compiler-webpack-plugin graphql
  # Or if you're using npm
  npm install --save-dev relay-compiler-webpack-plugin graphql
  1. Add the plugin to your Webpack configuration:
// const RelayCompilerLanguageTypescript = require('relay-compiler-language-typescript').default
const RelayCompilerWebpackPlugin = require('relay-compiler-webpack-plugin')
const path = require('path')

module.exports = {
  // ... Your existing Webpack configuration
  plugins: [
    // ...
    new RelayCompilerWebpackPlugin({
      // languagePlugin: RelayCompilerLanguageTypescript,
      schema: path.resolve(__dirname, './relative/path/to/schema.graphql'), // or schema.json
      src: path.resolve(__dirname, './relative/path/to/source/files'),
    })
  ]
  // ...
}

Note: TypeScript projects also needs to add the TypeScript language plugin as shown in the commented out lines in the above snippet.

  1. :tada:

Gotchas

If there are multiple versions of GraphQL in your dependency tree it will cause schema validation errors. To get around this, ensure you have the same graphql version as your relay-compiler version depends on. To assist this you can install dependencies as flat which ensures only one version of each dependency.

Plugin hooks

relay-compiler-webpack-plugin exposes a few tapable hooks, for plugins or tooling to use.

  • beforeWrite called before the plugin starts to compile queries
  • afterWrite(compileResult): called after writing is complete
class MyPlugin {
  apply (compiler) {
    compiler.hooks.compilation.tap('MyPlugin', async (compilation) => {
      RelayCompilerWebpackPlugin.getHooks(compilation).afterWrite.tapPromise(
        'MyPlugin', // <-- Set a meaningful name for stacktraces
        async (compileResult) => {
          if (compileResult === 'HAS_CHANGES') {
            await doSomething()
          }
        }
      )
    })
  }
}

Example Project

To see an example of its usage within a project, see relay-compiler-webpack-plugin-example.

Development

Running tests:

yarn test

Running tests with coverage:

yarn test:coverage

License

Relay Compiler Webpack Plugin may be redistributed according to the BSD 3-Clause License.

Keywords

FAQs

Package last updated on 18 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc