How to use the apollo-client.readQueryFromStore function in apollo-client

To help you get started, we’ve selected a few apollo-client 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 apollographql / react-apollo / src / connect.tsx View on Github external
for (const key in queryOptions) {
            if (!queryOptions.hasOwnProperty(key)) {
              continue;
            }

            const { query, variables, forceFetch } = queryOptions[key];

            const observableQuery = watchQuery(queryOptions[key]);

            // rudimentary way to manually check cache
            let queryData = defaultQueryData as any;

            // force fetch shouldn't try to read from the store
            if (!forceFetch) {
              try {
                const result = readQueryFromStore({
                  store: store.getState()[reduxRootKey].data,
                  query,
                  variables,
                });

                queryData = assign({
                  errors: null,
                  loading: false,
                }, result);
              } catch (e) {/* tslint */}
            }

            this.data[key] = queryData;

            this.handleQueryData(observableQuery, key);
          }