Giter Club home page Giter Club logo

graphql-transport-electron's Introduction

graphql-transport-electron

Why

In case you want to run a graphql server inside of the Electron main process (for instance if you are building a decentralized application), you need to have the client (renderer process) and server (main process) communicate through Electron IPC.

This project provides a very lightweight client and server interface for Electron IPC based on Apollo.

While its primary use-case is to enable a self-sustained and isolated graphql server inside of the Electron main process, you can connect the server interface to any ApolloLink instance. This means that you could also connect it with a HttpLink / WsLink that forwards your queries to a hosted graphql server outside of Electron.

Installation

# With yarn
yarn add graphql-transport-electron

# With npm
npm install graphql-transport-electron

Usage example

Main process

import { ipcMain } from 'electron';
// NOTE: The library ships with a fork of apollo-link-schema that also supports subscriptions.
import { createSchemaLink, createIpcExecutor } from 'graphql-transport-electron';
import schema from './my-graphql-schema';

// NOTE: This also works with any other apollo link (e.g. HttpLink from apollo-link).
const link = createSchemaLink({ schema });
createIpcExecutor({link, ipc: ipcMain });

Renderer process

import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ipcRenderer } from 'electron';
import { createIpcLink } from 'graphql-transport-electron';

const link = createIpcLink({ ipc: ipcRenderer });
const client = new ApolloClient({
  cache: new InMemoryCache(),
  link,
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.