Skip to content

Commit cfbd6b9

Browse files
committed
2 parents debcaaf + 7358cbf commit cfbd6b9

22 files changed

+9598
-8556
lines changed

.babelrc

-41
This file was deleted.

.babelrc.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = function(api) {
2+
const plugins = [
3+
'@babel/plugin-syntax-dynamic-import',
4+
'@babel/plugin-proposal-class-properties',
5+
'@babel/plugin-proposal-export-default-from',
6+
'@babel/plugin-proposal-export-namespace-from',
7+
'@babel/plugin-proposal-object-rest-spread',
8+
]
9+
const presets = [
10+
[
11+
'@babel/preset-env',
12+
api.env('es5')
13+
? { forceAllTransforms: true }
14+
: { targets: { node: 'current' } },
15+
],
16+
'@babel/preset-flow',
17+
]
18+
19+
if (api.env(['test', 'coverage', 'es5'])) {
20+
plugins.push('@babel/plugin-transform-runtime')
21+
}
22+
if (api.env('coverage')) {
23+
plugins.push('babel-plugin-istanbul')
24+
}
25+
26+
return { plugins, presets }
27+
}

.eslintrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"extends": [
3-
"@jedwards1211/eslint-config", "@jedwards1211/eslint-config-flow"
3+
"@jedwards1211/eslint-config","@jedwards1211/eslint-config-flow", "eslint-config-prettier"
44
],
55
"parser": "babel-eslint",
6+
"parserOptions": {
7+
"ecmaVersion": 6,
8+
"sourceType": "module"
9+
},
610
"env": {
711
"es6": true
812
}

.flowconfig

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PROJECT_ROOT>/es/.*
44
<PROJECT_ROOT>/node_modules/fbjs/.*
55
<PROJECT_ROOT>/node_modules/.*/fbjs/.*
6+
<PROJECT_ROOT>/node_modules/.*/config-chain/.*
67

78
[include]
89
./src

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ scripts
77
node_modules
88
.babelrc
99
.eslintrc
10+
.prettierrc
1011
.travis.yml
1112
.eslintcache
1213
.idea

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "es5"
5+
}

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ cache:
55
notifications:
66
email: false
77
node_js:
8+
- '10'
89
- '8'
9-
- '7'
1010
- '6'
1111
install:
1212
- yarn install --ignore-engines --check-files --frozen-lockfile

README.md

+44-46
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Coverage Status](https://codecov.io/gh/jcoreio/apollo-magic-refetch/branch/master/graph/badge.svg)](https://codecov.io/gh/jcoreio/apollo-magic-refetch)
55
[![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)
66
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
7+
[![npm version](https://badge.fury.io/js/apollo-magic-refetch)](https://badge.fury.io/js/apollo-magic-refetch)
78

89
Handling Apollo cache updates after creating and deleting objects, or
910
associating and dissociating objects, remains a
@@ -19,16 +20,16 @@ Until that happens, this is probably your best bet!
1920

2021
# Table of Contents
2122

22-
* [How it works](#how-it-works)
23-
* [Current limitations](#current-limitations)
24-
* [ES environment requirements](#es-environment-requirements)
25-
* [Type metadata usage](#type-metadata-usage)
26-
* [Handling Deletions](#handling-deletions)
27-
* [Handling Creation](#handling-creation)
28-
* [Handling associations being broken](#handling-associations-being-broken)
29-
* [Handling associations being created](#handling-associations-being-created)
30-
* [API](#api)
31-
+ [`refetch(client, typenameOrTerms, [ids], [idField])`](#refetchclient-typenameorterms-ids-idfield)
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, [ids], [idField])`](#refetchclient-typenameorterms-ids-idfield)
3233

3334
## How it works
3435

@@ -38,23 +39,23 @@ anywhere within their current data!
3839

3940
Similarly, after you create an object, you tell it the `typename` of the created
4041
object and it refetches all active queries that contain an object of that type
41-
in their selections. This is a bit less efficient than handling deletes, but
42+
in their selections. This is a bit less efficient than handling deletes, but
4243
way easier than anything else at the time of writing.
4344

4445
Since only active queries can be refetched, data in the cache for inactive
45-
queries will remain out-of-date. For that reason, I would recommend using the
46+
queries will remain out-of-date. For that reason, I would recommend using the
4647
`cache-and-network` policy on all queries you're not planning to `update` after
4748
all pertinent mutations.
4849

4950
## Current limitations
5051

51-
Interfaces and union types are not supported yet. This means if they are
52+
Interfaces and union types are not supported yet. This means if they are
5253
anywhere in your results, this library may fail to refetch when it should.
5354

5455
Also, lists of lists are not supported, if for whatever reason you are using
5556
lists of lists in your schema (I haven't even checked if this is possible).
5657

57-
Recursive queries are not currently working (https://github.com/jcoreio/apollo-magic-refetch/issues/2); currently it stops at objects of the target type, rather than looking at their descendants.
58+
Recursive queries are not currently working (https://github.com/jcoreio/apollo-magic-refetch/issues/2); currently it stops at objects of the target type, rather than looking at their descendants.
5859

5960
## ES environment requirements
6061

@@ -82,7 +83,7 @@ getSchemaTypes(client)
8283
## Handling Deletions
8384

8485
In this example, the `__typename` of the object being deleted is `Device` and it
85-
uses the standard `id` field. If instead the field were called `tag`, for
86+
uses the standard `id` field. If instead the field were called `tag`, for
8687
instance, you would pass `'tag'` after `deviceId` in the call to `refetch`.
8788

8889
You may pass an array or `Set` of ids in place of a single `deviceId`.
@@ -119,7 +120,7 @@ const DestroyDeviceButton = ({deviceId}) => (
119120

120121
When you omit the id parameter, `refetch` refetches all active queries that
121122
contain the requested `__typename` in their selections, regardless of what ids
122-
are actually in their results. This can be used after creating an object.
123+
are actually in their results. This can be used after creating an object.
123124

124125
In this example, the `__typename` of the object being created is `Device`.
125126

@@ -159,16 +160,15 @@ const CreateDeviceFormContainer = () => (
159160
## Handling associations being broken
160161

161162
In this example, a view shows a list of `Organization`s, each containing a
162-
sublist of `User`s. When one or more users is removed from an organization,
163+
sublist of `User`s. When one or more users is removed from an organization,
163164
it makes the following call:
165+
164166
```js
165-
refetch(client, [
166-
['User', userIds],
167-
['Organization', organizationId],
168-
])
167+
refetch(client, [['User', userIds], ['Organization', organizationId]])
169168
```
169+
170170
Passing an array to `refetch` means to only refetch queries containing all of
171-
the conditions in the array. So the query below would be refetched, but a query
171+
the conditions in the array. So the query below would be refetched, but a query
172172
containing only `Organizations` or a query containing only `User`s would not.
173173

174174
```js
@@ -250,52 +250,50 @@ const OrganizationsViewContainer = () => (
250250
251251
Assuming the same `Organization`s/`User`s schema as above, the example performs
252252
the necessary refetches when a user is created and added to an organization:
253+
253254
```js
254-
refetch(client, [
255-
['User'],
256-
['Organization', organizationId],
257-
])
255+
refetch(client, [['User'], ['Organization', organizationId]])
258256
```
257+
259258
In this case no `ids` are given for `User`, so any query containing the an
260259
`Organization` with the given `organizationId` in its results and selecting any
261-
`User`s would be refetched. (This doesn't perfectly exclude cases that fetch
260+
`User`s would be refetched. (This doesn't perfectly exclude cases that fetch
262261
Users and Organizations separately, instead of one nested inside the other, but
263262
it's better than nothing).
264263
265264
```js
266265
import * as React from 'react'
267266
import gql from 'graphql-tag'
268267
import refetch from 'apollo-magic-refetch'
269-
import {Mutation, ApolloConsumer} from 'react-apollo'
268+
import { Mutation, ApolloConsumer } from 'react-apollo'
270269
import CreateUserForm from './CreateUserForm'
271270

272271
const mutation = gql`
273-
mutation createUser($organizationId: Int!, $values: CreateUser!) {
274-
result: createUser(organizationId: $organizationId, values: $values) {
275-
organizationId
276-
id
277-
username
272+
mutation createUser($organizationId: Int!, $values: CreateUser!) {
273+
result: createUser(organizationId: $organizationId, values: $values) {
274+
organizationId
275+
id
276+
username
277+
}
278278
}
279-
}
280279
`
281280

282-
const CreateUserFormContainer = ({organizationId}) => (
281+
const CreateUserFormContainer = ({ organizationId }) => (
283282
<ApolloConsumer>
284283
{client => (
285284
<Mutation
286285
mutation={mutation}
287286
update={() =>
288-
refetch(client, [
289-
['User'],
290-
['Organization', organizationId],
291-
])
287+
refetch(client, [['User'], ['Organization', organizationId]])
292288
}
293289
>
294290
{createUser => (
295291
<CreateUserForm
296-
onSubmit={values => createUser({
297-
variables: {organizationId, values},
298-
})}
292+
onSubmit={values =>
293+
createUser({
294+
variables: { organizationId, values },
295+
})
296+
}
299297
/>
300298
)}
301299
</Mutation>
@@ -317,16 +315,16 @@ The `ApolloClient` in which to scan active queries.
317315
##### `typenameOrTerms: string | Array<Term>`
318316
319317
The `__typename` of the GraphQL type that was created or deleted, or an array of
320-
`[typename, ids, idField]` tuples (`ids` and `idField` are optional). If an
318+
`[typename, ids, idField]` tuples (`ids` and `idField` are optional). If an
321319
array is given, a query must match all of the conditions in the array to be
322320
refetched.
323321
324-
##### `ids: any` (*optional*)
322+
##### `ids: any` (_optional_)
325323
326-
A single id, an array of ids, or a `Set` of ids that were deleted. If given,
324+
A single id, an array of ids, or a `Set` of ids that were deleted. If given,
327325
only active queries whose current result contains an object with the given
328326
`typename` and `id` will be refetched.
329327
330-
##### `idField: string` (*optional, default*: `'id'`)
328+
##### `idField: string` (_optional, default_: `'id'`)
331329
332330
The name of the id field in the type that was deleted.

0 commit comments

Comments
 (0)