SurveyMonkey / graphql-ergonomock

Automatic mocking of GraphQL queries
MIT License
19 stars 5 forks source link

Using ergonomock-function with addTypename true #104

Closed jfulse closed 3 years ago

jfulse commented 3 years ago

Hello and thanks for a great library!

I'm trying to use ergonomock() together with a MockedProvider that uses addTypename=true. This doesn't work out of the box because the results from ergonomock() only includes __typename if the query does, and we would like to avoid adding it to the latter manually.

Is there any chance of an addTypename option to ergonomock? If not do you have a suggestion for another solution?

joual commented 3 years ago

Hey @jfulse !

I should be able to take a look at that relatively soon (within a couple days). Off the top of my head I don't see why we shouldn't be able to support that option. It actually sounds like a bug.

jfulse commented 3 years ago

Hello,

That's great news, thank you!

victor-guoyu commented 3 years ago

Hi @jfulse,

Could you please try to use the ErgonoMockedProvider instead of the one from apollo react?

import { ErgonoMockedProvider as MockedProvider } from "graphql-ergonomock";

You can find an example here: https://github.com/SurveyMonkey/graphql-ergonomock/blob/master/README.md#basic-example-apollo

if that doesn't work, please share a code snippet to show us how you used ergonomock and apollo MockedProvider together.

jfulse commented 3 years ago

Hello!

I did try that but couldn't get it working. I'll work in a minimal reproduction (and maybe this exercise itself will indicate something incorrect in my setup..)

jfulse commented 3 years ago

Apologies! It seems our backend has added custom scalar types without me realising it and these are causing the issue. I assume there's a way to mock custom scalars and will dig in and find out. @victor-guoyu

EDIT: So far I can't figure out how to handle custom scalars (beyond mocking each occurrence of such a field manually, which would be impractical). I've tried using both props mocks and resolvers. Have you come across this use case before?

victor-guoyu commented 3 years ago

@jfulse, thanks for the update and I don't think we have support for the custom scalar yet! I'll start working on it today and let you know when it's ready!

jfulse commented 3 years ago

I'll start working on it today and let you know when it's ready!

Once again that's great news, thanks a lot!

victor-guoyu commented 3 years ago

👋 Hi, @jfulse, could you please update to the latest version

here is an example of how you can provide a default mock function for the custom scalar type.

jfulse commented 3 years ago

It works with the latest version, thanks a lot for all the help and the new feature!