Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind mocked provider #129

Merged
merged 5 commits into from
Dec 1, 2021
Merged

Conversation

Arnarkari93
Copy link
Contributor

@Arnarkari93 Arnarkari93 commented Nov 19, 2021

What

Create <MockedProvider /> in rescript.

Why

  • We need to create the apollo client in rescript so that methods like rescript_query that are added to the client instance are available.
  • We need to serialize the data back to Js.Json.t so that we are writing to the apollo cache since cannot write variants to the cache.
  • Apollo differentiates null and undefined when writing to the cache. None translates to undefined

How

  • Expose makeResult method that takes in toJson method that knows how to serialize back to Js.Json.t. That method is generated as a part of the graphql ppx

@jeddeloh
Copy link
Owner

@Arnarkari93 I've got a couple questions on this PR. Is it ready for review?

@arnar-sothebys
Copy link

Yes, it's ready for review. Did you have some other approach to bind this in mind?

@jeddeloh
Copy link
Owner

Well, I haven't loaded up much in my head yet, but doesn't mocked provider use some react context to provide an apollo client? And in #112, you point out that the client needs these extra properties like rescript_query on it. We then discussed possibly recreating MockedProvider entirely in ReScript since it's not too large.

Are you saying we can just bind to MockedProvider, though?

@arnar-sothebys
Copy link

Ahh, now I remember what was. These bindings will be limited to testing components that use only hooks. If the component tries to directly perform an operation on the apollo client it will try to execute the rescript_query/rescript_mutate/rescript_subscribe method on the client and that will fail.

Rather then binding mocked provider we want to create
a apollo client by calling the rescript method so that methods
like `rescript_query` are available on the client

https://github.com/apollographql/apollo-client/blob/main/src/testing/react/MockedProvider.tsx
@Arnarkari93
Copy link
Contributor Author

Arnarkari93 commented Nov 24, 2021

I have updated the PR and recreated the MockedProvider in rescript.
Official version is here: https://github.com/apollographql/apollo-client/blob/main/src/testing/react/MockedProvider.tsx

@jeddeloh
Copy link
Owner

Thank you, this looks great! I'm going to merge a bit later today. If you want to add a comment in MockedProvider about why we built it ourselves rather than binding, that would probably be good, but no worries if not. I'll do so after.

@arnar-sothebys
Copy link

Thank you, this looks great! I'm going to merge a bit later today. If you want to add a comment in MockedProvider about why we built it ourselves rather than binding, that would probably be good, but no worries if not. I'll do so after.

Yes, no problem. I can add it now.

@jeddeloh jeddeloh merged commit e952560 into jeddeloh:master Dec 1, 2021
@jeddeloh
Copy link
Owner

jeddeloh commented Dec 1, 2021

This is now published in v2.3.0. Thank you so much for working on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants