apollo-cache-inmemory#InMemoryCache JavaScript Examples

The following examples show how to use apollo-cache-inmemory#InMemoryCache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: render.js    From tunnel-tool with MIT License 7 votes vote down vote up
configureGraph = ({ url, req }) => ({
  graph: new ApolloClient({
    ssrMode: true,
    link: new HttpLink({
      uri: url,
      onError: e => {
        console.log("APOLLO_CLIENT_ERROR");
        console.log(e.graphQLErrors);
      },
      credentials: "include",
      fetch: fetch,
      headers: {
        cookie: req.header("Cookie")
      }
    }),
    cache: new InMemoryCache()
  })
})
Example #2
Source File: apolloClient.js    From dineforward with MIT License 7 votes vote down vote up
export default function createApolloClient(initialState, ctx) {
  const linkOpts = {
    uri: apiUrl, // Server URL (must be absolute)
    credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers`
    fetch,
  };

  // The `ctx` (NextPageContext) will only be present on the server.
  // use it to extract auth headers (ctx.req) or similar.
  // The Keystone session ID cookie will be present here if this is SSR and
  // the user has a session.
  const sid = ctx && ctx['keystone.sid'];
  if (sid) linkOpts.headers = { 'keystone.sid': ctx['keystone.sid'] };

  return new ApolloClient({
    ssrMode: Boolean(ctx),
    link: new HttpLink(linkOpts),
    cache: new InMemoryCache().restore(initialState),
  });
}
Example #3
Source File: App.js    From graphql-sample-apps with Apache License 2.0 6 votes vote down vote up
createApolloClient = token => {
  const httpLink = createHttpLink({
    uri: config.graphqlUrl,
    options: {
      reconnect: true,
    },
  });

  const authLink = setContext((_, { headers }) => {
    // return the headers to the context so httpLink can read them
    return {
      headers: {
        ...headers,
        "X-Auth-Token": token,
      },
    };
  });

  return new ApolloClient({
    link: authLink.concat(httpLink),
    cache: new InMemoryCache()
  });
}
Example #4
Source File: App.js    From graphql-sample-apps with Apache License 2.0 6 votes vote down vote up
createApolloClient = token => {
  const httpLink = createHttpLink({
    uri: getSlashGraphQLEndpoint(),
    options: {
      reconnect: true,
    },
  });

  const authLink = setContext((request, { headers }) => {
    // return the header to the context so httpLink can read them
    return {
      headers: {
        ...headers,
        "X-Auth-Token": token,
      },
    };
  });

  return new ApolloClient({
    link: authLink.concat(httpLink),
    cache: new InMemoryCache()
  });
}
Example #5
Source File: App.js    From graphql-sample-apps with Apache License 2.0 6 votes vote down vote up
createApolloClient = () => {
  const httpLink = createHttpLink({
    uri: process.env.REACT_APP_GRAPHQL_ENDPOINT,
    options: {
      reconnect: true,
    },
  });

  return new ApolloClient({
    link: httpLink,
    cache: new InMemoryCache()
  });
}
Example #6
Source File: index.js    From graphql-sample-apps with Apache License 2.0 6 votes vote down vote up
client = new ApolloClient({
    link: httpLink,
    cache: new InMemoryCache(),
    request: operation => {
      operation.setContext({
        fetchOptions: {
          mode: "no-cors"
        }
      });
    },
    defaultOptions: {
      query: {
        fetchPolicy: 'network-only',
        errorPolicy: 'all'
      }
    }
})
Example #7
Source File: index.js    From graphql-sample-apps with Apache License 2.0 6 votes vote down vote up
client = new ApolloClient({
  link: trackMetrics.concat(httpLink),
  cache: new InMemoryCache(),
  request: (operation) => {
    operation.setContext({
      fetchOptions: {
        mode: "no-cors",
      },
    });
  },
  defaultOptions: {
    query: {
      fetchPolicy: "network-only",
      errorPolicy: "all",
    },
  },
})
Example #8
Source File: client.js    From mailmask with GNU Affero General Public License v3.0 6 votes vote down vote up
createApolloClient = ({ endpoint, name, initialState = {} }) => {
  const cache = new InMemoryCache({ fragmentMatcher }).restore(initialState)

  const client = new ApolloClient({
    name,
    cache,
    typeDefs: getTypeDefs(),
    link: createLinks({ cache, endpoint }),
  })

  return client
}
Example #9
Source File: _app.jsx    From teach-yourself-code with MIT License 6 votes vote down vote up
createApolloClient = () => {
  return new ApolloClient({
    link: new HttpLink({
      uri: `${hasuraEndpoint}`,
      headers: {
        authorization: `Bearer ${authToken}`,
        "x-hasura-admin-secret": `${adminSecret}`,
      },
    }),
    cache: new InMemoryCache(),
  });
}
Example #10
Source File: newApolloClient.js    From pods-frontend with MIT License 6 votes vote down vote up
export function newApolloClient({ provider }) {
  const tb = new Tightbeam({
    providerSource: () => provider,
    abiMapping: newAbiMapping()
  })
  const cache = new InMemoryCache()
  cache.writeData(tb.defaultCacheData())
  const client = new ApolloClient({
    cache,
    resolvers: tb.resolvers(),
    typeDefs: typeDefs
  });

  client.watchQuery({
    query: gql`query {
      network @client {
        id
        chainId
        name
      }
    }`,
    pollInterval: 2000,
    fetchPolicy: 'network-only'
  }).subscribe()

  client.watchQuery({
    query: gql`query { account @client }`,
    pollInterval: 2000,
    fetchPolicy: 'network-only'
  }).subscribe()

  return client
}
Example #11
Source File: CategoryPage.test.js    From trashpanda-fe with MIT License 6 votes vote down vote up
describe("CategoryPage", () => {
  const cache = new InMemoryCache();

  afterEach(cleanup);

  it("renders CategoryPage and title based on description of mock Category 1(using params argument)", async () => {
    const page = render(
      <MockedProvider cache={cache} addTypename={false}>
        <CategoryPage categories={mockCategoryList} materials={mockMaterials} />
      </MockedProvider>
    );
    page.debug();
    await waitForElement(() => page.getByText(/first family/i));
  });

  it("renders CategoryPage and, after iterating over mocked catergory 1 material_ids, it renders grid cards with names of mocked material instances 1, 2 and 4", async () => {
    const page = render(
      <MockedProvider cache={cache} addTypename={false}>
        <CategoryPage categories={mockCategoryList} materials={mockMaterials} />
      </MockedProvider>
    );
    page.debug();
    await waitForElement(() => page.getByText(/first material/i));
    await waitForElement(() => page.getByText(/second material/i));
    await waitForElement(() => page.getByText(/fourth material/i));
  });
});
Example #12
Source File: seed-db.js    From willow-grandstack with Apache License 2.0 5 votes vote down vote up
client = new ApolloClient({
  link: new HttpLink({ uri, fetch }),
  cache: new InMemoryCache(),
})
Example #13
Source File: client.js    From pancake-info-v1 with GNU General Public License v3.0 5 votes vote down vote up
client = new ApolloClient({
  link: new HttpLink({
    uri: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange',
  }),
  cache: new InMemoryCache(),
  shouldBatch: true,
})
Example #14
Source File: client.js    From horondi_client_fe with MIT License 5 votes vote down vote up
client = new ApolloClient({
  fetch,
  link: ApolloLink.from([terminatingLink]),
  cache: new InMemoryCache({
    addTypename: false,
    fragmentMatcher
  })
})
Example #15
Source File: client.js    From pancake-info-v1 with GNU General Public License v3.0 5 votes vote down vote up
healthClient = new ApolloClient({
  link: new HttpLink({
    uri: 'https://api.thegraph.com/index-node/graphql',
  }),
  cache: new InMemoryCache(),
  shouldBatch: true,
})
Example #16
Source File: client.js    From pancake-info-v1 with GNU General Public License v3.0 5 votes vote down vote up
blockClient = new ApolloClient({
  link: new HttpLink({
    uri: 'https://api.thegraph.com/subgraphs/name/pancakeswap/blocks',
  }),
  cache: new InMemoryCache(),
})
Example #17
Source File: request.js    From ncovis-2020 with MIT License 5 votes vote down vote up
cache = new InMemoryCache({})
Example #18
Source File: apolloClient.js    From web with MIT License 5 votes vote down vote up
cache = new InMemoryCache()
Example #19
Source File: graphql.js    From lifebank with MIT License 5 votes vote down vote up
client = new ApolloClient({
  link,
  cache: new InMemoryCache()
})
Example #20
Source File: main.js    From minimal-portfolio with GNU General Public License v3.0 5 votes vote down vote up
cache = new InMemoryCache()
Example #21
Source File: render.js    From tunnel-tool with MIT License 5 votes vote down vote up
configureGraph = ({ url, initState }) => {
  return new ApolloClient({
    cache: new InMemoryCache().restore(window.__APOLLO_STATE__),
    link: new HttpLink({ uri: url })
  });
}
Example #22
Source File: App.js    From project-avocado-web with MIT License 5 votes vote down vote up
cache = new InMemoryCache()
Example #23
Source File: App.js    From graphql-sample-apps with Apache License 2.0 5 votes vote down vote up
export default function App() {
  const { loading } = useAuth0();
  
  if (loading) {
    return <div>Loading...</div>;
  }
  const httpLink = createHttpLink({
    uri: "http://localhost:8080/graphql"
  });
  
  const client = new ApolloClient({
    link: httpLink,
    cache: new InMemoryCache(),
    request: operation => {
      operation.setContext({
        fetchOptions: {
          mode: "no-cors"
        }
      });
    },
    defaultOptions: {
      query: {
        fetchPolicy: 'network-only',
        errorPolicy: 'all'
      }
    }
  });

  return (
    <ApolloProvider client={client}>
      <div className="container">
        <Router history={history}>
          <Header />
          <Switch>
            <PrivateRoute exact path="/" component={QuestionList} />
            <PrivateRoute exact path="/create" component={CreateQuestion} />
            <PrivateRoute exact path="/view" component={ViewQuestion} />
          </Switch>
        </Router>
      </div>
    </ApolloProvider>
  );
}
Example #24
Source File: App.js    From graphql-sample-apps with Apache License 2.0 5 votes vote down vote up
export default function App() {
  const { loading, user } = useAuth0();
  let headers
  if (user !== undefined) {
    headers = {"username": user.email, "email": user.email}
  }
  if (loading) {
    return <div>Loading...</div>;
  }
  const httpLink = createHttpLink({
    uri: "http://localhost:4000/graphql",
    headers: headers
  });
  
  const client = new ApolloClient({
    link: httpLink,
    cache: new InMemoryCache(),
    request: operation => {
      operation.setContext({
        fetchOptions: {
          mode: "no-cors"
        }
      });
    },
    defaultOptions: {
      query: {
        fetchPolicy: 'network-only',
        errorPolicy: 'all'
      }
    }
  });

  return (
    <ApolloProvider client={client}>
      <div className="container">
        <Router history={history}>
          <Header />
          <Switch>
            <PrivateRoute exact path="/" component={QuestionList} />
            <PrivateRoute exact path="/create" component={CreateQuestion} />
            <PrivateRoute exact path="/view" component={ViewQuestion} />
          </Switch>
        </Router>
      </div>
    </ApolloProvider>
  );
}
Example #25
Source File: index.js    From reactnative-best-practice with MIT License 5 votes vote down vote up
client = new ApolloClient({
  link: createHttpLink({uri: 'http://devcloud3.digihcs.com:14047/graphqlhrm'}),
  cache: new InMemoryCache(),
  // link: ApolloLink.from([errorLink, authLink, terminalLink]),
})
Example #26
Source File: App.js    From spells-fyi with MIT License 5 votes vote down vote up
client = new ApolloClient({
  link: split(
    operation => operation.getContext().clientName === "github", // Routes the query to the proper client
    githubLink,
    thegraphLink
  ),
  cache: new InMemoryCache()
})
Example #27
Source File: index.js    From Lambda with MIT License 5 votes vote down vote up
cache = new InMemoryCache()
Example #28
Source File: index.js    From desktop with GNU General Public License v3.0 5 votes vote down vote up
client = new ApolloClient({
  // Disables forceFetch on the server (so queries are only run once)
  ssrMode: typeof window === "undefined",
  link: ApolloLink.from([new RetryLink(), authLink, httpLink]),
  cache: new InMemoryCache().restore(initialState)
})
Example #29
Source File: client.js    From spooky-info with GNU General Public License v3.0 5 votes vote down vote up
blockClient = new ApolloClient({
  link: new HttpLink({
    uri: 'https://api.fura.org/subgraphs/name/spookyswap',
  }),
  cache: new InMemoryCache(),
})