Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fusion-apollo-universal-client

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fusion-apollo-universal-client

[![Build status](https://badge.buildkite.com/107d4baa53a894926a5da4e9552291e6e1b8133d6f665729cc.svg?branch=master)](https://buildkite.com/uberopensource/fusion-apollo-universal-client)

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
34
increased by385.71%
Maintainers
2
Weekly downloads
 
Created
Source

fusion-apollo-universal-client

Build status

A simple universal client for GraphQL apps using fusion-apollo.

The Apollo Client is the entrypoint for most Apollo applications. This plugin provides a client with the minimum amount of configuration necessary to create a universally rendered Apollo application.


Table of contents


Installation

yarn add fusion-apollo-universal-client

Usage

Usage with fusion-apollo

import App, {ApolloClientToken} from 'fusion-apollo';
import GetApolloClient, {
  ApolloClientEndpointToken,
} from 'fusion-apollo-universal-client';
import unfetch from 'unfetch';

export default () => {
  const app = new App(root);
  app.register(ApolloClientToken, GetApolloClient);
  app.register(ApolloClientEndpointToken, '...');
  __NODE__ && app.register(FetchToken, unfetch);
  return app;
};

Usage with local server

If your app hosts the Apollo server a schema must be provided. The schema can be provided using the GraphQLSchemaToken from fusion-apollo.

import App, {ApolloClientToken, GraphQLSchemaToken} from 'fusion-apollo';
import {makeExecutableSchema} from 'graphql-tools';
import GetApolloClient, {ApolloClientEndpointToken} from 'fusion-apollo-universal-client';
import unfetch from 'unfetch';

export default () => {
  const app = new App(root);
  app.register(ApolloClientToken, GetApolloClient);
  app.register(ApolloClientEndpointToken, '...');
  app.register(GraphQLSchemaToken, makeExecutableSchema(...));
  __NODE__ && app.register(FetchToken, unfetch);
  return app;
};

See the Apollo Documentation for how to generate a schema.

Authorization

Authorization will work with hosted GraphQL services such as scaphold and graph.cool. This works by passing a stored authentication token inside of the authorization header. This token is currently assumed to stored in a cookie and cookies by the value provided in ApolloClientAuthKeyToken (defaults to "token").


API

Registration API
ApolloClientEndpointToken
import {ApolloClientEndpointToken} from 'fusion-apollo';

A token with the GraphQL endpoint which the Apollo HttpLink client communicates with. This can be an absolute path to a local GraphQL server, or a remote hosted GraphQL server.

Type
  • string - Required. The URI to make GraphQL requests from.
Dependencies
FetchToken
import {FetchToken} from 'fusion-tokens';

A fetch implementation. Browser-only.

Type
type Fetch = (url: string, options: Object) => Promise<Response>;
  • url: string - Required. Path or URL to the resource you wish to fetch.
  • options: Object - Optional. You may optionally pass an init options object as the second argument. See Request for more details.
  • [return]: Promise<Request> - Return value from fetch. See [Response](A function that loads appropriate translations and locale information given an HTTP request context) for more details.
Default value

If no fetch implementation is provided, window.fetch is used.

ApolloClientAuthKeyToken
import {ApolloClientAuthKeyToken} from 'fusion-apollo-universal-client';

(Optional) A configuration value that provides the value of an authentication token to use from the document cookies. If provided, this token is used in the Apollo auth middleware as an authorization header.

Type
  • string - Required. Name of the cookie which contains the authorization token.
Default value

If no token name is provided, authorization headers are not sent.

GetApolloClientCacheToken
import {GetApolloClientCacheToken} from 'fusion-apollo-universal-client';

(Optional) A function that returns an Apollo cache implementation.

Type
  • (ctx: Context) => ApolloCache - Optional.
Default value

The default cache implementation uses InMemoryCache.

ApolloClientCredentialsToken
import {ApolloClientCredentialsToken} from 'fusion-apollo-universal-client';

(Optional) A configuration value that provides the value of credentials value passed directly into the fetch implementation.

Type
  • string - Optional.
Default value

The default value is same-origin.

GetApolloClientLinksToken
import {GetApolloClientLinksToken} from 'fusion-apollo-universal-client';

(Optional) A configuration value that provides a array of ApolloLinks. The default links are provided as an argument to the provided function.

Type
  • (Array<ApolloLinkType>) => Array<ApolloLinkType> - Optional.
ApolloClientResolversToken
import { ApolloClientResolversToken } from "fusion-apollo-universal-client";

(Optional) Provides the resolvers for local state management.

Type
  • ResolverMap | $ReadOnlyArray<ResolverMap> - Optional.

FAQs

Package last updated on 18 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc