Skip to content
This repository has been archived by the owner on May 22, 2019. It is now read-only.

fusionjs/fusion-plugin-apollo-server

Repository files navigation

DEPRECATED. Please use fusion-plugin-apollo instead

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.

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

Register function to format errors from resolvers. Could be used for logging.

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
  };
});