npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fusion-apollo

v1.6.1

Published

FusionJS entry point for React universal rendering /w Apollo

Downloads

20

Readme

fusion-apollo

Build status

Fusion.js entry point for React universal rendering with Apollo

Provides a Fusion.js application class that is pre-configured with React and Apollo universal rendering for applications leveraging GraphQL.

The App class from this package should be used when you want to perform both server and client rendering with GraphQL querying. This package will also provide initial state hydration on the client.


Table of contents


Installation

yarn add fusion-apollo

Usage

// ./src/main.js
import React from 'react';
import App, {ApolloClientToken} from 'fusion-apollo';
import ApolloClient from 'fusion-apollo-universal-client';

export default function() {
  const app = new App(<Hello />);
  app.register(ApolloClientToken, ApolloClient);
  return app;
}

Loading GraphQL Queries/Schemas

fusion-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-apollo';
const query = gql('./some-query.graphql');
const schema = gql('./some-schema.graphql');

API

Registration API

ApolloClientToken
import {ApolloClientToken} from 'fusion-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.

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

Allows registration of a context object which gets passed into every resolver. See the Apollo Client context documentation for more details.

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

Define the GraphQLSchemaToken when using a locally hosted GraphQL endpoint from within a Fusion.js application. Connect your schema to a Fusion.js server with fusion-plugin-apollo-server. You can find an example schema in the graphql-tools repo.

Types
type GraphQLSchema = string;

App

import App from 'fusion-apollo';

A class that represents an application. An application is responsible for rendering (both virtual DOM and server-side rendering). The functionality of an application is extended via plugins.

Constructor

const app: App = new App(
  (el: ReactElement),
  (render: ?(el: ReactElement) => string)
);
  • el: ReactElement - a template root. In a React application, this would be a React element created via React.createElement or a JSX expression.
  • render: ?(el:ReactElement) => string - Optional. Defines how rendering should occur.

app.(register|middleware|enhance|cleanup)

See the fusion-core app methods for further information on provided methods. Fusion-apollo does not add additional app methods besides the inherited fusion-core methods.

gql

import {gql} from 'fusion-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.

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

Providers

As a convenience, fusion-apollo re-exports providers from fusion-react. You can find additional information on those as follows: