How to use the react-apollo.getDataFromTree function in react-apollo

To help you get started, we’ve selected a few react-apollo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alidcastano / rogue.js / packages / hocs / apollo / index.js View on Github external
async function initCache (ctx, App, client) {
  try {
    const AppWithApollo = h(ApolloProvider, { client }, h(App))
    await getDataFromTree(
      ctx.app.routable(AppWithApollo)
    )
  } catch (error) {
    // Prevent Apollo Client GraphQL errors from crashing SSR.
    // Handle them in components via the data.error prop:
    // http://dev.apollodata.com/react/api-queries.html#graphql-query-data-error
    console.error('Error while running `getDataFromTree`', error)
  }
}
github alidcastano / rogue.js / packages / rogue-hocs / apollo / index.js View on Github external
async function initCache (ctx, App, client) {
  try {
    const AppWithApollo = h(ApolloProvider, { client }, h(App))
    await getDataFromTree(
      ctx.app.routable(AppWithApollo)
    )
  } catch (error) {
    // Prevent Apollo Client GraphQL errors from crashing SSR.
    // Handle them in components via the data.error prop:
    // http://dev.apollodata.com/react/api-queries.html#graphql-query-data-error
    console.error('Error while running `getDataFromTree`', error)
  }
}
github apapacy / apollo-lesson / src / render.js View on Github external
headers: {
       cookie: req.header('Cookie'),
     },
     fetch,
   }),
   cache: new InMemoryCache(),
 });

    const context = {};
    const App =  
      
        
      
    ;

    await getDataFromTree(App)
    const html = ReactDOMServer.renderToString((App));
    const initialState = client.extract();

    res.write(`
      
      
        
          
          <title>Conduit</title>
          
          
        
        
github Sly777 / ran / libraries / withData.js View on Github external
: {}))
      };

      if (!process.browser) {
        const client = apolloClient(headers || {}, token || '', {}, ctx);
        const store = reduxStore();

        try {
          const app = (
            
              
                
              
            
          );
          await getDataFromTree(app);
        } catch (error) {
          // Prevent Apollo Client GraphQL errors from crashing SSR.
          // Handle them in components via the data.error prop:
          // https://github.com/apollographql/react-apollo/issues/406
          // http://dev.apollodata.com/react/api-queries.html#graphql-query-data-error
        }

        apolloState = client.cache.extract();
        serverState = store.getState();
      }

      return {
        reduxState: serverState,
        apolloState,
        headers,
        ...props
github smooth-code / smooth.js / packages / smooth / src / server / ssr.js View on Github external
// Generate unique request id
    const requestId = Math.random()
      .toString(36)
      .substring(7)

    const rootElement = wrapRootElement(config)({
      element: jsx,
      pathname: req.url,
      requestId,
    })

    // Loadable components
    jsx = webExtractor.collectChunks(jsx)

    await getDataFromTree(jsx)
    const apolloState = apolloClient.cache.extract()

    // Render app HTML
    const appHtml = renderToString(rootElement)

    // Handle React router status
    if (routerContext.status) {
      res.status(routerContext.status)
    }

    // Handle React Router redirection
    if (routerContext.url) {
      const status = routerContext.status === 301 ? 301 : 302
      res.redirect(status, routerContext.url)
      return
    }
github sysgears / apollo-universal-starter-kit / packages / server / src / middleware / website.jsx View on Github external
const context = {};
  const App = clientModules.getWrappedRoot(
    
      
        {clientModules.getDataRoot(
          
            {Routes}
          
        )}
      
    ,
    req
  );

  await getDataFromTree(App);

  if (context.pageNotFound === true) {
    res.status(404);
  } else {
    res.status(200);
  }

  const sheet = new ServerStyleSheet();
  const html = ReactDOMServer.renderToString(sheet.collectStyles(App));
  const css = sheet.getStyleElement().map((el, idx) =&gt; (el ? React.cloneElement(el, { key: idx }) : el));
  const helmet = Helmet.renderStatic(); // Avoid memory leak while tracking mounted instances

  if (context.url) {
    res.writeHead(301, { Location: context.url });
    res.end();
  } else {
github graphitejs / server / examples / school / lib / withData.js View on Github external
props: ctx.query,
        });
      }

      const props = {
        url: { ...ctx.query, pathname: ctx.pathname },
        ...await (Component.getInitialProps ? Component.getInitialProps(ctx) : {}),
      };

      if (!process.browser) {
        const app = (
          
            
          
        );
        await getDataFromTree(app);
      }

      const state = store.getState();

      return {
        initialState: {
          ...state,
          apollo: {
            data: client.getInitialState().data,
          },
        },
        headers,
        ...props,
      };
    }
github thetribeio / node-react-starter-kit / api / index.jsx View on Github external
const onCreateStore = (instance) =&gt; {
            onCreateStore.store = instance;
        };

        const Router = (props) =&gt; ;

        const app = (
            
        );

        await getDataFromTree(app);

        const body = renderToString(app);

        const html = renderToStaticMarkup(
            
                {body}
            ,
        );

        res.setHeader('Cache-Control', 'max-age=0, no-cache');
        res.send(`${html}`);
    } catch (error) {
github EddiG / ssr-cra-graphql / server.js View on Github external
opts: {
        credentials: 'include',
        headers: {
          cookie: req.header('Cookie'),
        },
      },
    }),
  });
  const app = (
    
      
        
      
    
  );
  await getDataFromTree(app);
  const state = { apollo: client.getInitialState() };
  const content = ReactDOMServer.renderToStaticMarkup(app);
  const helmet = Helmet.renderStatic();
  const html = ReactDOMServer.renderToStaticMarkup(
    ,
  );
  res.status(200);
  res.send(`${html}`);
  res.end();
});
github thebillkidy / MERGE-Stack / GRAPH / client / src / lib / withData.js View on Github external
const client = initClient(headers)
      const store = initStore(client, client.initialState)

      const props = {
        url: { query: ctx.query, pathname: ctx.pathname },
        ...await (Component.getInitialProps ? Component.getInitialProps(ctx) : {})
      }

      if (!process.browser) {
        const app = (
          
            
          
        )
        await getDataFromTree(app)
      }

      const state = store.getState()

      return {
        initialState: {
          ...state,
          apollo: {
            data: client.getInitialState().data
          }
        },
        headers,
        ...props
      }
    }