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
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d3d0ed9
feat: introduce schema proxy, copy graphql-tools/utils fns and licens…
alessbell Feb 16, 2024
88c3f4f
scaffold integration test
alessbell Feb 16, 2024
ea891f2
export createMockSchema and proxiedSchema
alessbell Feb 16, 2024
9a63ad9
tests: add schemaProxy tests
alessbell Feb 23, 2024
614b8f6
commit failing mutation test
alessbell Feb 23, 2024
a2375e1
chore: remove integration tests and update mutation test
alessbell Mar 20, 2024
e92a0af
chore: add changeset
alessbell Mar 20, 2024
e765917
chore: update tests and fix ts errors
alessbell Mar 21, 2024
7897611
update mockFetchWithSchema
alessbell Mar 26, 2024
d355cd2
fix: call .bind and move test file
alessbell Mar 26, 2024
85671a6
feat: adds schema validation
alessbell Mar 26, 2024
57ab7e4
chore: update api reports
alessbell Mar 26, 2024
919d66d
chore: remove skipped tests
alessbell Mar 26, 2024
de6aa06
fix: remove typescript ignore comments and improve accuracy of code c…
alessbell Mar 28, 2024
7d30ccf
chore: update launch.json
alessbell Mar 29, 2024
d1f3c19
feat: make fetch automocking/unmocking nicer
alessbell Mar 29, 2024
4f66938
feat: change API to .add and .fork that accept options including reso…
alessbell Mar 29, 2024
177790b
fix: hoist result of shallow merged resolvers to outer scope on calls…
alessbell Apr 1, 2024
a60a313
Clean up Prettier, Size-limit, and Api-Extractor
alessbell Apr 1, 2024
9b4badc
Merge branch 'release-3.10' into issue-9738-schema-driven-testing-utils
alessbell Apr 2, 2024
0079451
fix: remove node-fetch from mockFetchWithSchema
alessbell Apr 2, 2024
f7c04c9
Clean up Prettier, Size-limit, and Api-Extractor
alessbell Apr 2, 2024
d0a9119
chore: adds createMockFetch changeset
alessbell Apr 2, 2024
f72cbba
chore: add doc blocks
alessbell Apr 2, 2024
c86d306
Clean up Prettier, Size-limit, and Api-Extractor
alessbell Apr 2, 2024
59b847c
Merge branch 'release-3.10' into issue-9738-schema-driven-testing-utils
alessbell Apr 2, 2024
225223e
chore: remove unneeded fetch mock from jest-environment-jsdom to fix …
alessbell Apr 2, 2024
26d3e20
Merge branch 'issue-9738-schema-driven-testing-utils' of github.com:a…
alessbell Apr 2, 2024
6670ad8
fix: dont set AbortController in the env, it breaks two PQ tests
alessbell Apr 2, 2024
614cd3f
Merge branch 'release-3.10' into issue-9738-schema-driven-testing-utils
alessbell Apr 2, 2024
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
28 changes: 28 additions & 0 deletions .api-reports/api-report-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { FieldNode } from 'graphql';
import type { FragmentDefinitionNode } from 'graphql';
import type { GraphQLError } from 'graphql';
import type { GraphQLErrorExtensions } from 'graphql';
import type { GraphQLSchema } from 'graphql';
import { Observable } from 'zen-observable-ts';
import type { Observer } from 'zen-observable-ts';
import * as React_2 from 'react';
Expand Down Expand Up @@ -446,6 +447,16 @@ type ConcastSourcesIterable<T> = Iterable<Source<T>>;
// @public (undocumented)
export function createMockClient<TData>(data: TData, query: DocumentNode, variables?: {}): ApolloClient<NormalizedCacheObject>;

// @public (undocumented)
export const createMockFetch: (schema: any, mockFetchOpts?: {
validate: boolean;
}) => (uri: any, options: any) => Promise<Response>;

// @public (undocumented)
export const createMockSchema: (staticSchema: GraphQLSchema, mocks: {
[key: string]: any;
}) => GraphQLSchema;

// @public (undocumented)
namespace DataProxy {
// (undocumented)
Expand Down Expand Up @@ -1265,6 +1276,23 @@ type Path = ReadonlyArray<string | number>;
// @public (undocumented)
type Primitive = null | undefined | string | number | boolean | symbol | bigint;

// Warning: (ae-forgotten-export) The symbol "ProxiedSchemaFns" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export const proxiedSchema: (schemaWithMocks: GraphQLSchema, resolvers: Resolvers) => GraphQLSchema & ProxiedSchemaFns;

// @public (undocumented)
interface ProxiedSchemaFns {
// (undocumented)
addResolvers: (newResolvers: Resolvers) => GraphQLSchema;
// (undocumented)
fork: () => GraphQLSchema;
// (undocumented)
forkWithResolvers: (newResolvers: Resolvers) => GraphQLSchema;
// (undocumented)
reset: () => void;
}

// @public (undocumented)
class QueryInfo {
constructor(queryManager: QueryManager<any>, queryId?: string);
Expand Down
23 changes: 23 additions & 0 deletions .api-reports/api-report-testing_core.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { FieldNode } from 'graphql';
import type { FragmentDefinitionNode } from 'graphql';
import type { GraphQLError } from 'graphql';
import type { GraphQLErrorExtensions } from 'graphql';
import type { GraphQLSchema } from 'graphql';
import { Observable } from 'zen-observable-ts';
import type { Observer } from 'zen-observable-ts';
import type { Subscriber } from 'zen-observable-ts';
Expand Down Expand Up @@ -445,6 +446,11 @@ type ConcastSourcesIterable<T> = Iterable<Source<T>>;
// @public (undocumented)
export function createMockClient<TData>(data: TData, query: DocumentNode, variables?: {}): ApolloClient<NormalizedCacheObject>;

// @public (undocumented)
export const createMockFetch: (schema: any, mockFetchOpts?: {
validate: boolean;
}) => (uri: any, options: any) => Promise<Response>;

// @public (undocumented)
namespace DataProxy {
// (undocumented)
Expand Down Expand Up @@ -1220,6 +1226,23 @@ type Path = ReadonlyArray<string | number>;
// @public (undocumented)
type Primitive = null | undefined | string | number | boolean | symbol | bigint;

// Warning: (ae-forgotten-export) The symbol "ProxiedSchemaFns" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export const proxiedSchema: (schemaWithMocks: GraphQLSchema, resolvers: Resolvers) => GraphQLSchema & ProxiedSchemaFns;

// @public (undocumented)
interface ProxiedSchemaFns {
// (undocumented)
addResolvers: (newResolvers: Resolvers) => GraphQLSchema;
// (undocumented)
fork: () => GraphQLSchema;
// (undocumented)
forkWithResolvers: (newResolvers: Resolvers) => GraphQLSchema;
// (undocumented)
reset: () => void;
}

// @public (undocumented)
class QueryInfo {
constructor(queryManager: QueryManager<any>, queryId?: string);
Expand Down
5 changes: 5 additions & 0 deletions .changeset/stupid-bears-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": minor
---

Adds proxiedSchema and createMockSchema testing utilities
27 changes: 12 additions & 15 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Node.js inspector",
"port": 9229,
"request": "attach",
"skipFiles": ["<node_internals>/**"],
"type": "pwa-node"
},
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${relativeFile}", "--config", "./config/jest.config.js"],
"name": "Jest Attach Node Inspector for Current File",
"cwd": "${workspaceFolder}",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"${relativeFile}",
"--config",
"./config/jest.config.js",
"--runInBand",
"--watch"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
"internalConsoleOptions": "neverOpen"
}
]
}
1 change: 1 addition & 0 deletions config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const react17TestFileIgnoreList = [
ignoreTSFiles,
// We only support Suspense with React 18, so don't test suspense hooks with
// React 17
"src/testing/core/__tests__/schemaProxy.test.tsx",
"src/react/hooks/__tests__/useSuspenseQuery.test.tsx",
"src/react/hooks/__tests__/useBackgroundQuery.test.tsx",
"src/react/hooks/__tests__/useLoadableQuery.test.tsx",
Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.1",
"@graphql-tools/schema": "10.0.3",
"@graphql-tools/utils": "10.0.13",
"@microsoft/api-extractor": "7.42.3",
"@rollup/plugin-node-resolve": "11.2.1",
"@size-limit/esbuild-why": "11.1.1",
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,12 @@ Array [
"MockSubscriptionLink",
"MockedProvider",
"createMockClient",
"createMockFetch",
"createMockSchema",
"itAsync",
"mockObservableLink",
"mockSingleLink",
"proxiedSchema",
"subscribeAndCount",
"tick",
"wait",
Expand All @@ -386,9 +389,11 @@ Array [
"MockLink",
"MockSubscriptionLink",
"createMockClient",
"createMockFetch",
"itAsync",
"mockObservableLink",
"mockSingleLink",
"proxiedSchema",
"subscribeAndCount",
"tick",
"wait",
Expand Down
Loading
Loading