apollographql / react-apollo

:recycle: React integration for Apollo Client
https://www.apollographql.com/docs/react/
MIT License
6.85k stars 787 forks source link

`onCompleted` does not receive mocked data from MockedProvider #3899

Open KonradKlimczak opened 4 years ago

KonradKlimczak commented 4 years ago

Data from mocked result in MockProvider is not passed to onCompleted callback.

I have component like this:

function Dogs({ onDogSelected }) {
  const [options, setOptions] = useState([]);
  const [fetch, { loading, error }] = useLazyQuery(GET_DOGS, {
    onCompleted: (data) => {
      setOptions(data.dogs);
    }
  });

  if (loading) return 'Loading...';
  if (error) return `Error! ${error.message}`;

  useEffect(() => {
    fetch();
  }

  return (
    <select name="dog" onChange={onDogSelected}>
      {options.map(dog => (
        <option key={dog.id} value={dog.breed}>
          {dog.breed}
        </option>
      ))}
    </select>
  );
}

When I create a test and wrap it with MockProvider which has mocked query for this component, in onCompleted callback I receive undefined instead of data. If I use it in default way using returned data from useLazyQuery it works just fine.

deepubohra commented 4 years ago

I am also facing the same issue...Any help is much appreciated

carlespibernat commented 4 years ago

Same here!

wildantokped commented 4 years ago

bump

smehltrett commented 4 years ago

I seem to have just run into the same issue. Did anyone find a way around this?

yuriburk commented 4 years ago

Any news or workaround?

essaji commented 4 years ago

Was writing tests & got stuck on this, the data received on onCompleted is always undefined