0.0.6 • Published 3 years ago

operation-name-mock-link v0.0.6

Weekly downloads
9
License
MIT
Repository
github
Last release
3 years ago

Operation Name Mock Link

Differences with default Apollo MockedProvider

MockedProvider has a very strict matching behaviour: your query variables and the mock variables must match EXACTLY, including keys with the value undefined. It makes tests very bristle and leads to the dreaded No more mocked responses for the query: error.

This package uses a lighter approach, mocks are matched only based on the operationName.

Limitation: this might be problematic if a component is triggering multiple queries with the same operationName. But it is fine in most scenarios.

Usage

import {
  OperationNameMockedResponse,
  OperationNameMockLink
} from "operation-name-mock-link";

interface GetSomeDataResult {
  getSomeData: {
    id: string;
  }
}

const mock: OperationNameMockedResponse<GetSomeDataResult> = {
  request: {
    operationName: "myQuery",
    query: gql`
      query myQuery {
        getSomeData {
          id
        }
      }`
  },
  result: {
    data: {
      getSomeData: {
          id: "42"
      }
    }
  }
};

const wrapper = ({ children }) => (
  <MockedProvider
    // We replace MockedProvider default link with our custom MockLink
    link={new OperationNameMockLink([mock], false)}
  >
    {children}
  </MockedProvider>
);
0.0.5

3 years ago

0.0.6

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago