fusion-plugin-apollo-server

Connects a GraphQL schema to a Fusion.js server.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
fusion-plugin-apollo-server
831.3.05 years ago6 years agoMinified + gzip package size for fusion-plugin-apollo-server in KB

Readme

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
- Registration API
- [`ApolloServerEndpointToken`](#apolloserverendpointtoken)
- [`ApolloServerFormatFunctionToken`](#apolloserverformatfunctiontoken)
---

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