Skip to content

Instantly share code, notes, and snippets.

@hwillson
Created February 15, 2019 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hwillson/0683986dbcdf301527339412bfe1732b to your computer and use it in GitHub Desktop.
Save hwillson/0683986dbcdf301527339412bfe1732b to your computer and use it in GitHub Desktop.
Apollo Client - 2.5.0 Announcement Post - 1
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import gql from 'graphql-tag';
const GET_CART_ITEMS = gql`
query GetCartItems {
cartItems @client
}
`;
const client = new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
uri: 'http://localhost:4000/graphql',
}),
resolvers: {
Launch: {
isInCart: (launch, _args, { cache }) => {
const { cartItems } = cache.readQuery({ query: GET_CART_ITEMS });
return cartItems.includes(launch.id);
},
},
},
});
const GET_LAUNCH_DETAILS = gql`
query LaunchDetails($launchId: ID!) {
launch(id: $launchId) {
isInCart @client
site
rocket {
type
}
}
}
`;
// ... run the query using client.query, a <Query /> component, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment