Skip to content

Instantly share code, notes, and snippets.

@rcdexta
Last active November 9, 2021 16:19
Show Gist options
  • Save rcdexta/d2a7b3859e807abdc955155128e5cf38 to your computer and use it in GitHub Desktop.
Save rcdexta/d2a7b3859e807abdc955155128e5cf38 to your computer and use it in GitHub Desktop.
export function ApolloMockedProvider(props: any) {
let { mocks, ...otherProps } = props;
let mockLink = new MockLink(mocks);
let errorLoggingLink = onError(({ networkError }) => {
if (networkError) {
/No more mocked responses for the query/.test(networkError.message);
console.warn(`[Network error]: ${networkError}`);
}
});
let link = ApolloLink.from([errorLoggingLink, mockLink]);
return <MockedProvider {...otherProps} link={link} />;
}
@rcdexta
Copy link
Author

rcdexta commented Nov 9, 2021

Sample usage:

< ApolloMockedProvider mocks={mocks}>
        // component to mock and test
</ApolloMockedProvider >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment