diff --git a/Changelog.md b/Changelog.md index 05e5a56325..60cf6823ab 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,8 @@ Expect active development and potentially significant breaking changes in the `0 ### vNext +- Full support for both Apollo Client 0.4.21 and 0.5.0. [PR #277](https://github.com/apollostack/react-apollo/pull/277) + ### v0.5.11 - Bug: Fix issue with SSR queries running twice when a mutation wraps a query [#274](https://github.com/apollostack/react-apollo/issue/274) diff --git a/src/graphql.tsx b/src/graphql.tsx index 92a042da10..00bfc41b74 100644 --- a/src/graphql.tsx +++ b/src/graphql.tsx @@ -5,7 +5,6 @@ import { } from 'react'; // modules don't export ES6 modules -import flatten = require('lodash.flatten'); import pick = require('lodash.pick'); import shallowEqual from './shallowEqual'; @@ -66,8 +65,18 @@ const defaultMapResultToProps = props => props; const defaultMapPropsToSkip = props => false; // the fields we want to copy over to our data prop -const observableQueryFields = observable => pick(observable, 'variables', - 'refetch', 'fetchMore', 'updateQuery', 'startPolling', 'stopPolling'); +function observableQueryFields(observable) { + const fields = pick(observable, 'variables', + 'refetch', 'fetchMore', 'updateQuery', 'startPolling', 'stopPolling'); + + Object.keys(fields).forEach((key) => { + if (typeof fields[key] === 'function') { + fields[key] = fields[key].bind(observable); + } + }); + + return fields; +} function getDisplayName(WrappedComponent) { return WrappedComponent.displayName || WrappedComponent.name || 'Component'; @@ -145,13 +154,6 @@ export default function graphql( const graphQLDisplayName = `Apollo(${getDisplayName(WrappedComponent)})`; - // XXX: what is up with this? We shouldn't have to do this. - function calculateFragments(fragments): FragmentDefinition[] { - if (!fragments && !operation.fragments.length) return fragments; - if (!fragments) return fragments = flatten([...operation.fragments]); - return flatten([...fragments, ...operation.fragments]); - } - function calculateOptions(props, newOpts?) { let opts = mapPropsToOptions(props); @@ -160,10 +162,6 @@ export default function graphql( } if (newOpts) opts = assign({}, opts, newOpts); - if (opts.fragments) { - opts.fragments = calculateFragments(opts.fragments); - } - if (opts.variables || !operation.variables.length) return opts; let variables = {}; @@ -375,9 +373,14 @@ export default function graphql( // We've subscribed already, just update with our new options and // take the latest result if (this.querySubscription) { - // Since we don't care about the result, use a hacky version to - // work around https://github.com/apollostack/apollo-client/pull/694 - this.queryObservable._setOptionsNoResult(opts); + if (this.queryObservable._setOptionsNoResult) { + // Since we don't care about the result, use a hacky version to + // work around https://github.com/apollostack/apollo-client/pull/694 + // This workaround is only present in Apollo Client 0.4.21 + this.queryObservable._setOptionsNoResult(opts); + } else { + this.queryObservable.setOptions(opts); + } // Ensure we are up-to-date with the latest state of the world assign(this.data, diff --git a/test/react-native/component.test.js b/test/react-native/component.test.js index 7e50b26dcf..c23f783520 100644 --- a/test/react-native/component.test.js +++ b/test/react-native/component.test.js @@ -21,7 +21,7 @@ describe('App', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: { name: 'Luke Skywalker' } } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const ContainerWithData = graphql(query)(({ data }) => { if (data.loading) return Loading...; @@ -38,7 +38,7 @@ describe('App', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: { name: 'Luke Skywalker' } } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); class Container extends Component { componentWillReceiveProps(props) { diff --git a/test/react-web/client/graphql/fragments.test.tsx b/test/react-web/client/graphql/fragments.test.tsx index 515a2a75f8..9cb28a6a4a 100644 --- a/test/react-web/client/graphql/fragments.test.tsx +++ b/test/react-web/client/graphql/fragments.test.tsx @@ -24,7 +24,7 @@ describe('fragments', () => { `; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); try { @graphql(query) @@ -48,12 +48,13 @@ describe('fragments', () => { it('correctly fetches a query with inline fragments', (done) => { const query = gql` - query people { allPeople(first: 1) { ...person } } + query people { allPeople(first: 1) { __typename ...person } } fragment person on PeopleConnection { people { name } } `; - const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; + const data = { allPeople: { + __typename: 'PeopleConnection', people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -75,8 +76,14 @@ describe('fragments', () => { it('correctly merges a query with inline fragments and passed fragments', (done) => { const query = gql` query peopleAndShips { - allPeople(first: 1) { ...Person } - allShips(first: 1) { ...ships } + allPeople(first: 1) { + __typename + ...Person + } + allShips(first: 1) { + __typename + ...ships + } } fragment Person on PeopleConnection { people { name } } `; @@ -86,24 +93,30 @@ describe('fragments', () => { const mockedQuery = gql` query peopleAndShips { - allPeople(first: 1) { ...Person } - allShips(first: 1) { ...ships } + 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: { people: [ { name: 'Luke Skywalker' } ] }, - allShips: { starships: [ { name: 'CR90 corvette' } ] }, + 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 }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query, { - options: () => ({ fragments: [shipFragment]}) + options: () => ({ fragments: shipFragment }), }) class Container extends React.Component { componentWillReceiveProps(props) { @@ -124,27 +137,27 @@ describe('fragments', () => { it('correctly allows for passed fragments', (done) => { const query = gql` - query ships { allShips(first: 1) { ...Ships } } + 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) { ...Ships } } + query ships { allShips(first: 1) { __typename ...Ships } } fragment Ships on ShipsConnection { starships { name } } `; const data = { - allShips: { starships: [ { name: 'CR90 corvette' } ] }, + allShips: { __typename: 'ShipsConnection', starships: [ { name: 'CR90 corvette' } ] }, }; const networkInterface = mockNetworkInterface( { request: { query: mockedQuery }, result: { data } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query, { - options: () => ({ fragments: [shipFragment]}), + options: () => ({ fragments: shipFragment}), }) class Container extends React.Component { componentWillReceiveProps(props) { diff --git a/test/react-web/client/graphql/mutations.test.tsx b/test/react-web/client/graphql/mutations.test.tsx index 6d2ca46a38..5dcb8e22d1 100644 --- a/test/react-web/client/graphql/mutations.test.tsx +++ b/test/react-web/client/graphql/mutations.test.tsx @@ -22,7 +22,7 @@ describe('mutations', () => { const query = gql`mutation addPerson { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const ContainerWithData = graphql(query)(({ mutate }) => { expect(mutate).toBeTruthy(); @@ -37,7 +37,7 @@ describe('mutations', () => { const query = gql`mutation addPerson { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const props = ({ ownProps, addPerson }) => ({ [ownProps.methodName]: (name: string) => addPerson({ variables: { name }}), @@ -56,7 +56,7 @@ describe('mutations', () => { const query = gql`mutation addPerson { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let bar; const ContainerWithData = graphql(query)(() => { bar(); // this will throw @@ -76,7 +76,7 @@ describe('mutations', () => { const query = gql`mutation addPerson { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -108,7 +108,7 @@ describe('mutations', () => { request: { query, variables }, result: { data }, }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -140,7 +140,7 @@ describe('mutations', () => { request: { query, variables }, result: { data }, }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -172,7 +172,7 @@ describe('mutations', () => { request: { query, variables }, result: { data }, }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const Container = graphql(query)(() => null); try { @@ -187,7 +187,7 @@ describe('mutations', () => { const query = gql`mutation addPerson { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); function options(props) { expect(props.listId).toBe(2); @@ -231,7 +231,7 @@ describe('mutations', () => { request: { query, variables }, result: { data }, }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -270,7 +270,7 @@ describe('mutations', () => { }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -360,7 +360,7 @@ describe('mutations', () => { { request: { query, variables: { id: '123' } }, result: { data } }, { request: { query: mutation }, result: { data: mutationData } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let count = 0; @graphql(query) diff --git a/test/react-web/client/graphql/queries-1.test.tsx b/test/react-web/client/graphql/queries-1.test.tsx index ff79c2d7dc..8ad9bd8ea5 100644 --- a/test/react-web/client/graphql/queries-1.test.tsx +++ b/test/react-web/client/graphql/queries-1.test.tsx @@ -4,7 +4,7 @@ import * as renderer from 'react-test-renderer'; import gql from 'graphql-tag'; import ApolloClient from 'apollo-client'; -import { ApolloError } from 'apollo-client/errors'; +import { ApolloError } from 'apollo-client'; import { connect } from 'react-redux'; declare function require(name: string); @@ -35,7 +35,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const ContainerWithData = graphql(query)(({ data }) => { // tslint:disable-line expect(data).toBeTruthy(); @@ -55,7 +55,7 @@ describe('queries', () => { const networkInterface = mockNetworkInterface( { request: { query, variables }, result: { data } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const ContainerWithData = graphql(query)(({ data }) => { // tslint:disable-line expect(data).toBeTruthy();; @@ -70,7 +70,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let bar; const ContainerWithData = graphql(query)(() => { bar(); // this will throw @@ -90,7 +90,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -117,7 +117,7 @@ describe('queries', () => { otherPeople: { people: [ { name: 'Luke Skywalker' } ] }, }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -139,7 +139,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const ContainerWithData = graphql(query)(() => null); @@ -156,7 +156,7 @@ describe('queries', () => { it('passes any GraphQL errors in props', (done) => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const networkInterface = mockNetworkInterface({ request: { query }, error: new Error('boo') }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class ErrorContainer extends React.Component { @@ -185,7 +185,7 @@ describe('queries', () => { request: { query, variables }, result: { data }, }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -215,7 +215,7 @@ describe('queries', () => { request: { query, variables }, result: { data }, }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -244,7 +244,7 @@ describe('queries', () => { request: { query, variables }, result: { data }, }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const Container = graphql(query)(() => null); let error = null; @@ -268,7 +268,7 @@ describe('queries', () => { request: { query, variables }, result: { data }, }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const Container = graphql(query)(() => null); try { @@ -284,7 +284,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let firstRun = true; @@ -322,7 +322,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let queryExecuted; @graphql(query, { options: () => ({ skip: true }) }) @@ -348,7 +348,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let queryExecuted; @graphql(query, { skip: ({ skip }) => skip }) @@ -379,7 +379,7 @@ describe('queries', () => { fail(new Error('query ran even though skip present')); return oldQuery.call(this, request); }; - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query, { skip: true }) class Container extends React.Component {8 @@ -411,7 +411,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let queryExecuted; @graphql(query, { @@ -441,7 +441,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let queryExecuted; @graphql(query, { skip: true }) @@ -469,7 +469,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let hasSkipped = false; @graphql(query, { skip: ({ skip }) => skip }) @@ -517,7 +517,7 @@ describe('queries', () => { ranQuery++; return oldQuery.call(this, request); }; - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let hasSkipped = false; let hasRequeried = false; @@ -587,7 +587,7 @@ describe('queries', () => { { request: { query, variables: variables3 }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query, { skip: () => count === 1, @@ -636,7 +636,7 @@ describe('queries', () => { it('allows you to unmount a skipped query', (done) => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const networkInterface = mockNetworkInterface(); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query, { skip: true, @@ -689,7 +689,7 @@ describe('queries', () => { { request: { query, variables: variables2 }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query, { options: (props) => ({ variables: props, returnPartialData: count === 0 }), @@ -748,7 +748,7 @@ describe('queries', () => { // { request: { query, variables: variables2 }, result: { data: data2 } } // ); - // const client = new ApolloClient({ networkInterface }); + // const client = new ApolloClient({ networkInterface, addTypename: false }); // const Container = graphql(query)(() => null); // @connect(state => ({ apollo: state.apollo })) @@ -805,7 +805,7 @@ describe('queries', () => { { request: { query, variables: variables2 }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query, { options: (props) => ({ variables: props }) }) class Container extends React.Component { @@ -861,7 +861,7 @@ describe('queries', () => { { request: { query, variables: variables2 }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -907,7 +907,7 @@ describe('queries', () => { { request: { query, variables }, result: { data: data1 } }, { request: { query, variables }, result: { data: data2 } }, ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let count = 0; @graphql(query, { options() { return { variables }; } }) @@ -959,7 +959,7 @@ describe('queries', () => { { request: { query, variables }, result: { data: data1 } }, { request: { query, variables: { first: 2 } }, result: { data: data1 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let hasRefetched, count = 0; @graphql(query) @@ -1014,7 +1014,7 @@ describe('queries', () => { { request: { query, variables }, result: { data } }, { request: { query, variables: variables2 }, result: { data: data1 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let count = 0; @graphql(query, { options: () => ({ variables }) }) @@ -1061,7 +1061,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -1083,7 +1083,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); // @graphql(query) @graphql(query, { options: { pollInterval: 10 }}) @@ -1112,7 +1112,7 @@ describe('queries', () => { { request: { query }, result: { data } }, { request: { query }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let isRefetching; @graphql(query) @@ -1148,7 +1148,7 @@ describe('queries', () => { // { request: { query }, result: { data } }, // { request: { query }, result: { data } } // ); - // const client = new ApolloClient({ networkInterface }); + // const client = new ApolloClient({ networkInterface, addTypename: false }); // // let isRefectching; // let refetched; @@ -1194,7 +1194,7 @@ describe('queries', () => { { request: { query }, result: { data: data2 } }, { request: { query }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let count = 0; const Container = graphql(query, { options: () => ({ pollInterval: 75 }) })(() => { @@ -1215,7 +1215,7 @@ describe('queries', () => { const query = gql`query thing { getThing { thing } }`; const data = { getThing: { thing: true } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const props = ({ data }) => ({ showSpinner: data.loading }); const ContainerWithData = graphql(query, { props })(({ showSpinner }) => { @@ -1231,7 +1231,7 @@ describe('queries', () => { const query = gql`query thing { getThing { thing } }`; const data = { getThing: { thing: true } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const props = ({ data, ownProps }) => { expect(ownProps.sample).toBe(1); @@ -1252,7 +1252,7 @@ describe('queries', () => { const query = gql`query thing { getThing { thing } }`; const data = { getThing: { thing: true } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query, { props: ({ data }) => ({ thingy: data.getThing }) }) // tslint:disable-line class Container extends React.Component { @@ -1272,7 +1272,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -1344,7 +1344,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -1369,7 +1369,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -1390,7 +1390,7 @@ describe('queries', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query) class Container extends React.Component { @@ -1421,7 +1421,7 @@ describe('queries', () => { { request: { query }, result: { data } }, { request: { query }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let isUpdated; @graphql(query) @@ -1458,7 +1458,7 @@ describe('queries', () => { { request: { query }, result: { data } }, { request: { query }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let isUpdated; @graphql(query) @@ -1495,7 +1495,7 @@ describe('queries', () => { { request: { query, variables: vars1 }, result: { data: data1 } }, { request: { query, variables: vars2 }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let isUpdated = false; @graphql(query, { diff --git a/test/react-web/client/graphql/queries-2.test.tsx b/test/react-web/client/graphql/queries-2.test.tsx index 25f7cc2900..b62957122e 100644 --- a/test/react-web/client/graphql/queries-2.test.tsx +++ b/test/react-web/client/graphql/queries-2.test.tsx @@ -35,7 +35,7 @@ describe('queries', () => { }, }) } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let wrapper, app, count = 0; @graphql(query, { options: { pollInterval: 10 }}) @@ -72,7 +72,7 @@ describe('queries', () => { }, }) } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let wrapper, app, count = 0; @graphql(query, { options: { forceFetch: true }}) @@ -120,7 +120,7 @@ describe('queries', () => { { request: { query, variables }, result: { data }, delay: 10 }, { request: { query, variables: variables2 }, result: { data }, delay: 10 } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let wrapper, render, count = 0; @graphql(query, { options: ({ first }) => ({ variables: { first }})}) @@ -169,7 +169,7 @@ describe('queries', () => { { request: { query, variables }, result: { data }, delay: 10 }, { request: { query, variables: variables2 }, result: { data }, delay: 10 } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let count = 0; @graphql(query) @@ -217,7 +217,7 @@ describe('queries', () => { { request: { query, variables }, result: { data }, delay: 10 }, { request: { query, variables: variables2 }, result: { data }, delay: 10 } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let count = 0; const connect = (component) : any => { diff --git a/test/react-web/client/graphql/shared-operations-1.test.tsx b/test/react-web/client/graphql/shared-operations-1.test.tsx index 4f5578b0f7..4d85a60ab1 100644 --- a/test/react-web/client/graphql/shared-operations-1.test.tsx +++ b/test/react-web/client/graphql/shared-operations-1.test.tsx @@ -47,7 +47,7 @@ describe('shared operations', () => { { request: { query: peopleQuery }, result: { data: peopleData } }, { request: { query: shipsQuery }, result: { data: shipsData } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const withPeople = graphql(peopleQuery, { name: 'people' }); const withShips = graphql(shipsQuery, { name: 'ships' }); @@ -82,7 +82,7 @@ describe('shared operations', () => { { request: { query: peopleQuery }, result: { data: peopleData } }, { request: { query: shipsQuery }, result: { data: shipsData } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const withPeople = graphql(peopleQuery, { name: 'people' }); const withShips = graphql(shipsQuery, { name: 'ships' }); @@ -112,7 +112,7 @@ describe('shared operations', () => { { request: { query: peopleQuery }, result: { data: peopleData } }, { request: { query: peopleMutation }, result: { data: peopleMutationData } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const withPeople = graphql(peopleQuery, { name: 'people' }); const withPeopleMutation = graphql(peopleMutation, { name: 'addPerson' }); @@ -140,7 +140,7 @@ describe('shared operations', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let queryExecuted; @graphql(query, { options: { skip: true } }) @@ -175,7 +175,7 @@ describe('shared operations', () => { { request: { query: peopleQuery }, result: { data: peopleData } }, { request: { query: shipsQuery }, result: { data: shipsData } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const enhanced = compose( graphql(peopleQuery, { name: 'people' }), diff --git a/test/react-web/client/graphql/shared-operations-2.test.tsx b/test/react-web/client/graphql/shared-operations-2.test.tsx index 749445f47f..2476a6c74b 100644 --- a/test/react-web/client/graphql/shared-operations-2.test.tsx +++ b/test/react-web/client/graphql/shared-operations-2.test.tsx @@ -29,7 +29,7 @@ describe('shared operations', () => { const query = gql`query people { allPeople(first: 1) { people { name } } }`; const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } }; const networkInterface = mockNetworkInterface({ request: { query }, result: { data } }); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); const testData = { foo: 'bar' }; diff --git a/test/react-web/client/graphql/subscriptions.test.tsx b/test/react-web/client/graphql/subscriptions.test.tsx index 48ec9d4773..30df3e3fcc 100644 --- a/test/react-web/client/graphql/subscriptions.test.tsx +++ b/test/react-web/client/graphql/subscriptions.test.tsx @@ -28,7 +28,7 @@ describe('subscriptions', () => { const networkInterface = mockSubscriptionNetworkInterface( [{ request: { query }, results: [...results] }] ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); // XXX fix in apollo-client client.subscribe = client.subscribe.bind(client); @@ -49,7 +49,7 @@ describe('subscriptions', () => { const networkInterface = mockSubscriptionNetworkInterface( [{ request: { query, variables }, results: [...results] }] ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); // XXX fix in apollo-client client.subscribe = client.subscribe.bind(client); @@ -70,7 +70,7 @@ describe('subscriptions', () => { const networkInterface = mockSubscriptionNetworkInterface( [{ request: { query }, results: [...results] }] ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); // XXX fix in apollo-client client.subscribe = client.subscribe.bind(client); @@ -94,7 +94,7 @@ describe('subscriptions', () => { const networkInterface = mockSubscriptionNetworkInterface( [{ request: { query }, results: [...results] }] ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); // XXX fix in apollo-client client.subscribe = client.subscribe.bind(client); diff --git a/test/react-web/client/libraries/mobx.test.tsx b/test/react-web/client/libraries/mobx.test.tsx index 370b28d640..96fba59b87 100644 --- a/test/react-web/client/libraries/mobx.test.tsx +++ b/test/react-web/client/libraries/mobx.test.tsx @@ -46,7 +46,7 @@ describe('mobx integration', () => { { request: { query, variables: variables2 }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query, { options: (props) => ({ variables: { first: props.appState.first } }), @@ -55,7 +55,9 @@ describe('mobx integration', () => { class Container extends React.Component { componentWillReact() { if (this.props.appState.first === 1) { - this.props.data.refetch({ first: this.props.appState.first }); + this.props.data.refetch({ first: this.props.appState.first }).catch((e) => { + console.error(e); + }); } } componentWillReceiveProps(nextProps) { diff --git a/test/react-web/client/libraries/redux-1.test.tsx b/test/react-web/client/libraries/redux-1.test.tsx index be75558e34..e9c89bc671 100644 --- a/test/react-web/client/libraries/redux-1.test.tsx +++ b/test/react-web/client/libraries/redux-1.test.tsx @@ -34,7 +34,7 @@ describe('redux integration', () => { { request: { query, variables: variables2 }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let wrapper; function counter(state = 1, action) { @@ -93,7 +93,7 @@ describe('redux integration', () => { { request: { query, variables }, result: { data } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); // Typscript workaround const apolloReducer = client.reducer() as () => any; @@ -167,7 +167,7 @@ describe('redux integration', () => { { request: { query, variables: variables2 }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let wrapper; function counter(state = 1, action) { diff --git a/test/react-web/client/libraries/redux-2.test.tsx b/test/react-web/client/libraries/redux-2.test.tsx index 5a776e1738..2a2a976d15 100644 --- a/test/react-web/client/libraries/redux-2.test.tsx +++ b/test/react-web/client/libraries/redux-2.test.tsx @@ -48,7 +48,7 @@ describe('redux integration', () => { { request: { query, variables }, result: { data } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let wrapper; // Typscript workaround @@ -133,7 +133,7 @@ describe('redux integration', () => { { request: { query, variables: variables2 }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let wrapper; function counter(state = 1, action) { @@ -197,7 +197,7 @@ describe('redux integration', () => { { request: { query, variables: variables2 }, result: { data: data2 } } ); - const client = new ApolloClient({ networkInterface }); + const client = new ApolloClient({ networkInterface, addTypename: false }); let wrapper; function counter(state = 1, action) { diff --git a/test/react-web/server/index.test.tsx b/test/react-web/server/index.test.tsx index 41eddac900..33f5bd7fa6 100644 --- a/test/react-web/server/index.test.tsx +++ b/test/react-web/server/index.test.tsx @@ -39,7 +39,7 @@ describe('SSR', () => { const networkInterface = mockNetworkInterface( { request: { query }, result: { data }, delay: 50 } ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const WrappedElement = graphql(query)(({ data }) => (
{data.loading ? 'loading' : data.currentUser.firstName}
@@ -61,7 +61,7 @@ describe('SSR', () => { const networkInterface = mockNetworkInterface( { request: { query }, result: { data }, delay: 50 } ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const WrappedElement = graphql(query)(({ data }) => (
{data.loading ? 'loading' : data.currentUser.firstName}
@@ -88,7 +88,7 @@ describe('SSR', () => { { request: { query: idQuery }, result: { data: idData }, delay: 50 }, { request: { query: userQuery, variables }, result: { data: userData }, delay: 50 }, ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const withId = graphql(idQuery); const withUser = graphql(userQuery, { @@ -116,7 +116,7 @@ describe('SSR', () => { const networkInterface = mockNetworkInterface( { request: { query }, result: { data }, delay: 50 } ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const WrappedElement = graphql(query, { options: { skip: true }})(({ data }) => (
{data.loading ? 'loading' : 'skipped'}
@@ -139,7 +139,7 @@ describe('SSR', () => { const networkInterface = mockNetworkInterface( { request: { query }, result: { data }, delay: 50 } ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const WrappedElement = graphql(query, { skip: true })(({ data }) => (
{!data ? 'skipped' : 'dang'}
@@ -161,7 +161,7 @@ describe('SSR', () => { const networkInterface = mockNetworkInterface( { request: { query }, result: { data }, delay: 50 } ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const WrappedElement = graphql(query)(({ data }) => (
{data.loading ? 'loading' : data.currentUser.firstName}
@@ -185,7 +185,7 @@ describe('SSR', () => { const networkInterface = mockNetworkInterface( { request: { query, variables }, result: { data }, delay: 50 } ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const Element = graphql(query, { name: 'user' })(({ user }) => (
{user.loading ? 'loading' : user.currentUser.firstName}
@@ -209,7 +209,7 @@ describe('SSR', () => { const networkInterface = mockNetworkInterface( { request: { query, variables }, result: { data }, delay: 50 } ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); @graphql(query, { name: 'user' }) class Element extends React.Component { @@ -247,7 +247,7 @@ describe('SSR', () => { const networkInterface = mockNetworkInterface( { request: { query, variables }, result: { data }, delay: 50 } ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const Element = graphql(query, { name: 'user', @@ -279,7 +279,7 @@ describe('SSR', () => { { request: { query }, result: { data: data1 }, delay: 5 }, { request: { query: mutation }, result: { data: mutationData }, delay: 5 } ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const withQuery = graphql(query, { options: (ownProps) => ({ ssr: true }), @@ -331,7 +331,7 @@ describe('SSR', () => { { request: { query }, result: { data: data1 }, delay: 5 }, { request: { query: mutation }, result: { data: mutationData }, delay: 5 } ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const withQuery = graphql(query, { props: ({ ownProps, data }) => { @@ -366,7 +366,7 @@ describe('SSR', () => { const networkInterface = mockNetworkInterface( { request: { query }, result: { data }, delay: 50 } ); - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const WrappedElement = graphql(query)(({ data }) => (
{data.loading ? 'loading' : data.currentUser.firstName}
@@ -416,7 +416,9 @@ describe('SSR', () => { // XXX mock all queries it('should work on a non trivial example', function() { // this.timeout(10000); - const networkInterface = createNetworkInterface('http://graphql-swapi.parseapp.com/'); + const networkInterface = createNetworkInterface({ + uri: 'http://graphql-swapi.parseapp.com/', + }); const apolloClient = new ApolloClient({ networkInterface }); @graphql(gql` @@ -516,13 +518,13 @@ describe('SSR', () => { }); it('should work with queries that use fragments', function() { - const query = gql`{ currentUser { ...userInfo } }`; + const query = gql`{ currentUser { __typename, ...userInfo } }`; const userInfoFragment = createFragment(gql`fragment userInfo on User { firstName, lastName }`); - const data = { currentUser: { firstName: 'John', lastName: 'Smith' } }; + const data = { currentUser: { __typename: 'User', firstName: 'John', lastName: 'Smith' } }; const networkInterface = { query: () => Promise.resolve({ data }), }; - const apolloClient = new ApolloClient({ networkInterface }); + const apolloClient = new ApolloClient({ networkInterface, addTypename: false }); const UserPage = graphql(query, { options: {