Skip to content

Commit

Permalink
chore: rename createProxiedSchema to createTestSchema (#11764)
Browse files Browse the repository at this point in the history
* feat: rename createProxiedSchema to createSchemaProxy

* chore: add changeset

* chore rename createSchemaProxy to createTestSchema and createMockFetch to createSchemaFetch
  • Loading branch information
alessbell authored Apr 10, 2024
1 parent 488acef commit f046aa9
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 36 deletions.
14 changes: 7 additions & 7 deletions .api-reports/api-report-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,22 +450,22 @@ type ConcastSourcesIterable<T> = Iterable<Source<T>>;
export function createMockClient<TData>(data: TData, query: DocumentNode, variables?: {}): ApolloClient<NormalizedCacheObject>;

// @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<Response>;
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 {
Expand Down
4 changes: 2 additions & 2 deletions .api-reports/api-report-testing_core.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ type ConcastSourcesIterable<T> = Iterable<Source<T>>;
export function createMockClient<TData>(data: TData, query: DocumentNode, variables?: {}): ApolloClient<NormalizedCacheObject>;

// @alpha
export const createMockFetch: (schema: GraphQLSchema, mockFetchOpts?: {
export const createSchemaFetch: (schema: GraphQLSchema, mockFetchOpts?: {
validate: boolean;
}) => {
mock: (uri: any, options: any) => Promise<Response>;
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions .changeset/green-garlics-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": minor
---

Rename `createProxiedSchema` to `createTestSchema` and `createMockFetch` to `createSchemaFetch`.
2 changes: 1 addition & 1 deletion config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ Array [
"MockSubscriptionLink",
"MockedProvider",
"createMockClient",
"createMockFetch",
"createMockSchema",
"createProxiedSchema",
"createSchemaFetch",
"createTestSchema",
"itAsync",
"mockObservableLink",
"mockSingleLink",
Expand All @@ -389,8 +389,8 @@ Array [
"MockLink",
"MockSubscriptionLink",
"createMockClient",
"createMockFetch",
"createProxiedSchema",
"createSchemaFetch",
"createTestSchema",
"itAsync",
"mockObservableLink",
"mockSingleLink",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -173,7 +173,7 @@ describe("schema proxy", () => {
it("mocks scalars and resolvers", async () => {
const Profiler = createDefaultProfiler<ViewerQueryData>();

using _fetch = createMockFetch(schema);
using _fetch = createSchemaFetch(schema);

const client = new ApolloClient({
cache: new InMemoryCache(),
Expand Down Expand Up @@ -266,7 +266,7 @@ describe("schema proxy", () => {

const Profiler = createDefaultProfiler<ViewerQueryData>();

using _fetch = createMockFetch(forkedSchema);
using _fetch = createSchemaFetch(forkedSchema);

const client = new ApolloClient({
cache: new InMemoryCache(),
Expand Down Expand Up @@ -349,7 +349,7 @@ describe("schema proxy", () => {
it("does not pollute the original schema", async () => {
const Profiler = createDefaultProfiler<ViewerQueryData>();

using _fetch = createMockFetch(schema);
using _fetch = createSchemaFetch(schema);

const client = new ApolloClient({
cache: new InMemoryCache(),
Expand Down Expand Up @@ -444,7 +444,7 @@ describe("schema proxy", () => {

const Profiler = createDefaultProfiler<ViewerQueryData>();

using _fetch = createMockFetch(forkedSchema);
using _fetch = createSchemaFetch(forkedSchema);

const client = new ApolloClient({
cache: new InMemoryCache(),
Expand Down Expand Up @@ -566,7 +566,7 @@ describe("schema proxy", () => {

const Profiler = createDefaultProfiler<ViewerQueryData>();

using _fetch = createMockFetch(forkedSchema);
using _fetch = createSchemaFetch(forkedSchema);

const client = new ApolloClient({
cache: new InMemoryCache(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -908,7 +908,7 @@ describe("schema proxy", () => {

const Profiler = createDefaultProfiler<ViewerQueryData>();

using _fetch = createMockFetch(forkedSchema);
using _fetch = createSchemaFetch(forkedSchema);

const client = new ApolloClient({
cache: new InMemoryCache(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
) => {
Expand Down Expand Up @@ -84,4 +84,4 @@ const createMockFetch = (
return withCleanup({ mock: mockFetch, restore }, restore);
};

export { createMockFetch };
export { createSchemaFetch };
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -43,7 +43,7 @@ interface ProxiedSchemaFns {
* @since 3.9.0
* @alpha
*/
const createProxiedSchema = (
const createTestSchema = (
schemaWithMocks: GraphQLSchema,
resolvers: Resolvers
): ProxiedSchema => {
Expand All @@ -65,7 +65,7 @@ const createProxiedSchema = (
},

fork: ({ resolvers: newResolvers } = {}) => {
return createProxiedSchema(targetSchema, newResolvers ?? targetResolvers);
return createTestSchema(targetSchema, newResolvers ?? targetResolvers);
},

reset: () => {
Expand Down Expand Up @@ -116,4 +116,4 @@ const createProxiedSchema = (
return schema as ProxiedSchema;
};

export { createProxiedSchema };
export { createTestSchema };
4 changes: 2 additions & 2 deletions src/testing/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit f046aa9

Please sign in to comment.