Skip to content

Commit 2cf1dcd

Browse files
authored
Rename createHandler to createHandlerFromSchema, export utilities (#83)
1 parent 2ef075e commit 2cf1dcd

29 files changed

+113082
-570
lines changed

.changeset/strange-socks-admire.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@apollo/graphql-testing-library": minor
3+
---
4+
5+
Adds helper utilities `createDefaultResolvers`, `createPossibleTypesMap`, `generateEnumMocksFromSchema` and `mockCustomScalars` for those who want to manually create and configure their mock schema.
6+
7+
Also renames `createHandler` to `createHandlerFromSchema`; `createHandler` now provides an API that will create the mock schema under the hood with default resolvers as well as enum and custom scalar mocks.

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = {
1818
sourceType: "module",
1919
},
2020
plugins: ["@typescript-eslint"],
21+
ignorePatterns: ["**/__generated__/*.ts"],
2122
rules: {
2223
"@typescript-eslint/no-explicit-any": "off",
2324
"@typescript-eslint/no-unused-vars": [

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ jobs:
227227
run: pnpm install
228228

229229
- name: Lint
230-
run: pnpm run lint
230+
run: pnpm run prettier
231231

232232
type-check:
233233
name: Check types

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pnpm-lock.yaml
2-
.storybook/public/mockServiceWorker.js
2+
.storybook/public/mockServiceWorker.js
3+
__generated__

.storybook/public/mockServiceWorker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* - Please do NOT serve this file on production.
99
*/
1010

11-
const PACKAGE_VERSION = '2.3.4'
11+
const PACKAGE_VERSION = '2.3.5'
1212
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
1313
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
1414
const activeClientIds = new Set()

.storybook/stories/ApolloClient.stories.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,24 @@ import {
44
ApolloApp,
55
ApolloAppWithDefer as AppWithDefer,
66
} from "./components/apollo-client/ApolloComponent.js";
7-
import { createHandler } from "../../src/handlers.js";
8-
import { schemaWithMocks } from "../../src/__tests__/mocks/handlers.js";
7+
import { graphQLHandler } from "../../src/__tests__/mocks/handlers.js";
98

10-
const { handler } = createHandler(schemaWithMocks);
11-
12-
const meta = {
9+
export default {
1310
title: "Example/Apollo Client",
1411
component: ApolloApp,
1512
parameters: {
1613
layout: "centered",
1714
msw: {
1815
handlers: {
19-
graphql: handler,
16+
graphql: graphQLHandler,
2017
},
2118
},
2219
},
2320
} satisfies Meta<typeof ApolloApp>;
2421

25-
export default meta;
26-
2722
export { AppWithDefer };
2823

29-
type Story = StoryObj<typeof meta>;
30-
31-
export const App: Story = {
24+
export const App: StoryObj<typeof ApolloApp> = {
3225
play: async ({ canvasElement }) => {
3326
const canvas = within(canvasElement);
3427
await expect(

.storybook/stories/Relay.stories.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,24 @@ import {
44
RelayApp,
55
RelayAppWithDefer as AppWithDefer,
66
} from "./components/relay/RelayComponent.js";
7-
import { createHandler } from "../../src/handlers.js";
8-
import { schemaWithMocks } from "../../src/__tests__/mocks/handlers.js";
7+
import { graphQLHandler } from "../../src/__tests__/mocks/handlers.js";
98

10-
const { handler } = createHandler(schemaWithMocks);
11-
12-
const meta = {
9+
export default {
1310
title: "Example/Relay",
1411
component: RelayApp,
1512
parameters: {
1613
layout: "centered",
1714
msw: {
1815
handlers: {
19-
graphql: handler,
16+
graphql: graphQLHandler,
2017
},
2118
},
2219
},
2320
} satisfies Meta<typeof RelayApp>;
2421

25-
export default meta;
26-
2722
export { AppWithDefer };
2823

29-
type Story = StoryObj<typeof meta>;
30-
31-
export const App: Story = {
24+
export const App: StoryObj<typeof RelayApp> = {
3225
play: async ({ canvasElement }) => {
3326
const canvas = within(canvasElement);
3427
await expect(

.storybook/stories/components/relay/__generated__/RelayComponentAppQuery.graphql.ts

Lines changed: 109 additions & 116 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)