React-apollo: MockedProvider and @connection

Created on 9 Jan 2019  ·  2Comments  ·  Source: apollographql/react-apollo

Intended outcome:

When providing a query to MockedProvider, it works when the exact same query is passed to the Query component.

Actual outcome:

Error: Network error: No more mocked responses for the query.

I have put together a code sandbox that demonstrates the issue pretty clearly: https://codesandbox.io/s/085pqppxn

If you have an @connection directive on the query that is built with gql, when passing it to Query's query prop, it seems that the directive is removed before sending the query over the wire.

However, when passing the same query as a mock to MockedProvider, the directive is left in, resulting in the query never matching and the 'No more mocked responses for the query' happening.

How to reproduce the issue:

See https://codesandbox.io/s/085pqppxn

Version

(both latest at time of submission)

has-PR has-reproduction

Most helpful comment

I'm getting the same error in a different situation:

Here is my query

const LOCAL_INVEST_DATA_QUERY = gql`
    query {
        investAmount @client
        investReferenceId @client
        userDetails {
            email
        }
    }
`;

Here is my test

const mocks = [
    {
        request: {
            query: LOCAL_INVEST_DATA_QUERY
        },
        result: {
            data: {
                investAmount: 10000,
                investReferenceId: 'ASD-123-!@#',
                userDetails: {
                    email: '[email protected]'
                }
            }
        }
    }
];

describe('Payment form test suite', () => {
    test('renders with card option selected', async () => {
        const wrapper = mount(
            <MockedProvider mocks={mocks} addTypename={false}>
                <MyComponent />
            </MockedProvider>
        );

        await wait(2);

        wrapper.update();
        window.console.log(wrapper.debug());
    });
});

Current packages:

"apollo-client": "^2.5.0-beta.0",
"react-apollo": "^2.5.0-beta.1",

The error started happening when i updated from:

"apollo-client": "^2.5.0-alpha.10",
"react-apollo": "^2.4.0-alpha.4",

All 2 comments

I'm getting the same error in a different situation:

Here is my query

const LOCAL_INVEST_DATA_QUERY = gql`
    query {
        investAmount @client
        investReferenceId @client
        userDetails {
            email
        }
    }
`;

Here is my test

const mocks = [
    {
        request: {
            query: LOCAL_INVEST_DATA_QUERY
        },
        result: {
            data: {
                investAmount: 10000,
                investReferenceId: 'ASD-123-!@#',
                userDetails: {
                    email: '[email protected]'
                }
            }
        }
    }
];

describe('Payment form test suite', () => {
    test('renders with card option selected', async () => {
        const wrapper = mount(
            <MockedProvider mocks={mocks} addTypename={false}>
                <MyComponent />
            </MockedProvider>
        );

        await wait(2);

        wrapper.update();
        window.console.log(wrapper.debug());
    });
});

Current packages:

"apollo-client": "^2.5.0-beta.0",
"react-apollo": "^2.5.0-beta.1",

The error started happening when i updated from:

"apollo-client": "^2.5.0-alpha.10",
"react-apollo": "^2.4.0-alpha.4",
Was this page helpful?
0 / 5 - 0 ratings