All Projects → sysgears → Persistgraphql Webpack Plugin

sysgears / Persistgraphql Webpack Plugin

Licence: mit
PersistGraphQL Webpack Plugin

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Persistgraphql Webpack Plugin

Persistgraphql
A build tool for GraphQL projects.
Stars: ✭ 409 (+948.72%)
Mutual labels:  graphql, apollo-client
React Boilerplate
⚛ The stable base upon which we build our React projects at Mirego.
Stars: ✭ 39 (+0%)
Mutual labels:  graphql, apollo-client
Apollo Link Firebase
🔥 🔗 apollo-link-firebase provides you a simple way to use Firebase with graphQL.
Stars: ✭ 415 (+964.1%)
Mutual labels:  graphql, apollo-client
Apollo Storybook Decorator
Wrap your storybook environment with Apollo Client, provide mocks for isolated UI testing with GraphQL
Stars: ✭ 333 (+753.85%)
Mutual labels:  graphql, apollo-client
Kikstart Graphql Client
🚀 Small NodeJS Wrapper around apollo-client that provides easy access to running queries, mutations and subscriptions.
Stars: ✭ 27 (-30.77%)
Mutual labels:  graphql, apollo-client
Absinthe
The GraphQL toolkit for Elixir
Stars: ✭ 3,805 (+9656.41%)
Mutual labels:  graphql, apollo-client
Apollo Resolvers
Expressive and composable resolvers for Apollostack's GraphQL server
Stars: ✭ 428 (+997.44%)
Mutual labels:  graphql, apollo-client
Kit
ReactQL starter kit (use the CLI)
Stars: ✭ 232 (+494.87%)
Mutual labels:  graphql, apollo-client
Apollo Link Maxage
An Apollo Link to invalidate cached queries
Stars: ✭ 23 (-41.03%)
Mutual labels:  graphql, apollo-client
Chatty
A WhatsApp clone with React Native and Apollo (Tutorial)
Stars: ✭ 481 (+1133.33%)
Mutual labels:  graphql, apollo-client
Next Shopify Storefront
🛍 A real-world Shopping Cart built with TypeScript, NextJS, React, Redux, Apollo Client, Shopify Storefront GraphQL API, ... and Material UI.
Stars: ✭ 317 (+712.82%)
Mutual labels:  graphql, apollo-client
Link state demo
🚀 Demonstrate how to support multiple stores in Apollo Link State
Stars: ✭ 30 (-23.08%)
Mutual labels:  graphql, apollo-client
Apollo Client
🚀  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
Stars: ✭ 17,070 (+43669.23%)
Mutual labels:  graphql, apollo-client
Apollo Errors
Machine-readable custom errors for Apollostack's GraphQL server
Stars: ✭ 405 (+938.46%)
Mutual labels:  graphql, apollo-client
Ember Apollo Client
🚀 An ember-cli addon for Apollo Client and GraphQL
Stars: ✭ 257 (+558.97%)
Mutual labels:  graphql, apollo-client
Apollo Cache Hermes
A cache implementation for Apollo Client, tuned for performance
Stars: ✭ 425 (+989.74%)
Mutual labels:  graphql, apollo-client
Prisma Auth0 Example
Boilerplate Prisma Startup
Stars: ✭ 184 (+371.79%)
Mutual labels:  graphql, apollo-client
Apollo Offline
An offline toolkit for the Apollo client
Stars: ✭ 186 (+376.92%)
Mutual labels:  graphql, apollo-client
Searchkit
GraphQL API & React UI components for Elasticsearch. The easiest way to build a great search experience
Stars: ✭ 4,338 (+11023.08%)
Mutual labels:  graphql, apollo-client
Create Social Network
An educational project, demonstrating how to build a large scalable project with Javascript.
Stars: ✭ 853 (+2087.18%)
Mutual labels:  graphql, apollo-client

PersistGraphQL Webpack Plugin

Build Status Greenkeeper badge Twitter Follow

Webpack Plugin that gathers all the GraphQL queries/mutation/subscriptions both from .graphql files and from embedded queries in JavaScript/TypeScript source code. It generates virtual module persisted_queries.json with all the queries as a map object (query -> id) available for require from any place within source code and output file on file system with all the queries.

Installation

npm install --save-dev persistgraphql-webpack-plugin

Usage

When Webpack is used for front-end only

Sample Webpack config:

var PersistGraphQLPlugin = require('persistgraphql-webpack-plugin');

module.exports = {
  module: {
    rules: [
      {
        test: /\.(graphql|gql)$/,
        use: 'graphql-tag/loader'
      },
    ]
  }

  plugins: [
    new PersistGraphQLPlugin({filename: 'persisted_queries.json',
        moduleName: path.resolve('node_modules/persisted_queries.json')})
  ]
};

In the source code of front-end persisted GraphQL queries will be injected as a virtual module persisted_queries.json. This module will be updated if queries added or changed. Also asset with name persisted_queries.json will be generated during compilation and written to output directory.

var queryMap = require('persisted_queries.json');
console.log(queryMap);

When Webpack is used both for back-end and front-end

var PersistGraphQLPlugin = require('persistgraphql-webpack-plugin');

const moduleName = path.resolve('node_modules/persisted_queries.json');
const frontendPersistPlugin = new PersistGraphQLPlugin({ moduleName });
const backendPersistPlugin =
    new PersistGraphQLPlugin({ provider: frontendPersistPlugin, moduleName });

var frontendWebpackConfig = {
  module: {
    rules: [
      {
        test: /\.(graphql|gql)$/,
        use: 'graphql-tag/loader'
      },
    ]
  }

  plugins: [
    frontendPersistPlugin
  ]
};

var backendWebpackConfig = {
  // ...
  plugins: [
    backendPersistPlugin
  ]
}

Both in the source code of front-end and back-end persisted GraphQL queries will be injected as a virtual module node_modules/persisted_queries.json. This module will be updated if queries added or changed.

var queryMap = require('persisted_queries.json');
console.log(queryMap);
Name Type Description
moduleName {String} Name of virtual wepback module with persisted GraphQL queries, this option is required
filename {String} Name of the ouput file with persisted GraphQL queries
addTypename {Boolean} Apply a query transformation to the query documents, adding the __typename field at every level of the query, default: true
hashQuery {Function} Function to hash queries in hash map, default: SHA-256 from query, if false passed - counter values are used
provider {Object} Instance of plugin running on another webpack instance which will provide persisted GraphQL queries
excludeRegex {RegExp} RegExp to match file path that will be excluded from processing by the plugin, default: /[\\/]node_modules[\\/]/
graphqlRegex {RegExp} RegExp to match files loaded by graphql-tag/loader that should be processed by the plugin, default: /(.graphql|.gql)$/
jsRegex {RegExp} RegExp to match js files that have embedded GraphQL queries marked with gql tag, default: /(.jsx?|.tsx?)$/

License

Copyright © 2017 SysGears INC. This source code is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].