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 |
|
8 | Jest + Enzyme mocks for Apollo 2.x.
|
9 |
|
10 | ## Installation
|
11 |
|
12 | ```bash
|
13 | $ yarn add @shopify/jest-mock-apollo
|
14 | ```
|
15 |
|
16 | ## Setup
|
17 |
|
18 | This 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
|
22 | import {buildSchema} from 'graphql';
|
23 | import configureClient from '@shopify/jest-mock-apollo';
|
24 |
|
25 | // You likely want to import this from somewhere in real production code
|
26 | const schemaSrc = `
|
27 | type Product {
|
28 | id: Int!
|
29 | title: String
|
30 | }
|
31 |
|
32 | type Query {
|
33 | products: [Product]
|
34 | }
|
35 | `;
|
36 | const schema = buildSchema(schemaSrc);
|
37 |
|
38 | const createGraphQLClient = configureClient({schema});
|
39 |
|
40 | export {createGraphQLClient};
|
41 | ```
|
42 |
|
43 | The 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 |
|
47 | Take a look at the test suite for examples on how to use enzyme's mock context.
|
48 |
|
49 | ## API Reference
|
50 |
|
51 | See the comments and TypeScript annotations in the code for details on the provided utilities.
|