1
1
# apollo-magic-refetch
2
2
3
- [ ![ Build Status ] ( https://travis-ci.org/ jcoreio/apollo-magic-refetch.svg?branch=master )] ( https://travis-ci.org /jcoreio/apollo-magic-refetch )
3
+ [ ![ CircleCI ] ( https://circleci.com/gh/ jcoreio/apollo-magic-refetch.svg?style=svg )] ( https://circleci.com/gh /jcoreio/apollo-magic-refetch )
4
4
[ ![ Coverage Status] ( https://codecov.io/gh/jcoreio/apollo-magic-refetch/branch/master/graph/badge.svg )] ( https://codecov.io/gh/jcoreio/apollo-magic-refetch )
5
5
[ ![ semantic-release] ( https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg )] ( https://github.com/semantic-release/semantic-release )
6
6
[ ![ Commitizen friendly] ( https://img.shields.io/badge/commitizen-friendly-brightgreen.svg )] ( http://commitizen.github.io/cz-cli/ )
@@ -20,19 +20,19 @@ Until that happens, this is probably your best bet!
20
20
21
21
# Table of Contents
22
22
23
- * [ How it works] ( #how-it-works )
24
- * [ Current limitations] ( #current-limitations )
25
- * [ ES environment requirements] ( #es-environment-requirements )
26
- * [ Type metadata usage] ( #type-metadata-usage )
27
- * [ Handling Deletions] ( #handling-deletions )
28
- * [ Handling Creation] ( #handling-creation )
29
- * [ Handling associations being broken] ( #handling-associations-being-broken )
30
- * [ Handling associations being created] ( #handling-associations-being-created )
31
- * [ API] ( #api )
32
- + [ ` refetch(client, typenameOrTerms, [predicate, [idField]]) ` ] ( #refetchclient-typenameorterms-predicate-idfield )
33
- + [ ` refetch.fetchTypeMetadata(client) ` ] ( #refetchfetchtypemetadataclient )
34
- + [ ` refetch.setTypeMetadata(typeMetadataPromise) ` ] ( #refetchsettypemetadatatypemetadatapromise )
35
- + [ ` typesQuery ` ] ( #typesquery )
23
+ - [ How it works] ( #how-it-works )
24
+ - [ Current limitations] ( #current-limitations )
25
+ - [ ES environment requirements] ( #es-environment-requirements )
26
+ - [ Type metadata usage] ( #type-metadata-usage )
27
+ - [ Handling Deletions] ( #handling-deletions )
28
+ - [ Handling Creation] ( #handling-creation )
29
+ - [ Handling associations being broken] ( #handling-associations-being-broken )
30
+ - [ Handling associations being created] ( #handling-associations-being-created )
31
+ - [ API] ( #api )
32
+ - [ ` refetch(client, typenameOrTerms, [predicate, [idField]]) ` ] ( #refetchclient-typenameorterms-predicate-idfield )
33
+ - [ ` refetch.fetchTypeMetadata(client) ` ] ( #refetchfetchtypemetadataclient )
34
+ - [ ` refetch.setTypeMetadata(typeMetadataPromise) ` ] ( #refetchsettypemetadatatypemetadatapromise )
35
+ - [ ` typesQuery ` ] ( #typesquery )
36
36
37
37
## How it works
38
38
@@ -52,9 +52,9 @@ all pertinent mutations.
52
52
53
53
## Current limitations
54
54
55
- * Interfaces and union types are not supported yet. This means if they are
56
- anywhere in your results, this library may fail to refetch when it should.
57
- * Lists of lists are not supported yet.
55
+ - Interfaces and union types are not supported yet. This means if they are
56
+ anywhere in your results, this library may fail to refetch when it should.
57
+ - Lists of lists are not supported yet.
58
58
59
59
## ES environment requirements
60
60
@@ -95,7 +95,7 @@ const app = express()
95
95
const typeMetadataPromise = execute (schema, typesQuery)
96
96
97
97
app .get (' /graphql/refetchTypeMetadata' , (req , res ) => {
98
- typeMetadataPromise .then (data => res .json (data))
98
+ typeMetadataPromise .then (( data ) => res .json (data))
99
99
})
100
100
```
101
101
@@ -107,14 +107,14 @@ import refetch from 'apollo-magic-refetch'
107
107
108
108
// accepts a promise that resolves to the graphql execution result.
109
109
refetch .setTypeMetadata (
110
- fetch (' /graphql/refetchTypeMetadata' ).then (res => res .json ())
110
+ fetch (' /graphql/refetchTypeMetadata' ).then (( res ) => res .json ())
111
111
)
112
112
```
113
113
114
114
## Handling Deletions
115
115
116
116
Typically you call ` refetch ` within the ` update ` callback of your ` Mutation `
117
- that deletes objects. You just have to call ` refetch ` with the ` __typename `
117
+ that deletes objects. You just have to call ` refetch ` with the ` __typename `
118
118
that was deleted (in this case, ` Device ` ) and the ` id ` of the deleted object.
119
119
This refetches any active queries that contain the deleted object in cached data.
120
120
@@ -152,13 +152,13 @@ const DestroyDeviceButton = ({deviceId}) => (
152
152
## Handling Creation
153
153
154
154
Typically you call ` refetch ` within the ` update ` callback of your ` Mutation `
155
- that creates objects. You just have to call ` refetch ` with the ` __typename `
155
+ that creates objects. You just have to call ` refetch ` with the ` __typename `
156
156
that was created.
157
157
158
158
Unlike deletions, you don't pass the ` id ` of the created
159
- object. Without a specific ` id ` to search for, it simply refetches all active
159
+ object. Without a specific ` id ` to search for, it simply refetches all active
160
160
queries that contain any object of the requested ` __typename ` in their cached
161
- data, in case the created object belongs in the new results. This is less
161
+ data, in case the created object belongs in the new results. This is less
162
162
efficient than refetching queries containing a specific ` id ` , but far easier
163
163
than manually inserting the created object into each relevant query.
164
164
@@ -204,7 +204,10 @@ sublist of `User`s. When one or more users is removed from an organization,
204
204
it makes the following call:
205
205
206
206
``` js
207
- refetch (client, [[' User' , userIds], [' Organization' , organizationId]])
207
+ refetch (client, [
208
+ [' User' , userIds],
209
+ [' Organization' , organizationId],
210
+ ])
208
211
```
209
212
210
213
Passing an array to ` refetch ` means to only refetch queries containing all of
@@ -320,16 +323,16 @@ const mutation = gql`
320
323
321
324
const CreateUserFormContainer = ({ organizationId }) => (
322
325
< ApolloConsumer>
323
- {client => (
326
+ {( client ) => (
324
327
< Mutation
325
328
mutation= {mutation}
326
329
update= {() =>
327
330
refetch (client, [[' User' ], [' Organization' , organizationId]])
328
331
}
329
332
>
330
- {createUser => (
333
+ {( createUser ) => (
331
334
< CreateUserForm
332
- onSubmit= {values =>
335
+ onSubmit= {( values ) =>
333
336
createUser ({
334
337
variables: { organizationId, values },
335
338
})
@@ -382,7 +385,7 @@ The name of the id field in the type that was deleted. This is only used if
382
385
### `refetch.fetchTypeMetadata (client )`
383
386
384
387
Prefetches type metadata by running an introspection query on the given on
385
- `ApolloClient`. The server must support client introspection queries;
388
+ `ApolloClient`. The server must support client introspection queries;
386
389
otherwise use [`refetch.setTypeMetadata`](#refetchsettypemetadatatypemetadatapromise).
387
390
388
391
#### Arguments
@@ -410,7 +413,7 @@ import { typesQuery } from 'apollo-magic-refetch'
410
413
` ` `
411
414
412
415
The parsed GraphQL introspection query that gets all of the type metadata
413
- needed to determine which queries to refetch. Use this if your server forbids
416
+ needed to determine which queries to refetch. Use this if your server forbids
414
417
client introspection queries; execute this query on the server side and send
415
418
the result to the client code that calls
416
419
[` refetch .setTypeMetadata ` ](#refetchsettypemetadatatypemetadatapromise).
0 commit comments