Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Allow to set FetchResult generic type in MockedResponse #3636

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

niekert
Copy link

@niekert niekert commented Oct 28, 2019

Currently there is no way to specify the shape of the FetchResult of a MockedResponse. Because of this, it's easy to pass the incorrect data to MockedResponse. By adding the TData generic to FetchResult it's possible to specify the shape of data that the query should return.

interface Result {
  someMutation: {
    ok: boolean
  }
}

const mockedResponse: MockedResponse<Result> = {
  request: {
    query: SomeDocument
  },
  data: {
    someMutation: {
       ok: true // This is now typechecked
       something: '', // TS error because this does not exist in `Result` type.
    }
  }
}

@apollo-cla
Copy link

@niekert: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

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

Successfully merging this pull request may close these issues.

2 participants