From f046aa9fc24ac197a797045d280811a3bbe05806 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Wed, 10 Apr 2024 09:58:00 -0400 Subject: [PATCH] chore: rename `createProxiedSchema` to `createTestSchema` (#11764) * feat: rename createProxiedSchema to createSchemaProxy * chore: add changeset * chore rename createSchemaProxy to createTestSchema and createMockFetch to createSchemaFetch --- .api-reports/api-report-testing.md | 14 +++++------ .api-reports/api-report-testing_core.md | 4 ++-- .changeset/green-garlics-protect.md | 5 ++++ config/jest.config.js | 2 +- src/__tests__/__snapshots__/exports.ts.snap | 8 +++---- ...ema.test.tsx => createTestSchema.test.tsx} | 24 +++++++++---------- ...reateMockFetch.ts => createSchemaFetch.ts} | 8 +++---- ...teProxiedSchema.ts => createTestSchema.ts} | 8 +++---- src/testing/core/index.ts | 4 ++-- 9 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 .changeset/green-garlics-protect.md rename src/testing/core/__tests__/{createProxiedSchema.test.tsx => createTestSchema.test.tsx} (97%) rename src/testing/core/{createMockFetch.ts => createSchemaFetch.ts} (92%) rename src/testing/core/{createProxiedSchema.ts => createTestSchema.ts} (94%) diff --git a/.api-reports/api-report-testing.md b/.api-reports/api-report-testing.md index 774a8e69cd1..e2734983594 100644 --- a/.api-reports/api-report-testing.md +++ b/.api-reports/api-report-testing.md @@ -450,22 +450,22 @@ type ConcastSourcesIterable = Iterable>; export function createMockClient(data: TData, query: DocumentNode, variables?: {}): ApolloClient; // @alpha -export const createMockFetch: (schema: GraphQLSchema, mockFetchOpts?: { +export const createMockSchema: (staticSchema: GraphQLSchema, mocks: { + [key: string]: any; +}) => GraphQLSchema; + +// @alpha +export const createSchemaFetch: (schema: GraphQLSchema, mockFetchOpts?: { validate: boolean; }) => { mock: (uri: any, options: any) => Promise; restore: () => void; } & Disposable; -// @alpha -export const createMockSchema: (staticSchema: GraphQLSchema, mocks: { - [key: string]: any; -}) => GraphQLSchema; - // Warning: (ae-forgotten-export) The symbol "ProxiedSchema" needs to be exported by the entry point index.d.ts // // @alpha -export const createProxiedSchema: (schemaWithMocks: GraphQLSchema, resolvers: Resolvers) => ProxiedSchema; +export const createTestSchema: (schemaWithMocks: GraphQLSchema, resolvers: Resolvers) => ProxiedSchema; // @public (undocumented) namespace DataProxy { diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index 42df7b5c695..0534bddcecb 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -449,7 +449,7 @@ type ConcastSourcesIterable = Iterable>; export function createMockClient(data: TData, query: DocumentNode, variables?: {}): ApolloClient; // @alpha -export const createMockFetch: (schema: GraphQLSchema, mockFetchOpts?: { +export const createSchemaFetch: (schema: GraphQLSchema, mockFetchOpts?: { validate: boolean; }) => { mock: (uri: any, options: any) => Promise; @@ -459,7 +459,7 @@ export const createMockFetch: (schema: GraphQLSchema, mockFetchOpts?: { // Warning: (ae-forgotten-export) The symbol "ProxiedSchema" needs to be exported by the entry point index.d.ts // // @alpha -export const createProxiedSchema: (schemaWithMocks: GraphQLSchema, resolvers: Resolvers) => ProxiedSchema; +export const createTestSchema: (schemaWithMocks: GraphQLSchema, resolvers: Resolvers) => ProxiedSchema; // @public (undocumented) namespace DataProxy { diff --git a/.changeset/green-garlics-protect.md b/.changeset/green-garlics-protect.md new file mode 100644 index 00000000000..53dbebb4f55 --- /dev/null +++ b/.changeset/green-garlics-protect.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": minor +--- + +Rename `createProxiedSchema` to `createTestSchema` and `createMockFetch` to `createSchemaFetch`. diff --git a/config/jest.config.js b/config/jest.config.js index 0375a1a071a..4832d1355c7 100644 --- a/config/jest.config.js +++ b/config/jest.config.js @@ -33,7 +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__/createProxiedSchema.test.tsx", + "src/testing/core/__tests__/createTestSchema.test.tsx", "src/react/hooks/__tests__/useSuspenseQuery.test.tsx", "src/react/hooks/__tests__/useBackgroundQuery.test.tsx", "src/react/hooks/__tests__/useLoadableQuery.test.tsx", diff --git a/src/__tests__/__snapshots__/exports.ts.snap b/src/__tests__/__snapshots__/exports.ts.snap index 5744dc7b332..bee4f75643a 100644 --- a/src/__tests__/__snapshots__/exports.ts.snap +++ b/src/__tests__/__snapshots__/exports.ts.snap @@ -369,9 +369,9 @@ Array [ "MockSubscriptionLink", "MockedProvider", "createMockClient", - "createMockFetch", "createMockSchema", - "createProxiedSchema", + "createSchemaFetch", + "createTestSchema", "itAsync", "mockObservableLink", "mockSingleLink", @@ -389,8 +389,8 @@ Array [ "MockLink", "MockSubscriptionLink", "createMockClient", - "createMockFetch", - "createProxiedSchema", + "createSchemaFetch", + "createTestSchema", "itAsync", "mockObservableLink", "mockSingleLink", diff --git a/src/testing/core/__tests__/createProxiedSchema.test.tsx b/src/testing/core/__tests__/createTestSchema.test.tsx similarity index 97% rename from src/testing/core/__tests__/createProxiedSchema.test.tsx rename to src/testing/core/__tests__/createTestSchema.test.tsx index dc5f686f8c7..25dbe78631e 100644 --- a/src/testing/core/__tests__/createProxiedSchema.test.tsx +++ b/src/testing/core/__tests__/createTestSchema.test.tsx @@ -13,14 +13,14 @@ import { spyOnConsole, useTrackRenders, } from "../../internal/index.js"; -import { createProxiedSchema } from "../createProxiedSchema.js"; +import { createTestSchema } from "../createTestSchema.js"; import { GraphQLError, buildSchema } from "graphql"; import type { UseSuspenseQueryResult } from "../../../react/index.js"; import { useMutation, useSuspenseQuery } from "../../../react/index.js"; import { createMockSchema } from "../../graphql-tools/utils.js"; import userEvent from "@testing-library/user-event"; import { act, screen } from "@testing-library/react"; -import { createMockFetch } from "../createMockFetch.js"; +import { createSchemaFetch } from "../createSchemaFetch.js"; import { FallbackProps, ErrorBoundary as ReactErrorBoundary, @@ -147,7 +147,7 @@ describe("schema proxy", () => { Date: () => new Date("January 1, 2024 01:00:00").toJSON().split("T")[0], }); - const schema = createProxiedSchema(schemaWithMocks, { + const schema = createTestSchema(schemaWithMocks, { Query: { viewer: () => ({ name: "Jane Doe", @@ -173,7 +173,7 @@ describe("schema proxy", () => { it("mocks scalars and resolvers", async () => { const Profiler = createDefaultProfiler(); - using _fetch = createMockFetch(schema); + using _fetch = createSchemaFetch(schema); const client = new ApolloClient({ cache: new InMemoryCache(), @@ -266,7 +266,7 @@ describe("schema proxy", () => { const Profiler = createDefaultProfiler(); - using _fetch = createMockFetch(forkedSchema); + using _fetch = createSchemaFetch(forkedSchema); const client = new ApolloClient({ cache: new InMemoryCache(), @@ -349,7 +349,7 @@ describe("schema proxy", () => { it("does not pollute the original schema", async () => { const Profiler = createDefaultProfiler(); - using _fetch = createMockFetch(schema); + using _fetch = createSchemaFetch(schema); const client = new ApolloClient({ cache: new InMemoryCache(), @@ -444,7 +444,7 @@ describe("schema proxy", () => { const Profiler = createDefaultProfiler(); - using _fetch = createMockFetch(forkedSchema); + using _fetch = createSchemaFetch(forkedSchema); const client = new ApolloClient({ cache: new InMemoryCache(), @@ -566,7 +566,7 @@ describe("schema proxy", () => { const Profiler = createDefaultProfiler(); - using _fetch = createMockFetch(forkedSchema); + using _fetch = createSchemaFetch(forkedSchema); const client = new ApolloClient({ cache: new InMemoryCache(), @@ -709,7 +709,7 @@ describe("schema proxy", () => { const { ErrorBoundary } = createTrackedErrorComponents(Profiler); - using _fetch = createMockFetch(forkedSchema); + using _fetch = createSchemaFetch(forkedSchema); const client = new ApolloClient({ cache: new InMemoryCache(), @@ -789,7 +789,7 @@ describe("schema proxy", () => { const { ErrorBoundary } = createTrackedErrorComponents(Profiler); // @ts-expect-error - we're intentionally passing an invalid schema - using _fetch = createMockFetch(forkedSchema); + using _fetch = createSchemaFetch(forkedSchema); const client = new ApolloClient({ cache: new InMemoryCache(), @@ -849,7 +849,7 @@ describe("schema proxy", () => { it("preserves resolvers from previous calls to .add on subsequent calls to .fork", async () => { let name = "Virginia"; - const schema = createProxiedSchema(schemaWithMocks, { + const schema = createTestSchema(schemaWithMocks, { Query: { viewer: () => ({ name, @@ -908,7 +908,7 @@ describe("schema proxy", () => { const Profiler = createDefaultProfiler(); - using _fetch = createMockFetch(forkedSchema); + using _fetch = createSchemaFetch(forkedSchema); const client = new ApolloClient({ cache: new InMemoryCache(), diff --git a/src/testing/core/createMockFetch.ts b/src/testing/core/createSchemaFetch.ts similarity index 92% rename from src/testing/core/createMockFetch.ts rename to src/testing/core/createSchemaFetch.ts index 7adb50d10ae..8b9b5d82dd7 100644 --- a/src/testing/core/createMockFetch.ts +++ b/src/testing/core/createSchemaFetch.ts @@ -22,15 +22,15 @@ import { withCleanup } from "../internal/index.js"; * * @example * ```js - * using _fetch = createMockFetch(schema); // automatically restores fetch after exiting the block + * using _fetch = createSchemaFetch(schema); // automatically restores fetch after exiting the block * - * const { restore } = createMockFetch(schema); + * const { restore } = createSchemaFetch(schema); * restore(); // manually restore fetch if `using` is not supported * ``` * @since 3.10.0 * @alpha */ -const createMockFetch = ( +const createSchemaFetch = ( schema: GraphQLSchema, mockFetchOpts: { validate: boolean } = { validate: true } ) => { @@ -84,4 +84,4 @@ const createMockFetch = ( return withCleanup({ mock: mockFetch, restore }, restore); }; -export { createMockFetch }; +export { createSchemaFetch }; diff --git a/src/testing/core/createProxiedSchema.ts b/src/testing/core/createTestSchema.ts similarity index 94% rename from src/testing/core/createProxiedSchema.ts rename to src/testing/core/createTestSchema.ts index e3ceaec2043..af7911d50da 100644 --- a/src/testing/core/createProxiedSchema.ts +++ b/src/testing/core/createTestSchema.ts @@ -32,7 +32,7 @@ interface ProxiedSchemaFns { Date: () => new Date("December 10, 1815 01:00:00").toJSON().split("T")[0], }); * - * const schema = createProxiedSchema(schemaWithMocks, { + * const schema = createTestSchema(schemaWithMocks, { Query: { writer: () => ({ name: "Ada Lovelace", @@ -43,7 +43,7 @@ interface ProxiedSchemaFns { * @since 3.9.0 * @alpha */ -const createProxiedSchema = ( +const createTestSchema = ( schemaWithMocks: GraphQLSchema, resolvers: Resolvers ): ProxiedSchema => { @@ -65,7 +65,7 @@ const createProxiedSchema = ( }, fork: ({ resolvers: newResolvers } = {}) => { - return createProxiedSchema(targetSchema, newResolvers ?? targetResolvers); + return createTestSchema(targetSchema, newResolvers ?? targetResolvers); }, reset: () => { @@ -116,4 +116,4 @@ const createProxiedSchema = ( return schema as ProxiedSchema; }; -export { createProxiedSchema }; +export { createTestSchema }; diff --git a/src/testing/core/index.ts b/src/testing/core/index.ts index b9b3065b211..3aaad32032b 100644 --- a/src/testing/core/index.ts +++ b/src/testing/core/index.ts @@ -12,6 +12,6 @@ export { createMockClient } from "./mocking/mockClient.js"; export { default as subscribeAndCount } from "./subscribeAndCount.js"; export { itAsync } from "./itAsync.js"; export { wait, tick } from "./wait.js"; -export { createProxiedSchema } from "./createProxiedSchema.js"; -export { createMockFetch } from "./createMockFetch.js"; +export { createTestSchema } from "./createTestSchema.js"; +export { createSchemaFetch } from "./createSchemaFetch.js"; export * from "./withConsoleSpy.js";