@shopify/react-effect-apollo
A bridging layer between react-apollo and react-effect.
Last updated 17 days ago by shopify-dep .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @shopify/react-effect-apollo 
SYNC missed versions from official npm registry.

@shopify/react-effect-apollo

Note: this library is no longer maintained. Developers should use the GraphQLUniversalProvider from @shopify/react-graphql-universal-provider to wait for GraphQL queries to resolve on the server, and to perform automatic serialization.

Build Status License: MIT npm version npm bundle size (minified + gzip)

A bridging layer between react-apollo and react-effect.

Installation

$ yarn add @shopify/react-effect-apollo

Usage

react-apollo exposes a function, getDataFromTree, which performs a sequence of tree traversals to resolve GraphQL data. This can be wasteful in situations where you are already traversing the tree for other purposes, like resolving translations in @shopify/react-i18n, or extracting network details in @shopify/react-network. This package provides a way of resolving Apollo’s data with just a single call of @shopify/react-effect’s extract() function, which will also extract all other server details from packages using @shopify/react-effect.

To use this package, create a new "bridge" component from the exposed createApolloBridge function in your server code. Then, wrap this bridge around your application when calling extract(). That’s all there is to it!

import {renderToString} from 'react-dom/server';
import ApolloClient from 'apollo-client';
import {createApolloBridge} from '@shopify/react-effect-apollo';
import {extract} from '@shopify/react-effect/server';
import App from './App';

export async function middleware(ctx) {
  const client = new ApolloClient /* client config */();
  const ApolloBridge = createApolloBridge();
  const app = <App apolloClient={client} />; // or however you pass your client

  await extract(app, {
    render(element) {
      return <ApolloBridge>{element}</ApolloBridge>;
    },
  });

  ctx.body = renderToString(app);
}

Options

createApolloBridge accepts the following options:

  • inflightQueryBehavior: a member of the InflightQueryBehavior enum, which is exported from this package. Can be either InflightQueryBehavior.RenderSubtree, which will render the entire tree, including children of Apollo Query components that have not been resolved yet, or InflightQueryBehavior.SkipSubtree, which will return null from Query components until their data is fetched.

    The default is to render the entire tree, which is consistent with how Apollo works on the client but may lead to unnecessary queries being run. InflightQueryBehavior.SkipSubtree is the default behavior for Apollo’s built-in getDataFromTree.

Current Tags

  • 4.0.3                                ...           latest (17 days ago)

22 Versions

  • 4.0.3                                ...           17 days ago
  • 4.0.2                                ...           2 months ago
  • 4.0.1                                ...           2 months ago
  • 4.0.0                                ...           4 months ago
  • 3.0.11                                ...           4 months ago
  • 3.0.10                                ...           5 months ago
  • 3.0.9                                ...           5 months ago
  • 3.0.8                                ...           5 months ago
  • 3.0.7                                ...           7 months ago
  • 3.0.6                                ...           7 months ago
  • 3.0.5                                ...           8 months ago
  • 3.0.4                                ...           9 months ago
  • 3.0.3                                ...           9 months ago
  • 3.0.2                                ...           9 months ago
  • 3.0.1                                ...           9 months ago
  • 3.0.0                                ...           10 months ago
  • 2.0.3                                ...           10 months ago
  • 2.0.2                                ...           10 months ago
  • 2.0.1                                ...           10 months ago
  • 2.0.0                                ...           10 months ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Downloads
Today 0
This Week 22
This Month 40
Last Day 0
Last Week 0
Last Month 42
Dependencies (0)
None
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |