-
Notifications
You must be signed in to change notification settings - Fork 787
Apollo MockedProvider with client directives #2508
Comments
Faced the same problem, created a branch to integrate apollo-link-state with it. https://github.com/Rafe/react-apollo/commit/1979d07ad2290856f7db3f8a0133002bf71f8cc8 In this commit, I added the Open the Any thought? |
I was able to get this working using the const cache = new InMemoryCache().restore({
ROOT_QUERY: {
someQueryName: {
type: 'id',
id: 'SOME-QUERY-NAME-ID',
generated: false,
},
},
'SOME-QUERY-NAME-ID': {
a: 1,
prop: true,
or: 'hello',
two: 3,
__typename: 'SomeQuery',
},
});
render(
<MockedProvider cache={cache}>
<ComponentWhichMakesSomeQuery />
</MockedProvider>
); (Hope that makes sense) |
* Adds test for #2508 * Allow @client fields in the `MockedProvider` link chain by default Apollo Client 2.5 handles `@client` fields locally, which means when using local resolvers, `@client` fields aren't sent through AC's configured link chain. To allow people to upgrade to AC 2.5 painlessly, local `@client` handling has to be enabled by setting local resolvers. If local resolvers aren't set, the `@client` field is still sent through the link chain. `MockedProvider` was updated to include a `resolvers` prop, that can be used to pass local resolvers into the `ApolloClient` instance it uses internally for testing. The `resolvers` prop was given a default value of `{}` however, which means AC's local resolver support is always enabled, and also means that `MockedProvider` can't be used for tests that require the `@client` field to be passed through the link chain. When we hit Apollo Client 3.0, this won't be necessary, but for now we need to be flexible about this, since people might have updated to Apollo Client 2.5, but are still using and testing local state using `apollo-link-state`. Long story short, this commit removes the `resolvers` default, which means by default `MockedProvider` isn't using AC 2.5's new local state handling. It has to be enabled by prodiving local resolvers via the `MockedProvider` `resolvers` prop. * Updated @client tests * Changelog update
When using apollo-client 2.4.8 and react-apollo 2.4.0, MockedProvider handled I have a small query like this: query isLoadingQuery {
loadingStatus @client {
isLoading
}
} and a test like const mock = {
request: {
query: isLoadingQuery
},
result: {
data: {
loadingStatus: {
isLoading: true
}
}
}
};
describe('Pace', function() {
it('should render pace when loading', function() {
const wrapper = mount(
<MockedProvider mocks={[mock]} addTypename={false}>
<ApolloPace height={25} />
</MockedProvider>
);
expect(wrapper.children().html()).toBeNull();
return waitForExpect(() => {
wrapper.update();
expect(wrapper.children().html()).not.toBeNull();
});
});
}); This test used to pass before the upgrade. Now I can only get it to pass by removing |
Related: ardatan/graphql-tools#916 |
This was fixed in #2524, and will be included in the next |
Y A S Awesome, thanks. |
@hwillson any chance it'll be released today? |
Fixed in #2524. Thanks! |
I am still having this issue with this setup: ├─ @apollo/[email protected] |
I am also seeing a @client warning and not the expected behaviour so my test fails
Query
Test
warning |
For someone who still experience this problem, adding __typename solved it for me |
Intended outcome:
When using a MockedProvider and a query with client directives, the client directives should resolve
Actual outcome:
Client directives are unrecognized and console warns a message. There does not seem a way to specify apollo-link-state on the MockedProvider, which means any component using a client directive in its query is not really testable.
How to reproduce the issue:
Use a @client in a query, and then run the mockedProvider, the client directive will not be resolved.
Version
The text was updated successfully, but these errors were encountered: