Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #438 from apollostack/update-apollo-client
Browse files Browse the repository at this point in the history
Update apollo client
  • Loading branch information
helfer authored Jan 27, 2017
2 parents 9498b57 + 31955ea commit 1b1587c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 182 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Expect active development and potentially significant breaking changes in the `0

### vNext

### 0.9.0
- Update apollo-client peerDependency to 0.8.0 [PR #438](https://github.com/apollostack/react-apollo/pull/438)

### 0.8.3
- Bug: [Issue #404](https://github.com/apollostack/react-apollo/issues/404) fix issue with network errors thrown when changing variables.

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"README.md"
],
"peerDependencies": {
"apollo-client": "^0.6.0",
"apollo-client": "^0.8.0",
"react": "0.14.x || 15.* || ^15.0.0",
"redux": "^2.0.0 || ^3.0.0"
},
Expand All @@ -89,7 +89,7 @@
"@types/redux-form": "^4.0.29",
"@types/redux-immutable": "^3.0.30",
"@types/sinon": "^1.16.29",
"apollo-client": "^0.6.0",
"apollo-client": "^0.8.0",
"babel-jest": "^14.1.0",
"babel-preset-react-native": "^1.9.0",
"browserify": "^13.0.0",
Expand Down
14 changes: 2 additions & 12 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {

// modules don't export ES6 modules
import pick = require('lodash.pick');
import flatten = require('lodash.flatten');
import shallowEqual from './shallowEqual';

import invariant = require('invariant');
Expand All @@ -16,7 +15,6 @@ import hoistNonReactStatics = require('hoist-non-react-statics');

import ApolloClient, {
ObservableQuery,
MutationBehavior,
MutationQueryReducersMap,
Subscription,
ApolloStore,
Expand All @@ -25,15 +23,12 @@ import ApolloClient, {

import {
DocumentNode,
FragmentDefinitionNode,
} from 'graphql';

import { parser, DocumentType } from './parser';

export declare interface MutationOptions {
variables?: Object;
resultBehaviors?: MutationBehavior[];
fragments?: FragmentDefinitionNode[] | FragmentDefinitionNode[][];
optimisticResponse?: Object;
updateQueries?: MutationQueryReducersMap;
forceFetch?: boolean;
Expand All @@ -46,7 +41,6 @@ export declare interface QueryOptions {
returnPartialData?: boolean;
noFetch?: boolean;
pollInterval?: number;
fragments?: FragmentDefinitionNode[] | FragmentDefinitionNode[][];
// deprecated
skip?: boolean;
}
Expand Down Expand Up @@ -179,7 +173,7 @@ export default function graphql(

// request / action storage. Note that we delete querySubscription if we
// unsubscribe but never delete queryObservable once it is created.
private queryObservable: ObservableQuery | any;
private queryObservable: ObservableQuery<any> | any;
private querySubscription: Subscription;
private previousData: any = {};
private lastSubscriptionData: any;
Expand Down Expand Up @@ -266,10 +260,6 @@ export default function graphql(
}
if (newOpts) opts = assign({}, opts, newOpts);

if (opts.fragments) {
opts.fragments = flatten(opts.fragments);
}

if (opts.variables || !operation.variables.length) return opts;

let variables = {};
Expand Down Expand Up @@ -362,7 +352,7 @@ export default function graphql(
}

// For server-side rendering (see server.ts)
fetchData(): Promise<ApolloQueryResult> | boolean {
fetchData(): Promise<ApolloQueryResult<any>> | boolean {
if (this.shouldSkip()) return false;
if (
operation.type === DocumentType.Mutation || operation.type === DocumentType.Subscription
Expand Down
138 changes: 0 additions & 138 deletions test/react-web/client/graphql/fragments.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,142 +66,4 @@ describe('fragments', () => {

renderer.create(<ApolloProvider client={client}><Container /></ApolloProvider>);
});

it('correctly merges a query with inline fragments and passed fragments', (done) => {
const query = gql`
query peopleAndShips {
allPeople(first: 1) {
__typename
...Person
}
allShips(first: 1) {
__typename
...ships
}
}
fragment Person on PeopleConnection { people { name } }
`;
const shipFragment = createFragment(gql`
fragment ships on ShipsConnection { starships { name } }
`);

const mockedQuery = gql`
query peopleAndShips {
allPeople(first: 1) {
__typename
...Person
}
allShips(first: 1) {
__typename
...ships
}
}
fragment Person on PeopleConnection { people { name } }
fragment ships on ShipsConnection { starships { name } }
`;

const data = {
allPeople: { __typename: 'PeopleConnection', people: [ { name: 'Luke Skywalker' } ] },
allShips: { __typename: 'ShipsConnection', starships: [ { name: 'CR90 corvette' } ] },
};
const networkInterface = mockNetworkInterface(
{ request: { query: mockedQuery }, result: { data } }
);
const client = new ApolloClient({ networkInterface, addTypename: false });

@graphql(query, {
options: () => ({ fragments: shipFragment }),
})
class Container extends React.Component<any, any> {
componentWillReceiveProps(props) {
expect(props.data.loading).toBe(false);
expect(props.data.allPeople).toEqual(data.allPeople);
expect(props.data.allShips).toEqual(data.allShips);
done();
}
render() {
return null;
}
};

renderer.create(<ApolloProvider client={client}><Container /></ApolloProvider>);
});

it('correctly allows for passed fragments', (done) => {
const query = gql`
query ships { allShips(first: 1) { __typename ...Ships } }
`;
const shipFragment = createFragment(gql`
fragment Ships on ShipsConnection { starships { name } }
`);

const mockedQuery = gql`
query ships { allShips(first: 1) { __typename ...Ships } }
fragment Ships on ShipsConnection { starships { name } }
`;

const data = {
allShips: { __typename: 'ShipsConnection', starships: [ { name: 'CR90 corvette' } ] },
};
const networkInterface = mockNetworkInterface(
{ request: { query: mockedQuery }, result: { data } }
);
const client = new ApolloClient({ networkInterface, addTypename: false });

@graphql(query, {
options: () => ({ fragments: shipFragment}),
})
class Container extends React.Component<any, any> {
componentWillReceiveProps(props) {
expect(props.data.loading).toBe(false);
expect(props.data.allShips).toEqual(data.allShips);
done();
}
render() {
return null;
}
};

renderer.create(<ApolloProvider client={client}><Container /></ApolloProvider>);
});

it('correctly allows for passed fragments in an array', (done) => {
const query = gql`
query ships { allShips(first: 1) { __typename ...Ships } }
`;
const shipFragment = createFragment(gql`
fragment Ships on ShipsConnection { starships { name } }
`);

const mockedQuery = gql`
query ships { allShips(first: 1) { __typename ...Ships } }
fragment Ships on ShipsConnection { starships { name } }
`;

const data = {
allShips: { __typename: 'ShipsConnection', starships: [ { name: 'CR90 corvette' } ] },
};
const networkInterface = mockNetworkInterface(
{ request: { query: mockedQuery }, result: { data } }
);
const client = new ApolloClient({ networkInterface, addTypename: false });

@graphql(query, {
options: () => ({ fragments: [shipFragment]}),
})
class Container extends React.Component<any, any> {
componentWillReceiveProps(props) {
expect(props.data.loading).toBe(false);
expect(props.data.allShips).toEqual(data.allShips);
done();
}
render() {
return null;
}
};

renderer.create(<ApolloProvider client={client}><Container /></ApolloProvider>);
});


});
31 changes: 1 addition & 30 deletions test/react-web/server/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom/server';
import ApolloClient, { createNetworkInterface, createFragment } from 'apollo-client';
import ApolloClient, { createNetworkInterface } from 'apollo-client';
import { graphql, ApolloProvider } from '../../../src';
import { walkTree, getDataFromTree, renderToStringWithData } from '../../../src/server';
import 'isomorphic-fetch';
Expand Down Expand Up @@ -668,34 +668,5 @@ describe('SSR', () => {
expect(markup).toMatch(/Tatooine/);
});
});

it('should work with queries that use fragments', function() {
const query = gql`{ currentUser { __typename, ...userInfo } }`;
const userInfoFragment = createFragment(gql`fragment userInfo on User { firstName, lastName }`);
const data = { currentUser: { __typename: 'User', firstName: 'John', lastName: 'Smith' } };
const networkInterface = {
query: () => Promise.resolve({ data }),
};
const apolloClient = new ApolloClient({ networkInterface, addTypename: false });

const UserPage = graphql(query, {
options: {
fragments: userInfoFragment
}
})(({ data }) => (
<div>{data.loading ? 'Loading...' : `${data.currentUser.firstName} ${data.currentUser.lastName}`}</div>
));

const app = (
<ApolloProvider client={apolloClient}>
<UserPage />
</ApolloProvider>
);

return renderToStringWithData(app)
.then((markup) => {
expect(markup).toMatch(/John Smith/);
});
});
});
});

0 comments on commit 1b1587c

Please sign in to comment.