3.8.7 • Published 1 year ago

fusion-plugin-apollo v3.8.7

Weekly downloads
99
License
MIT
Repository
github
Last release
1 year ago

fusion-plugin-apollo

Build status

Fusion.js plugin for universal rendering with React and Apollo

This package provides universal rendering for Fusion.js applications leveraging GraphQL.

The plugin will perform graphql queries on the server, thereby rendering your applications initial HTML view on the server before sending it to the client. Additionally this plugin will also provide initial state hydration on the client side.


Table of contents


Installation

yarn add fusion-plugin-apollo

Usage

// ./src/main.js
import React from 'react';
import App from 'fusion-react';
import {RenderToken} from 'fusion-core';

// New import provided by this plugin
import ApolloPlugin, {
  GraphQLSchemaToken, 
  ApolloClientToken
} from 'fusion-plugin-apollo';

// Plugin which provides an apollo client pre-configured for universal rendering
import ApolloUniversalClient from 'fusion-apollo-universal-client';

export default function() {
  const app = new App(<Hello />);
  app.register(RenderToken, ApolloPlugin);
  app.register(ApolloClientToken, ApolloUniversalClient);
  if (__NODE__) {
    app.register(GraphQLSchemaToken, YourGraphQLSchema);
  }
  return app;
}

Loading GraphQL Queries/Schemas

fusion-plugin-apollo ships with a compiler plugin that lets you load graphql queries and schemas with the gql macro. This macro takes a relative path argument and returns the query/schema as a string.

NOTE: Because this is a build time feature, the path argument must be a string literal. Dynamic paths are not supported.

import {gql} from 'fusion-plugin-apollo';
const query = gql('./some-query.graphql');
const schema = gql('./some-schema.graphql');

API

Registration API

ApolloClientToken
import {ApolloClientToken} from 'fusion-plugin-apollo';

A plugin, which provides an instance of Apollo Client, to be registered and used as within the Apollo Provider. You can use fusion-apollo-universal-client as a barebones Apollo Client token.

type ApolloClient<TInitialState> = (ctx: Context, initialState: TInitialState) => ApolloClientType;
ApolloContextToken
import {ApolloContextToken} from 'fusion-plugin-apollo';

Optional - A function which returns the apollo context. Defaults to the fusion context. See the Apollo Client context documentation for more details.

type ApolloContext<T> = (ctx: Context => T) | T;
GraphQLSchemaToken
import {GraphQLSchemaToken} from 'fusion-plugin-apollo';

Your graphql schema is registered on the GraphQLSchemaToken token. This can be an Object of {typeDefs, resolvers} or the result from makeExecutableSchema or makeRemoteExecutableSchema from the graphql-tools library.

GraphQLEndpointToken
import {GraphQLEndpointToken} from 'fusion-plugin-apollo'; 

Optional - the endpoint for serving the graphql API. Defaults to '/graphql'.

type GraphQLEndpoint = string;

Plugin

import ApolloPlugin from 'fusion-plugin-apollo';

A plugin which is responsible for rendering (both virtual DOM and server-side rendering).

gql

import {gql} from 'fusion-plugin-apollo';

A macro for loading graphql queries and schemas. Takes a relative path string and returns the contents of the graphql schema/query as a string.

type gql = (path: string): DocumentNode 
  • path: string - Relative path to the graphql schema/query file. NOTE: This must be a string literal, dynamic paths are not supported.

3.8.7

1 year ago

3.8.4

1 year ago

3.8.6

1 year ago

3.8.5

1 year ago

3.7.3

2 years ago

3.7.2

2 years ago

3.8.0

1 year ago

3.8.3

1 year ago

3.8.2

1 year ago

3.8.1

1 year ago

3.7.1

2 years ago

3.6.5

2 years ago

3.7.0

2 years ago

3.6.2

2 years ago

3.6.4

2 years ago

3.6.3

2 years ago

3.6.1

2 years ago

3.6.0

2 years ago

3.5.7

2 years ago

3.5.9

2 years ago

3.5.8

2 years ago

3.5.3

2 years ago

3.5.2

2 years ago

3.5.6

2 years ago

3.5.5

2 years ago

3.5.4

2 years ago

3.5.1

2 years ago

3.5.0

3 years ago

3.4.16

3 years ago

3.4.14

3 years ago

3.4.15

3 years ago

3.4.13

3 years ago

3.4.11

3 years ago

3.4.12

3 years ago

3.4.10

3 years ago

3.4.9

3 years ago

3.4.8

3 years ago

3.4.7

3 years ago

3.4.6

4 years ago

3.4.5

4 years ago

3.4.4

4 years ago

3.4.3

4 years ago

3.4.2

4 years ago

3.4.1

4 years ago

3.4.0

4 years ago

3.3.2

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

2.0.0-9

5 years ago

2.0.0-8

5 years ago

2.0.0-7

5 years ago

2.0.0-6

5 years ago

2.0.0-5

5 years ago

2.0.0-4

5 years ago

2.0.0-3

5 years ago

2.0.0-2

5 years ago

2.0.0-1

5 years ago

2.0.0-0

5 years ago