Skip to content
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

Schema-driven testing utilities #11605

Merged
merged 30 commits into from
Apr 2, 2024

Conversation

alessbell
Copy link
Member

Introduces a new testing utility currently in src/testing/core/schemaProxy.ts (name subject to change) which creates a Proxy object to a user-supplied schema, allowing users to set (and override) mock resolvers inline in their tests.

In combination with a terminating SchemaLink or MSW, this new API will allow users to write tests that more closely resemble how users actually use their applications, testing link chain code not previously possible with the MockedProvider approach of static response mocking and providing a way to define default scalar mocks.

This is a draft that makes use of utilities from @graphql-tools/mock which have been inlined with line references to the original MIT-licensed code, and with the license copied over alongside.

Copy link

changeset-bot bot commented Feb 16, 2024

🦋 Changeset detected

Latest commit: 614cd3f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@alessbell alessbell changed the base branch from main to release-3.10 February 16, 2024 20:45
Copy link
Contributor

github-actions bot commented Feb 16, 2024

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 38.58 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 46.44 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 44 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 34.14 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 32.02 KB (0%)
import { ApolloProvider } from "dist/react/index.js" 1.23 KB (0%)
import { ApolloProvider } from "dist/react/index.js" (production) 1.22 KB (0%)
import { useQuery } from "dist/react/index.js" 5.27 KB (0%)
import { useQuery } from "dist/react/index.js" (production) 4.35 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.5 KB (0%)
import { useLazyQuery } from "dist/react/index.js" (production) 4.58 KB (0%)
import { useMutation } from "dist/react/index.js" 3.51 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.73 KB (0%)
import { useSubscription } from "dist/react/index.js" 3.19 KB (0%)
import { useSubscription } from "dist/react/index.js" (production) 2.38 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 5.44 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 4.11 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 4.92 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.58 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 5.03 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 3.69 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.17 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.11 KB (0%)
import { useFragment } from "dist/react/index.js" 2.29 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.23 KB (0%)

Copy link

netlify bot commented Feb 16, 2024

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 614cd3f
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/660c6d3877c481000740b513
😎 Deploy Preview https://deploy-preview-11605--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@alessbell alessbell force-pushed the issue-9738-schema-driven-testing-utils branch from f594629 to e92a0af Compare March 20, 2024 17:37
@alessbell alessbell changed the base branch from release-3.10 to proxied-schema-testing-utils March 20, 2024 17:43
@alessbell
Copy link
Member Author

/release:pr

Copy link
Contributor

A new release has been made for this PR. You can install it with:

npm i @apollo/client@0.0.0-pr-11605-20240321163144

@alessbell alessbell marked this pull request as ready for review March 21, 2024 20:19
src/testing/core/schemaProxy.ts Outdated Show resolved Hide resolved
src/testing/core/mockFetchWithSchema.ts Outdated Show resolved Hide resolved
src/testing/graphql-tools/utils.ts Show resolved Hide resolved
@alessbell alessbell added this to the Schema-driven testing milestone Mar 29, 2024
@alessbell alessbell linked an issue Mar 29, 2024 that may be closed by this pull request
Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neat! I had one comment as something to think about, but otherwise I've got nothing else other than any feedback from Lenz. Really excited for this feature 🎉 🔥

src/testing/core/mockFetchWithSchema.ts Outdated Show resolved Hide resolved
src/testing/core/mockFetchWithSchema.ts Outdated Show resolved Hide resolved
@alessbell alessbell changed the base branch from proxied-schema-testing-utils to release-3.10 April 2, 2024 18:17
@alessbell alessbell merged commit e2dd4c9 into release-3.10 Apr 2, 2024
32 of 33 checks passed
@alessbell alessbell deleted the issue-9738-schema-driven-testing-utils branch April 2, 2024 20:49
@github-actions github-actions bot mentioned this pull request Apr 2, 2024
@github-actions github-actions bot mentioned this pull request Apr 24, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Testing utilities] Custom fetch implementation via context
3 participants