UNPKG

1.63 kBMarkdownView Raw
1# `@shopify/jest-mock-apollo`
2
3[![Build Status](https://travis-ci.org/Shopify/quilt.svg?branch=master)](https://travis-ci.org/Shopify/quilt)
4[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md) [![npm version](https://badge.fury.io/js/%40shopify%2Fjest-mock-apollo.svg)](https://badge.fury.io/js/%40shopify%2Fjest-mock-apollo)
5
6:warning: This is being replace with [`@shopify/graphql-testing`](../../packages/graphql-testing)
7
8Jest + Enzyme mocks for Apollo 2.x.
9
10## Installation
11
12```bash
13$ yarn add @shopify/jest-mock-apollo
14```
15
16## Setup
17
18This package provides a decorator for building mock GraphQL clients specific to your project. The initial function call takes in project-wide configuration and emits a customized decorator to be used across your project. For example:
19
20```ts
21// tests/utilities/graphql.ts
22import {buildSchema} from 'graphql';
23import configureClient from '@shopify/jest-mock-apollo';
24
25// You likely want to import this from somewhere in real production code
26const schemaSrc = `
27 type Product {
28 id: Int!
29 title: String
30 }
31
32 type Query {
33 products: [Product]
34 }
35`;
36const schema = buildSchema(schemaSrc);
37
38const createGraphQLClient = configureClient({schema});
39
40export {createGraphQLClient};
41```
42
43The factory requires a `GraphQLSchema` (`schema`) in order to ensure that more useful error messages are shown and that mocks are validated against the schema.
44
45## Example Usage
46
47Take a look at the test suite for examples on how to use enzyme's mock context.
48
49## API Reference
50
51See the comments and TypeScript annotations in the code for details on the provided utilities.