Skip to content

Refactor createHandler to createHandlerFromSchema #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/strange-socks-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@apollo/graphql-testing-library": minor
---

Adds helper utilities `createDefaultResolvers`, `createPossibleTypesMap`, `generateEnumMocksFromSchema` and `mockCustomScalars` for those who want to manually create and configure their mock schema.

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.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
sourceType: "module",
},
plugins: ["@typescript-eslint"],
ignorePatterns: ["**/__generated__/*.ts"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ jobs:
run: pnpm install

- name: Lint
run: pnpm run lint
run: pnpm run prettier

type-check:
name: Check types
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pnpm-lock.yaml
.storybook/public/mockServiceWorker.js
.storybook/public/mockServiceWorker.js
__generated__
2 changes: 1 addition & 1 deletion .storybook/public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* - Please do NOT serve this file on production.
*/

const PACKAGE_VERSION = '2.3.4'
const PACKAGE_VERSION = '2.3.5'
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
const activeClientIds = new Set()
Expand Down
15 changes: 4 additions & 11 deletions .storybook/stories/ApolloClient.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,24 @@ import {
ApolloApp,
ApolloAppWithDefer as AppWithDefer,
} from "./components/apollo-client/ApolloComponent.js";
import { createHandler } from "../../src/handlers.js";
import { schemaWithMocks } from "../../src/__tests__/mocks/handlers.js";
import { graphQLHandler } from "../../src/__tests__/mocks/handlers.js";

const { handler } = createHandler(schemaWithMocks);

const meta = {
export default {
title: "Example/Apollo Client",
component: ApolloApp,
parameters: {
layout: "centered",
msw: {
handlers: {
graphql: handler,
graphql: graphQLHandler,
},
},
},
} satisfies Meta<typeof ApolloApp>;

export default meta;

export { AppWithDefer };

type Story = StoryObj<typeof meta>;

export const App: Story = {
export const App: StoryObj<typeof ApolloApp> = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await expect(
Expand Down
15 changes: 4 additions & 11 deletions .storybook/stories/Relay.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,24 @@ import {
RelayApp,
RelayAppWithDefer as AppWithDefer,
} from "./components/relay/RelayComponent.js";
import { createHandler } from "../../src/handlers.js";
import { schemaWithMocks } from "../../src/__tests__/mocks/handlers.js";
import { graphQLHandler } from "../../src/__tests__/mocks/handlers.js";

const { handler } = createHandler(schemaWithMocks);

const meta = {
export default {
title: "Example/Relay",
component: RelayApp,
parameters: {
layout: "centered",
msw: {
handlers: {
graphql: handler,
graphql: graphQLHandler,
},
},
},
} satisfies Meta<typeof RelayApp>;

export default meta;

export { AppWithDefer };

type Story = StoryObj<typeof meta>;

export const App: Story = {
export const App: StoryObj<typeof RelayApp> = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await expect(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading