trojanowski / apollo-link-mock Goto Github PK
View Code? Open in Web Editor NEWCorrectly transpiled test-links.ts from react-apollo repository
License: Other
Correctly transpiled test-links.ts from react-apollo repository
License: Other
MockLink
is now supported in @apollo/react-testing
as a transpiled lib export already:
import { MockLink } from '@apollo/react-testing';
https://github.com/apollographql/apollo-client/blob/master/src/utilities/testing/index.ts#L2
https://github.com/apollographql/apollo-client/blob/master/src/utilities/testing/mocking/mockLink.ts
For anyone coming here wondering why they're getting errors like No more mocked responses for the query...
If you're using the @connection
directive for helping with paginated caching, this standalone version of the mock link is not sufficient without some help. The issue has been fixed in react-apollo
, where this link was extracted from: https://github.com/apollographql/react-apollo/pull/2523/files
I'm not sure if the right action would be to update this link here or to deprecate this repo to avoid future confusion. It seems strange to have these two maintained in parallel, but at any rate, hopefully this issue will save someone some time while googling/looking around. A workaround if people still wish to continue using this project is to utilize removeConnectionDirectiveFromDocument
from apollo-utilities
.
import { removeConnectionDirectiveFromDocument } from 'apollo-utilies';
const mock = {
request: {
query: removeConnectionDirectiveFromDocument(myQueryDocumentThatIncludesAConnectionDirective),
variables: { ... }
},
result: { ... }
};
const client = new ApolloClient({
cache: ...,
link: new MockLink([mock])
});
Feel free to close this issue @trojanowski if you're not interested in updating this project with those fixes - I just wanted to get this out there in case it's helpful for anyone. I started using react-apollo/test-utils
directly for my use-case because I'm already relying on that project, but I understand people might have valid reasons for using this fork.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.