apollo-boost#InMemoryCache JavaScript Examples
The following examples show how to use
apollo-boost#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: graphql.js From mongodb-graphql-demo with Apache License 2.0 | 6 votes |
initGraphQLClient = () => {
hasLoggedInUser();
if (!hasLoggedInUser()) {
loginAnonymous();
}
if (hasLoggedInUser()) {
const accessToken = getCurrentUser().auth.activeUserAuthInfo.accessToken;
// Add an Authorization header to each GraphQL request
const authLink = setContext((_, { headers }) => ({
headers: {
...headers,
Authorization: `Bearer ${accessToken}`,
},
}));
// Connect Apollo to the GraphQL Endpoint
const GRAPHQL_URL = `https://stitch.mongodb.com/api/client/v2.0/app/${CONFIG.APP_ID}/graphql`;
const httpLink = new HttpLink({ uri: GRAPHQL_URL });
// Instantiate the Apollo Client
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache(),
});
return client;
}
}
Example #2
Source File: auth.js From React-Messenger-App with MIT License | 5 votes |
function create(initialState, { getToken }) {
const httpLink = createHttpLink({
uri: "http://localhost:4000"
//credentials: "same-origin"
});
const authLink = setContext((_, { headers }) => {
const token = getToken();
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : ""
}
};
});
let link = authLink.concat(httpLink);
if (process.browser) {
const token = getToken();
const wsLink = new WebSocketLink({
uri: `ws://localhost:4000`,
options: {
reconnect: true,
connectionParams: {
Authorization: `Bearer ${token}`
}
}
});
link = split(
// split based on operation type
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === "OperationDefinition" && operation === "subscription";
},
wsLink,
authLink.concat(httpLink)
);
}
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
return new ApolloClient({
connectToDevTools: process.browser,
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
link,
cache: new InMemoryCache().restore(initialState || {})
});
}
Example #3
Source File: App.jsx From web-frontend with MIT License | 5 votes |
createApolloClient = (cache = {}) =>
new ApolloClient({
ssrMode: typeof window !== "undefined",
cache: new InMemoryCache().restore(cache),
link: createUploadLink({ uri: "http://77.228.91.193:4000/graphql" }),
})
Example #4
Source File: main.js From graphql-sample-apps with Apache License 2.0 | 5 votes |
client = new ApolloClient({
uri: "http://localhost:8080/graphql",
cache: new InMemoryCache(),
})
Example #5
Source File: main.js From graphql-sample-apps with Apache License 2.0 | 5 votes |
client = new ApolloClient({
uri: "http://localhost:8080/graphql",
cache: new InMemoryCache(),
})
Example #6
Source File: main.js From graphql-sample-apps with Apache License 2.0 | 5 votes |
client = new ApolloClient({
uri: "http://localhost:8080/graphql",
cache: new InMemoryCache(),
})
Example #7
Source File: main.js From graphql-sample-apps with Apache License 2.0 | 5 votes |
client = new ApolloClient({
uri: "http://localhost:8080/graphql",
cache: new InMemoryCache(),
})
Example #8
Source File: App.js From Gameplayer with MIT License | 5 votes |
client = new ApolloClient({
uri: process.env.REACT_APP_GRAPHQL_ENDPOINT,
cache: new InMemoryCache(),
})