# How to run a GQL Query against mock data to get realistic results in unit tests?

**URL:** <https://community.apollographql.com/t/how-to-run-a-gql-query-against-mock-data-to-get-realistic-results-in-unit-tests/7805>\
**Category:** Client SDKs\
**Tags:** client, web\
**Created:** [September 7, 2024, 6:58pm UTC](https://community.apollographql.com/t/how-to-run-a-gql-query-against-mock-data-to-get-realistic-results-in-unit-tests/7805 "2024-09-07T18:58:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gabriel\_Faria](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/gabriel_faria/32/5285_2.png) [@Gabriel\_Faria](https://community.apollographql.com/u/Gabriel_Faria)\
**Post date:** [September 7, 2024, 6:58pm UTC](https://community.apollographql.com/t/how-to-run-a-gql-query-against-mock-data-to-get-realistic-results-in-unit-tests/7805/1 "2024-09-07T18:58:55Z")

</div>

I’m looking for a way to run a query against a mock data object.

**The problem**  
I currently mock the GQL response via `<MockedProvider mocks={mocks}>`. That works great, but the mock’s `result` comes back exactly as defined. The mock response can return fields the query did not ask for.

**The request**  
I would like to have a fake data library and generate the mock result data by getting the fake data and “running” the query against it. [Apollo iOS has pretty much what I want](https://www.apollographql.com/docs/ios/testing/test-mocks/#mocking-graphql-responses-with-json), but it’s not available for React + Typescript. For example:

```auto
const fakeUserData = {id: 1, name: "First Last"};
query = gql`query { user { id } }`;
query.data.from(fakeUserData):
// Returns: {id: 1} without `name`.

```

Does this exist somewhere? Does this pattern make sense?  
Thanks!

---

<div class="post-metadata">

**Author:** ![JeffAuriemma](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jeffauriemma/32/2845_2.png) [@JeffAuriemma](https://community.apollographql.com/u/JeffAuriemma)\
**Post date:** [January 31, 2025, 4:35pm UTC](https://community.apollographql.com/t/how-to-run-a-gql-query-against-mock-data-to-get-realistic-results-in-unit-tests/7805/2 "2025-01-31T16:35:14Z")

</div>

Hi @Gabriel_Faria 👋 try our GraphQL Testing Library, its schema-driven testing API might be what you’re looking for 🙂

> **[GitHub - apollographql/graphql-testing-library: Testing utilities that encourage good practices...](https://github.com/apollographql/graphql-testing-library)**
>
> Testing utilities that encourage good practices for apps built with GraphQL.
