How to use the relay-hooks.fetchQuery function in relay-hooks

To help you get started, we’ve selected a few relay-hooks 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 relay-tools / relay-hooks / examples / relay-hook-example / nextjs-ssr / relay / withData.tsx View on Github external
if (ComposedComponent.getInitialProps) {
      composedInitialProps = await ComposedComponent.getInitialProps(ctx);
    }
    if (!isServer) {
      return {
        ...composedInitialProps,
        environment: null,
      };
    }

    let queryRecords = {};
    const environment = initEnvironment();

    const {query, variables} = options;
    if (query) {
      await fetchQuery(environment, query, variables);
      queryRecords = environment
        .getStore()
        .getSource()
        .toJSON();
    }
    return {
      ...composedInitialProps,
      queryRecords,
      environment,
    };
  };