Created
February 15, 2019 20:08
-
-
Save hwillson/0683986dbcdf301527339412bfe1732b to your computer and use it in GitHub Desktop.
Apollo Client - 2.5.0 Announcement Post - 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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