graphql-hooks
Version:
38 lines (37 loc) • 1.23 kB
TypeScript
import GraphQLClient from './GraphQLClient';
import LocalGraphQLError from './LocalGraphQLError';
import { LocalClientOptions, LocalQueries } from './types/common-types';
/** Local version of the GraphQLClient which only returns specified queries
* Meant to be used as a way to easily mock and test queries during development. This client never contacts any actual server.
* Queries are given in the form of an object of functions.
* Example:
```
const localQueries = {
[allPostsQuery]: () => ({
allPosts: [
{
id: 1,
title: 'Test',
url: 'https://example.com'
}
]
}),
[createPostMutation]: () => ({ createPost: { id: 1 } }),
}
const client = new LocalGraphQLClient({ localQueries })
```
*/
declare class LocalGraphQLClient extends GraphQLClient {
localQueries: LocalQueries;
requestDelayMs: number;
constructor(config: LocalClientOptions);
verifyConfig(): void;
request(operation: any): Promise<{
error: LocalGraphQLError<any>;
data?: undefined;
} | {
data: any;
error?: undefined;
}>;
}
export default LocalGraphQLClient;