Skip to content

Commit

Permalink
chore rename createSchemaProxy to createTestSchema and createMockFetc…
Browse files Browse the repository at this point in the history
…h to createSchemaFetch
  • Loading branch information
alessbell committed Apr 10, 2024
1 parent 5b432d2 commit 837286b
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 37 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 createSchemaProxy: (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 createSchemaProxy: (schemaWithMocks: GraphQLSchema, resolvers: Resolvers) => ProxiedSchema;
export const createTestSchema: (schemaWithMocks: GraphQLSchema, resolvers: Resolvers) => ProxiedSchema;

// @public (undocumented)
namespace DataProxy {
Expand Down
2 changes: 1 addition & 1 deletion .changeset/green-garlics-protect.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@apollo/client": minor
---

Rename `createProxiedSchema` to `createSchemaProxy`
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__/createSchemaProxy.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",
"createSchemaProxy",
"createSchemaFetch",
"createTestSchema",
"itAsync",
"mockObservableLink",
"mockSingleLink",
Expand All @@ -389,8 +389,8 @@ Array [
"MockLink",
"MockSubscriptionLink",
"createMockClient",
"createMockFetch",
"createSchemaProxy",
"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 { createSchemaProxy } from "../createSchemaProxy.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 = createSchemaProxy(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 = createSchemaProxy(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 = createSchemaProxy(schemaWithMocks, {
* const schema = createTestSchema(schemaWithMocks, {
Query: {
writer: () => ({
name: "Ada Lovelace",
Expand All @@ -43,7 +43,7 @@ interface ProxiedSchemaFns {
* @since 3.9.0
* @alpha
*/
const createSchemaProxy = (
const createTestSchema = (
schemaWithMocks: GraphQLSchema,
resolvers: Resolvers
): ProxiedSchema => {
Expand All @@ -65,7 +65,7 @@ const createSchemaProxy = (
},

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

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

export { createSchemaProxy };
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 { createSchemaProxy } from "./createSchemaProxy.js";
export { createMockFetch } from "./createMockFetch.js";
export { createTestSchema } from "./createTestSchema.js";
export { createSchemaFetch } from "./createSchemaFetch.js";
export * from "./withConsoleSpy.js";

0 comments on commit 837286b

Please sign in to comment.