Skip to content

Commit d20bf71

Browse files
author
Guillaume Chau
committed
Doc updates & fixes
1 parent 4096d00 commit d20bf71

File tree

1 file changed

+87
-85
lines changed

1 file changed

+87
-85
lines changed

README.md

Lines changed: 87 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Integrates [apollo](https://www.apollographql.com/) in your [Vue](http://vuejs.o
4848
- [Special options](#special-options)
4949
- [Skip all](#skip-all)
5050
- [Multiple clients](#multiple-clients)
51-
- [Server-Side Rendering](#server-side-rendering)
5251
- [Query Components](#query-components)
52+
- [Server-Side Rendering](#server-side-rendering)
5353
- [Migration](#migration)
5454
- [API Reference](#api-reference)
5555

@@ -1199,6 +1199,91 @@ tags: {
11991199
}
12001200
```
12011201

1202+
## Query components
1203+
1204+
(WIP) You can use the `ApolloQuery` (or `apollo-query`) component to make watched Apollo queries directly in your template:
1205+
1206+
```html
1207+
<ApolloQuery
1208+
:query="require('../graphql/HelloWorld.gql')"
1209+
:variables="{ name }"
1210+
>
1211+
<template slot-scope="{ result: { loading, error, data } }">
1212+
<!-- Loading -->
1213+
<div v-if="loading" class="loading apollo">Loading...</div>
1214+
1215+
<!-- Error -->
1216+
<div v-else-if="error" class="error apollo">An error occured</div>
1217+
1218+
<!-- Result -->
1219+
<div v-else-if="data" class="result apollo">{{ data.hello }}</div>
1220+
1221+
<!-- No result -->
1222+
<div v-else class="no-result apollo">No result :(</div>
1223+
</template>
1224+
</ApolloQuery>
1225+
```
1226+
1227+
Props:
1228+
1229+
- `query`: GraphQL query (transformed by `graphql-tag`)
1230+
- `variables`: Object of GraphQL variables
1231+
- `fetchPolicy`: See [apollo fetchPolicy](https://www.apollographql.com/docs/react/basics/queries.html#graphql-config-options-fetchPolicy)
1232+
- `pollInterval`: See [apollo pollInterval](https://www.apollographql.com/docs/react/basics/queries.html#graphql-config-options-pollInterval)
1233+
- `notifyOnNetworkStatusChange`: See [apollo notifyOnNetworkStatusChange](https://www.apollographql.com/docs/react/basics/queries.html#graphql-config-options-notifyOnNetworkStatusChange)
1234+
- `context`: See [apollo context](https://www.apollographql.com/docs/react/basics/queries.html#graphql-config-options-context)
1235+
- `skip`: Boolean disabling query fetching
1236+
- `clienId`: Used to resolve the Apollo Client used (defined in ApolloProvider)
1237+
- `tag`: String HTML tag name (default: `div`)
1238+
1239+
Scoped slot props:
1240+
- `result`: Apollo Query result
1241+
- `result.data`: Data returned by the query
1242+
- `result.loading`: Boolean indicating that a request is in flight
1243+
- `result.error`: Eventual error for the current result
1244+
- `result.networkStatus`: See [apollo networkStatus](https://www.apollographql.com/docs/react/basics/queries.html#graphql-query-data-networkStatus)
1245+
- `query`: Smart Query associated with the component
1246+
1247+
(WIP) You can subscribe to more data with the `ApolloSubscribeToMore` (or `apollo-subscribe-to-more`) component:
1248+
1249+
```html
1250+
<template>
1251+
<ApolloQuery :query="...">
1252+
<ApolloSubscribeToMore
1253+
:document="require('../gql/MessageAdded.gql')"
1254+
:variables="{ channel }"
1255+
:updateQuery="onMessageAdded"
1256+
/>
1257+
1258+
<!-- ... -->
1259+
</ApolloQuery>
1260+
</template>
1261+
1262+
<script>
1263+
export default {
1264+
data () {
1265+
return {
1266+
channel: 'general',
1267+
}
1268+
},
1269+
1270+
methods: {
1271+
onMessageAdded (previousResult, { subscriptionData }) {
1272+
// The previous result is immutable
1273+
const newResult = {
1274+
messages: [...previousResult.messages],
1275+
}
1276+
// Add the question to the list
1277+
newResult.messages.push(subscriptionData.data.messageAdded)
1278+
return newResult
1279+
},
1280+
},
1281+
}
1282+
</script>
1283+
```
1284+
1285+
*You can put as many of those as you want inside a `<ApolloQuery>` component.*
1286+
12021287
## Server-Side Rendering
12031288

12041289
### Prefetch components
@@ -1480,7 +1565,7 @@ function createApp (context) {
14801565
el: '#app',
14811566
router,
14821567
store,
1483-
apolloProvider,
1568+
provide: apolloProvider.provide(),
14841569
...App,
14851570
}),
14861571
router,
@@ -1520,89 +1605,6 @@ router.onReady(() => {
15201605
})
15211606
```
15221607

1523-
## Query components
1524-
1525-
(WIP) You can use the `ApolloQuery` (or `apollo-query`) component to make watched Apollo queries directly in your template:
1526-
1527-
```html
1528-
<ApolloQuery
1529-
:query="require('../graphql/HelloWorld.gql')"
1530-
:variables="{ name }"
1531-
>
1532-
<template slot-scope="{ result: { loading, error, data } }">
1533-
<!-- Loading -->
1534-
<div v-if="loading" class="loading apollo">Loading...</div>
1535-
1536-
<!-- Error -->
1537-
<div v-else-if="error" class="error apollo">An error occured</div>
1538-
1539-
<!-- Result -->
1540-
<div v-else-if="data" class="result apollo">{{ data.hello }}</div>
1541-
1542-
<!-- No result -->
1543-
<div v-else class="no-result apollo">No result :(</div>
1544-
</template>
1545-
</ApolloQuery>
1546-
```
1547-
1548-
Props:
1549-
1550-
- `query`: GraphQL query (transformed by `graphql-tag`)
1551-
- `variables`: Object of GraphQL variables
1552-
- `fetchPolicy`: See [apollo fetchPolicy](https://www.apollographql.com/docs/react/basics/queries.html#graphql-config-options-fetchPolicy)
1553-
- `pollInterval`: See [apollo pollInterval](https://www.apollographql.com/docs/react/basics/queries.html#graphql-config-options-pollInterval)
1554-
- `notifyOnNetworkStatusChange`: See [apollo notifyOnNetworkStatusChange](https://www.apollographql.com/docs/react/basics/queries.html#graphql-config-options-notifyOnNetworkStatusChange)
1555-
- `context`: See [apollo context](https://www.apollographql.com/docs/react/basics/queries.html#graphql-config-options-context)
1556-
- `skip`: Boolean disabling query fetching
1557-
- `clienId`: Used to resolve the Apollo Client used (defined in ApolloProvider)
1558-
- `tag`: String HTML tag name (default: `div`)
1559-
1560-
Scoped slot props:
1561-
- `result`: Apollo Query result
1562-
- `result.data`: Data returned by the query
1563-
- `result.loading`: Boolean indicating that a request is in flight
1564-
- `result.error`: Eventual error for the current result
1565-
- `result.networkStatus`: See [apollo networkStatus](https://www.apollographql.com/docs/react/basics/queries.html#graphql-query-data-networkStatus)
1566-
- `query`: Smart Query associated with the component
1567-
1568-
(WIP) You can subscribe to mode data with the `ApolloSubscribeToMore` (or `apollo-subscribe-to-more`) component:
1569-
1570-
```html
1571-
<template>
1572-
<ApolloQuery>
1573-
<ApolloSubscribeToMore
1574-
:document="require('../gql/MessageAdded.gql')"
1575-
:variables="{ channel }"
1576-
:updateQuery="onMessageAdded"
1577-
/>
1578-
</ApolloQuery>
1579-
</template>
1580-
1581-
<script>
1582-
export default {
1583-
data () {
1584-
return {
1585-
channel: 'general',
1586-
}
1587-
},
1588-
1589-
methods: {
1590-
onMessageAdded (previousResult, { subscriptionData }) {
1591-
// The previous result is immutable
1592-
const newResult = {
1593-
messages: [...previousResult.messages],
1594-
}
1595-
// Add the question to the list
1596-
newResult.messages.push(subscriptionData.data.messageAdded)
1597-
return newResult
1598-
},
1599-
},
1600-
}
1601-
</script>
1602-
```
1603-
1604-
*You can put as many of those as you want inside a `<ApolloQuery>` component.*
1605-
16061608
---
16071609

16081610
# Migration

0 commit comments

Comments
 (0)