Giter VIP home page Giter VIP logo

fusion-apollo-universal-client's Introduction

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-tokens';

(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.

ApolloClientCredentialsToken
import {ApolloClientCredentialsToken} from 'fusion-tokens';

(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.


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.