Skip to content

Instantly share code, notes, and snippets.

@danahartweg
Created July 2, 2022 18:34
Show Gist options
  • Save danahartweg/c0aaa956b73f4f3052b21aa0fac4ea09 to your computer and use it in GitHub Desktop.
Save danahartweg/c0aaa956b73f4f3052b21aa0fac4ea09 to your computer and use it in GitHub Desktop.
Query test harness - Unit testing Flutter GraphQL
MockQueryResult<T> generateMockQuery<T>(MockGraphQLClient graphQLClient) {
registerFallbackValue(_FakeQueryOptions<T>());
final result = MockQueryResult<T>();
when(() => graphQLClient.query<T>(any())).thenAnswer((_) async => result);
final queryManager = graphQLClient.queryManager;
when(() => queryManager.query<T>(any())).thenAnswer((_) async => result);
return result;
}
class MockQueryResult<T> extends Mock implements QueryResult<T> {}
class _FakeQueryOptions<T> extends Fake implements QueryOptions<T> {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment