angus-c / fusion-plugin-apollo-server

Connects a GraphQL schema to your Fusion.js server.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fusion-plugin-apollo-server

Build status

This plugin connects GraphQL schema to your Fusion.js server, allowing you to host a web server and graphql endpoint within the same Fusion.js project. This is most useful when used with fusion-apollo and fusion-apollo-universal-client.


Table of contents


Installation

yarn add fusion-plugin-apollo-server

Usage

To use the apollo server create a schema. The schema can be provided using the GraphQLSchemaToken from fusion-apollo. See the Apollo Documentation for how to generate a schema.

import ApolloServer, {ApolloServerEndpointToken} from 'fusion-plugin-apollo-server';
import {GraphQLSchemaToken} from 'fusion-apollo';
import {makeExecutableSchema} from 'graphql-tools';

export default () => {
  ...
  app.register(ApolloServer);
  app.register(ApolloServerEndpointToken, '/graphql'); // optional - /graphql is the default
  app.register(GraphQLSchemaToken, makeExecutableSchema(...));
  ...
};

API

Registration API

ApolloServerEndpointToken
import {ApolloServerEndpointToken} from 'fusion-plugin-apollo-server';

This should be registered to a string representing the desired GraphQL endpoint. If using fusion-apollo-universal-client, this will likely be the same value as `ApolloClientEndpointToken.

ApolloContextToken

This can be used to transform the koa context into an apollo context.

import {ApolloContextToken} from 'fusion-apollo';

app.register(ApolloContextToken, ctx => {
  return {
    httpContext: ctx,
    otherContext: SOMEOHTERCONTEXT
  };
});

About

Connects a GraphQL schema to your Fusion.js server.

License:MIT License


Languages

Language:JavaScript 88.8%Language:Shell 8.7%Language:Dockerfile 2.5%