Open MrTibbles opened 4 years ago
It is already possible to use the Apollo Server mocking in the client side tests, I write all my client-side tests that way. Instead of using MockedProvider
, you can use SchemaLink. This unfortunately means that you will have to keep a copy of your server schema with your client tests (or download the server schema every time the tests run), but I think it's worth it. See this article for more details: https://medium.com/free-code-camp/a-new-approach-to-mocking-graphql-data-1ef49de3d491
That is neat, thanks for sharing link to article.
Leaving open for core contributors visibility. Having a simpler DX as i outline would be excellent, the process @dylanwulf references is neat and achievable, but not as seamless as the Apollo Server mocking feature i referenced.
Having used Apollo for years in production and written countless
MockResponse
s i am all too familiar with the object signature and the creation of those objects. However on occasion it can be tiresome having to create these objects, and more importantly maintain them.So what i am wondering is that would be it possible to support the exact same behaviour from Apollo Server mocking feature on the
MockedProvider
test utility? When running tests on the client side it would be possible to enable auto-mocking of network responses to remove the absolute requirement of having to createMockResponse
objects for all GQL operations? Considering that the @apollo/react-testing package is a dev dep' it would not pollute the run time bundle size of the overall application. However that is based on limited understanding/thought on where this could/would be implemented. I would like to think that it could be achieved via a prop on<MockedProvider />
, using the same implementation from Apollo server with a prop ofmocks
being a boolean or a custom mock object.As ever, more than happy to contribute to adding this behaviour, thought i would get a sense of community opinion first.