Skip to content

Commit

Permalink
Merge branch 'master' into react-apollo-mockedprovider-fix
Browse files Browse the repository at this point in the history
* master: (112 commits)
  chore(deps): update dependency danger to v3.8.8
  chore(deps): update dependency enzyme to v3.5.0
  chore(deps): update dependency apollo-client to v2.4.1
  chore(deps): update dependency apollo-cache-inmemory to v1.2.9
  chore(deps): update dependency apollo-cache to v1.1.16
  chore(deps): update dependency @types/react to v16.4.12
  chore(deps): update dependency rollup-plugin-commonjs to v9.1.6
  chore(deps): update dependency @types/node to v10.9.2
  chore(deps): update dependency react-scripts to v1.1.5
  chore(deps): update dependency ts-jest to v23.1.4
  Avoid importing lodash directly (apollographql#2045)
  type graphql.options.skip HOC property (apollographql#2208)
  Replace duplicate ObservableQueryFields types defined in apollo-client (apollographql#2281)
  Make mock links mock parameter readonly (apollographql#2284)
  test-utils: allow passing a custom cache object to `MockedProvider` (apollographql#2254)
  Query: Fix data is undefined on error (apollographql#1983)
  Don't mutate options object when calculating variables from props (apollographql#1968)
  Feature: add onSubscriptionData callback to <Subscription> (apollographql#1966)
  Changelog update
  Example of a mutation including tests (apollographql#1998)
  ...
  • Loading branch information
williamboman committed Aug 29, 2018
2 parents d1840e0 + 05e5ed9 commit 7cf750d
Show file tree
Hide file tree
Showing 80 changed files with 3,058 additions and 3,097 deletions.
77 changes: 68 additions & 9 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
# Change log

## vNext

- Added an example app that shows how to test mutations. <br/>
[@excitement-engineer](https://github.com/excitement-engineer) in [#1998](https://github.com/apollographql/react-apollo/pull/1998)
- The `<Subscription />` component now allows the registration of a callback
function, that will be triggered each time the component receives data. The
callback `options` object param consists of the current Apollo Client
instance in `client`, and the received subscription data in
`subscriptionData`. <br/>
[@jedwards1211](https://github.com/jedwards1211) in [#1966](https://github.com/apollographql/react-apollo/pull/1966)
- The `graphql` `options` object is no longer mutated, when calculating
variables from props. This now prevents an issue where components created
with `graphql` were not having their query variables updated properly, when
props changed. <br/>
[@ksmth](https://github.com/ksmth) in [#1968](https://github.com/apollographql/react-apollo/pull/1968)
- When a query failed on the first result, the query result `data` was being
returned as `undefined`. This behavior has been changed so that `data` is
returned as an empty object. This makes checking for data (e.g.
instead of `data && data.user` you can just check `data.user`) and
destructring (e.g. `{ data: { user } }`) easier. **Note:** this could
potentially hurt applications that are relying on a falsey check of `data`
to see if any query errors have occurred. A better (and supported) way to
check for errors is to use the result `errors` property. <br/>
[@TLadd](https://github.com/TLadd) in [#1983](https://github.com/apollographql/react-apollo/pull/1983)
- Allow a custom `cache` object to be passed into the test-utils
`MockedProvider`. <br/>
[@palmfjord](https://github.com/palmfjord) in [#2254](https://github.com/apollographql/react-apollo/pull/2254)
- Make the `MockedProvider` `mocks` prop read only. <br/>
[@amacleay](https://github.com/amacleay) in [#2284](https://github.com/apollographql/react-apollo/pull/2284)
- Remove duplicate `FetchMoreOptions` and `FetchMoreQueryOptions` types, and
instead import them from Apollo Client. <br/>
[@skovy](https://github.com/skovy) in [#2281](https://github.com/apollographql/react-apollo/pull/2281)
- Type changes for the `graphql` HOC `options.skip` property. <br/>
[@jameslaneconkling](https://github.com/jameslaneconkling) in [#2208](https://github.com/apollographql/react-apollo/pull/2208)
- Avoid importing `lodash` directly. <br/>
[@shahyar](https://github.com/shahyar) in [#2045](https://github.com/apollographql/react-apollo/pull/2045)

## 2.1.11 (August 9, 2018)

- Fixed an issue in `getDataFromTree` where queries that threw more than one
error had error messages swallowed, and returned an invalid error object
with circular references. Multiple errors are now preserved. <br/>
[@anand-sundaram-zocdoc](https://github.com/anand-sundaram-zocdoc) in [#2133](https://github.com/apollographql/react-apollo/pull/2133)
- Update both the `<Mutation />` component and `graphql` HOC to accept a new
`awaitRefetchQueries` prop (boolean). When set to `true`, queries specified
in `refetchQueries` will be completed before the mutation itself is
completed. `awaitRefetchQueries` is `false` by default, which means
`refetchQueries` are usually completed after the mutation has resolved.
Relates to Apollo Client. <br/>
[PR #3169](https://github.com/apollographql/apollo-client/pull/3169). <br/>
[@hwillson](https://github.com/hwillson) in [#2214](https://github.com/apollographql/react-apollo/pull/2214)
- Typings adjustment: pass `TData` along into `MutationUpdaterFn` when using
`MutationOpts`, to ensure that the updater function is properly typed. <br/>
[@danilobuerger](https://github.com/danilobuerger) in [#2227](https://github.com/apollographql/react-apollo/pull/2227)
- Check if queryManager is set before accessing it. <br/>
[@danilobuerger](https://github.com/danilobuerger) in [#2165](https://github.com/apollographql/react-apollo/pull/2165)

## 2.1.9 (July 4, 2018)

- Added `onCompleted` and `onError` props to the `Query` component, than can
Expand All @@ -8,6 +65,8 @@
[@jeshep](https://github.com/jeshep) in [#1922](https://github.com/apollographql/react-apollo/pull/1922)
- Add `UNSAFE_componentWillMount` SSR support.
[@leops](https://github.com/leops) in [#2152](https://github.com/apollographql/react-apollo/pull/2152)
- Clear out scheduler on MockedProvider unmount.
[@danilobuerger](https://github.com/danilobuerger) in [#2151](https://github.com/apollographql/react-apollo/pull/2151)

## 2.1.8 (June 28, 2018)

Expand All @@ -16,31 +75,31 @@
## 2.1.7 (June 27, 2018)

- The `ApolloProvider` `children` prop type has been changed from `element`
to `node`, to allow multiple children.
to `node`, to allow multiple children.
[@quentin-](https://github.com/quentin-) in [#1955](https://github.com/apollographql/react-apollo/pull/1955)
- Properly support the new `getDerivedStateFromProps` lifecycle method.
- Properly support the new `getDerivedStateFromProps` lifecycle method.
[@amannn](https://github.com/amannn) in [#2076](https://github.com/apollographql/react-apollo/pull/2076)
- `lodash` is no longer pinned to version 4.17.10.
- `lodash` is no longer pinned to version 4.17.10.
[@cherewaty](https://github.com/cherewaty) in [#1951](https://github.com/apollographql/react-apollo/pull/1951)
- README updates to replace `apollo-client-preset` with `apollo-boost`.
- README updates to replace `apollo-client-preset` with `apollo-boost`.
[@JamesTheHacker](https://github.com/JamesTheHacker) in [#1925](https://github.com/apollographql/react-apollo/pull/1925)
- README updates to fix broken links.
- README updates to fix broken links.
[@DennisKo](https://github.com/DennisKo) in [#1935](https://github.com/apollographql/react-apollo/pull/1935)
- Project README has been updated to show a `<Query />` example.
- Project README has been updated to show a `<Query />` example.
[@petetnt](https://github.com/petetnt) in [#2102](https://github.com/apollographql/react-apollo/pull/2102)

## 2.1.6 (June 19, 2018)

- Adjust `getDataFromTree` to properly traverse React 16.3's context API
provider/consumer approach.
provider/consumer approach.
[@marnusw](https://github.com/marnusw) in [#1978](https://github.com/apollographql/react-apollo/pull/1978)
- An `ApolloClient` instance can now be passed into a `Mutation`
component via a prop named `client`. This prop will override
an `ApolloClient` instance set via `context`, by the `ApolloProvider`
component.
component.
[@amneacsu](https://github.com/amneacsu) in [#1890](https://github.com/apollographql/react-apollo/pull/1890)
- The `ApolloClient` instance used by a Mutation is now available in that
Mutation's result.
Mutation's result.
[@cooperka](https://github.com/cooperka) in [#1945](https://github.com/apollographql/react-apollo/pull/1945)

## 2.1.5
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import { ApolloClient } from 'apollo-boost';
const client = new ApolloClient();
```

> Migrating from 1.x? See the [2.0 migration guide](https://www.apollographql.com/docs/react/2.0-migration.html).
> Migrating from 1.x? See the [2.0 migration guide](https://www.apollographql.com/docs/react/recipes/2.0-migration.html).
Next you will want to add a [`<ApolloProvider/>`][] component to the root of your React component tree. This component [provides](https://reactjs.org/docs/context.html) the React Apollo functionality to all the other components in the application without passing it explicitly. To use an [`<ApolloProvider/>`][] with your newly constructed client see the following:

Expand Down
4 changes: 2 additions & 2 deletions dangerfile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Removed import
import { includes } from 'lodash';
import * as fs from 'fs';
import includes from 'lodash/includes';
import fs from 'fs';

// Setup
const pr = danger.github.pr;
Expand Down
2 changes: 1 addition & 1 deletion examples/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"react": "^16.3.0",
"react-apollo": "../../lib",
"react-dom": "^16.3.0",
"react-scripts": "1.1.4"
"react-scripts": "1.1.5"
},
"scripts": {
"start": "react-scripts start",
Expand Down
6 changes: 3 additions & 3 deletions examples/base/src/__tests__/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import * as renderer from 'react-test-renderer';
import React from 'react';
import renderer from 'react-test-renderer';
import { MockedProvider } from 'react-apollo/test-utils';

import { HERO_QUERY, withCharacter, CharacterWithoutData, App } from '../App';
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('withCharacter', () => {
const mocks = [{ request: { query, variables }, result: { data: { hero: empty } } }];
renderer.create(
<ErrorBoundary>
<MockedProvider mocks={mocks} removeTypename>
<MockedProvider mocks={mocks}>
<ContainerWithData {...variables} />
</MockedProvider>
</ErrorBoundary>,
Expand Down
5 changes: 4 additions & 1 deletion examples/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
"react": "^16.2.0",
"react-apollo": "../../lib",
"react-dom": "^16.2.0",
"react-scripts": "1.1.4"
"react-scripts": "1.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"react-testing-library": "5.0.0"
}
}
48 changes: 12 additions & 36 deletions examples/components/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Query } from 'react-apollo';
import gql from 'graphql-tag';
import Character from './character';

export const HERO_QUERY = gql`
query GetCharacter($episode: Episode!) {
Expand All @@ -16,46 +17,21 @@ export const HERO_QUERY = gql`
}
`;

export const HeroQuery = ({ episode, children }) => (
const App = ({ episode }) => (
<Query query={HERO_QUERY} variables={{ episode }}>
{result => {
const { loading, error, data } = result;
return children({
loading,
error,
hero: data && data.hero,
});

if (loading) {
return <div>Loading</div>;
}
if (error) {
return <h1>ERROR</h1>;
}

return <Character hero={data.hero} />;
}}
</Query>
);

export const Character = ({ loading, error, hero }) => {
if (loading) {
return <div>Loading</div>;
}
if (error) {
return <h1>ERROR</h1>;
}
return (
<div>
{hero && (
<div>
<h3>{hero.name}</h3>
{hero.friends &&
hero.friends.map(
friend =>
friend && (
<h6 key={friend.id}>
{friend.name}: {friend.appearsIn.map(x => x && x.toLowerCase()).join(', ')}
</h6>
),
)}
</div>
)}
</div>
);
};

export const App = () => (
<HeroQuery episode="EMPIRE">{result => <Character {...result} />}</HeroQuery>
);
export default App;
61 changes: 17 additions & 44 deletions examples/components/src/__tests__/__snapshots__/app.js.snap
Original file line number Diff line number Diff line change
@@ -1,61 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`App renders 1`] = `
<div>
Loading
</div>
`;

exports[`Character handles a loading state 1`] = `
<div>
Loading
</div>
`;

exports[`Character handles an error state 1`] = `
<h1>
ERROR
</h1>
`;

exports[`Character returns markup for a friend without an appearsIn 1`] = `
exports[`App renders data 1`] = `
<div>
<div>
<h3>
r2d2
</h3>
<h6>
luke
:
newhope
</h6>
<h6>
james
:
</h6>
<div>
<h3>
r2d2
</h3>
<h6>
luke
:
newhope
</h6>
</div>
</div>
</div>
`;

exports[`Character returns markup for a hero with no friends 1`] = `
exports[`App renders error 1`] = `
<div>
<div>
<h3>
r2d2
</h3>
</div>
<h1>
ERROR
</h1>
</div>
`;

exports[`Character returns markup for empty array of friends 1`] = `
exports[`App renders loading 1`] = `
<div>
<div>
<h3>
r2d2
</h3>
Loading
</div>
</div>
`;

exports[`Character returns markup for null response 1`] = `<div />`;
52 changes: 52 additions & 0 deletions examples/components/src/__tests__/__snapshots__/character.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Character returns markup for a friend without an appearsIn 1`] = `
<div>
<div>
<div>
<h3>
r2d2
</h3>
<h6>
luke
:
newhope
</h6>
<h6>
james
:
</h6>
</div>
</div>
</div>
`;

exports[`Character returns markup for a hero with no friends 1`] = `
<div>
<div>
<div>
<h3>
r2d2
</h3>
</div>
</div>
</div>
`;

exports[`Character returns markup for empty array of friends 1`] = `
<div>
<div>
<div>
<h3>
r2d2
</h3>
</div>
</div>
</div>
`;

exports[`Character returns markup for null response 1`] = `
<div>
<div />
</div>
`;
Loading

0 comments on commit 7cf750d

Please sign in to comment.