vue-cli-plugin-apollo
Version:
vue-cli 3 plugin to add Apollo and GraphQL
51 lines (42 loc) • 958 B
Markdown
# Client state
You can use [local state](https://www.apollographql.com/docs/tutorial/local-state/) for client-only local data with the related options of `createApolloClient`:
```js
import gql from 'graphql-tag'
import { createApolloClient } from 'vue-cli-plugin-apollo/graphql-client'
const options = {
// ...
typeDefs: gql`
type Query {
connected: Boolean!
}
`,
resolvers: {
Mutation: {
connectedSet: (root, { value }, { cache }) => {
const data = {
connected: value,
}
cache.writeData({ data })
},
},
},
onCacheInit: cache => {
const data = {
connected: false,
}
cache.writeData({ data })
},
}
const { apolloClient } = createApolloClient(options)
```
Then you need to use the ` ` directive:
```graphql
query isConnected {
connected
}
```
```graphql
mutation setConnected ($value: Boolean!) {
connectedSet (value: $value)
}
```