All Projects → yusinto → relay-compiler-plus

yusinto / relay-compiler-plus

Licence: MIT License
Custom relay compiler which supports persisted queries

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to relay-compiler-plus

graphql-spotify
GraphQL Schema And Resolvers For Spotify Web API
Stars: ✭ 55 (-19.12%)
Mutual labels:  graphql-server, graphql-schema, graphql-js, graphql-tools
Typegql
Create GraphQL schema with TypeScript classes.
Stars: ✭ 415 (+510.29%)
Mutual labels:  graphql-server, graphql-schema, graphql-js
Graphql2rest
GraphQL to REST converter: automatically generate a RESTful API from your existing GraphQL API
Stars: ✭ 181 (+166.18%)
Mutual labels:  graphql-server, graphql-schema, graphql-js
Graphql Log
Add logging to your GraphQL resolvers so you know what's going on in your app.
Stars: ✭ 94 (+38.24%)
Mutual labels:  graphql-server, graphql-schema, graphql-js
36 Graphql Concepts
📜 36 concepts every GraphQL developer should know.
Stars: ✭ 209 (+207.35%)
Mutual labels:  graphql-client, graphql-server, graphql-schema
Fullstack Graphql
🌈 Simple Fullstack GraphQL Application. API built with Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). WebApp built with React + Redux to access the API. Written in ES6 using Babel + Webpack.
Stars: ✭ 955 (+1304.41%)
Mutual labels:  graphql-client, graphql-server, graphql-schema
Graphql Cost Analysis
A Graphql query cost analyzer.
Stars: ✭ 527 (+675%)
Mutual labels:  graphql-server, graphql-schema, graphql-js
Hotchocolate
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
Stars: ✭ 3,009 (+4325%)
Mutual labels:  graphql-client, graphql-server, graphql-schema
graphql-express-nodejs
A Simple GraphQL Server implementation using Express and Node. See post here: https://t.co/Cm6GitZaBL
Stars: ✭ 24 (-64.71%)
Mutual labels:  graphql-server, graphql-schema, graphql-js
fullstack-graphql-angular
Simple Fullstack GraphQL Application with Angular CLI + Redux. API built with Typescript + Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). WebApp built with Angular CLI + Redux + Async Middleware to access the API.
Stars: ✭ 67 (-1.47%)
Mutual labels:  graphql-client, graphql-server, graphql-schema
gqlc
GraphQL IDL Compiler
Stars: ✭ 23 (-66.18%)
Mutual labels:  graphql-schema, graphql-tools
relay-store-types-generator
Generate types for the Relay store from your GraphQL schema.
Stars: ✭ 17 (-75%)
Mutual labels:  relay, relay-modern
nim-graphql
Nim implementation of GraphQL with sugar and steroids
Stars: ✭ 47 (-30.88%)
Mutual labels:  graphql-client, graphql-server
protoc-gen-twirpql
Generate A GraphQL Layer from A Twirp Server: https://twirpql.dev
Stars: ✭ 49 (-27.94%)
Mutual labels:  graphql-client, graphql-server
ugql
🚀GraphQL.js over HTTP with uWebSockets.js
Stars: ✭ 27 (-60.29%)
Mutual labels:  graphql-server, graphql-js
schemaglue
Naturally breaks down your monolithic graphql schema into bits and pieces and then glue them back together.
Stars: ✭ 117 (+72.06%)
Mutual labels:  graphql-schema, graphql-tools
kobby
Kobby is a codegen plugin of Kotlin DSL Client by GraphQL schema. The generated DSL supports execution of complex GraphQL queries, mutation and subscriptions in Kotlin with syntax similar to native GraphQL syntax.
Stars: ✭ 52 (-23.53%)
Mutual labels:  graphql-client, graphql-schema
graphql-query-whitelist
GraphQL query whitelisting middleware
Stars: ✭ 17 (-75%)
Mutual labels:  graphql-server, graphql-js
react-relay-appsync
AppSync for Relay
Stars: ✭ 19 (-72.06%)
Mutual labels:  relay, relay-modern
student-api-graphql
A GraphQL Wrapper for Ellucian's Banner Student REST API
Stars: ✭ 19 (-72.06%)
Mutual labels:  graphql-server, graphql-js

relay-compiler-plus

npm version npm downloads npm npm

Custom relay compiler which supports persisted queries :bowtie:

Relay modern is awesome. However it's missing a few things, one of which is persisted queries. This package is a custom relay compiler which supports:

  • persisted queries
  • direct compilation of graphql-js

Direct graphql-js support means you can generate your relay queries, schema.graphql and query map files all in a single step!

Installation

yarn add relay-compiler-plus

Make sure you have the latest version of graphql-js:

yarn upgrade graphql --latest  

Usage

  1. Add this npm command to your package.json:

    "scripts": {
        "rcp": "NODE_ENV=production relay-compiler-plus --schema <SCHEMA_FILE_PATH> --src <SRC_DIR_PATH>"
    },
    

    where

    • <SCHEMA_FILE_PATH> is the path to your schema.graphql or schema.json file or schema.js (yes! rcp now supports direct compilation from graphql-js!).
    • <SRC_DIR_PATH> is the path to your src directory

    then:

    npm run rcp
    

    this should generate:

    • query files (*.graphql.js) containing query ids and null query text. Note that if you omit NODE_ENV=production, rcp will include both the query id and the query text in your query files. This can be useful for debugging in development.
    • A queryMap.json file under <SRC_DIR_PATH>/queryMap.json. This file can be consumed by the server to map the query ids to actual queries.
    • If you specified a schema.js file, this will also generate a schema.graphql file under ../<SRC_DIR_PATH>/schema.graphql. The schema.graphql has to sit outside the src folder otherwise the relay-compiler will complain.

    If your graphql-js file is complex and you need to override the default webpack config you can do so like this:

    "scripts": {
        "rcp": "NODE_ENV=production relay-compiler-plus --webpackConfig <WEBPACK_CONFIG_PATH> --src <SRC_DIR_PATH>"
    },
    

    where

    • <WEBPACK_CONFIG_PATH> is the path to your custom webpack config to transpile your graphql-js schema. In your custom webpack config, you need to set output.libraryTarget: 'commonjs2'. See the example config for a working copy.
  2. On the server, use matchQueryMiddleware prior to express-graphql to match queryIds to actual queries. Note that queryMap.json is auto-generated by relay-compiler-plus at step 1.

    import Express from 'express';
    import expressGraphl from 'express-graphql';
    import {matchQueryMiddleware} from 'relay-compiler-plus'; // do this
    import queryMapJson from '../queryMap.json'; // do this
    
    const app = Express();
    
    app.use('/graphql',
      matchQueryMiddleware(queryMapJson), // do this
      expressGraphl({
        schema: graphqlSchema,
        graphiql: true,
      }));
  3. On the client, modify your relay network fetch implementation to pass a queryId parameter in the request body instead of a query parameter. Note that operation.id is generated by relay-compiler-plus in step 1.

    function fetchQuery(operation, variables) {
      return fetch('/graphql', {
        method: 'POST',
        headers: {
          'content-type': 'application/json'
        },
        body: JSON.stringify({
          queryId: operation.id, // do this
          variables,
        }),
      }).then(response => {
        return response.json();
      });
    }

Run your app and that's it!

Example

Check the example for a fully working demo.

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].