From 35a91e4bcc2e2aa8a3462aecde189537719349f1 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 2 Apr 2025 15:48:21 +0200 Subject: [PATCH 1/6] add `@apollo/client/testing/internal` entry point --- src/__tests__/ApolloClient.ts | 6 +++-- src/__tests__/client.ts | 6 +++-- src/__tests__/dataMasking.ts | 6 +++-- src/__tests__/fetchMore.ts | 9 +++---- src/__tests__/graphqlSubscriptions.ts | 3 +-- src/__tests__/local-state/export.ts | 3 +-- src/__tests__/local-state/general.ts | 3 +-- src/__tests__/local-state/resolvers.ts | 2 +- src/__tests__/local-state/subscriptions.ts | 3 +-- src/__tests__/mutationResults.ts | 6 +++-- src/__tests__/optimistic.ts | 3 +-- src/__tests__/refetchQueries.ts | 3 +-- src/__tests__/subscribeToMore.ts | 6 +++-- src/cache/inmemory/__tests__/cache.ts | 2 +- src/cache/inmemory/__tests__/entityStore.ts | 2 +- .../inmemory/__tests__/fragmentRegistry.ts | 3 +-- src/cache/inmemory/__tests__/policies.ts | 8 +++--- src/cache/inmemory/__tests__/roundtrip.ts | 2 +- src/cache/inmemory/__tests__/writeToStore.ts | 2 +- .../__tests__/ApolloClient/general.test.ts | 10 +++---- .../ApolloClient/multiple-results.test.ts | 3 +-- src/core/__tests__/ObservableQuery.ts | 8 +++--- src/core/__tests__/fetchPolicies.ts | 4 +-- .../batch-http/__tests__/batchHttpLink.ts | 3 +-- src/link/batch/__tests__/batchLink.ts | 2 +- src/link/context/__tests__/index.ts | 3 +-- src/link/core/__tests__/ApolloLink.ts | 2 +- src/link/error/__tests__/index.ts | 3 +-- src/link/http/__tests__/HttpLink.ts | 2 +- src/link/http/__tests__/responseIterator.ts | 3 +-- .../responseIteratorNoAsyncIterator.ts | 3 +-- .../__tests__/persisted-queries.test.ts | 3 +-- src/link/retry/__tests__/retryLink.ts | 3 +-- src/link/schema/__tests__/schemaLink.ts | 3 +-- src/link/ws/__tests__/webSocketLink.ts | 3 +-- src/masking/__tests__/maskFragment.test.ts | 2 +- src/masking/__tests__/maskOperation.test.ts | 2 +- .../__tests__/useBackgroundQuery.test.tsx | 26 +++++++++---------- .../hooks/__tests__/useFragment.test.tsx | 3 +-- .../hooks/__tests__/useLazyQuery.test.tsx | 9 +++---- .../hooks/__tests__/useLoadableQuery.test.tsx | 14 +++++----- .../hooks/__tests__/useMutation.test.tsx | 3 +-- src/react/hooks/__tests__/useQuery.test.tsx | 8 +++--- .../__tests__/useQueryRefHandlers.test.tsx | 14 +++++----- .../hooks/__tests__/useSubscription.test.tsx | 2 +- .../__tests__/useSuspenseFragment.test.tsx | 3 +-- .../hooks/__tests__/useSuspenseQuery.test.tsx | 18 ++++++------- .../cache/__tests__/QueryReference.test.tsx | 2 +- .../__tests__/createQueryPreloader.test.tsx | 6 ++--- .../ssr/__tests__/useReactiveVar.test.tsx | 3 +-- .../core/mocking/__tests__/mockLink.ts | 4 +-- .../__tests__/createTestSchema.test.tsx | 5 +++- src/testing/experimental/createSchemaFetch.ts | 3 +-- src/testing/matchers/toComplete.ts | 3 ++- src/testing/matchers/toEmitAnything.ts | 3 ++- .../matchers/toEmitApolloQueryResult.ts | 2 +- src/testing/matchers/toEmitError.ts | 3 ++- src/testing/matchers/toEmitFetchResult.ts | 2 +- src/testing/matchers/toEmitMatchedValue.ts | 3 ++- src/testing/matchers/toEmitNext.ts | 3 ++- src/testing/matchers/toEmitStrictTyped.ts | 3 ++- src/testing/matchers/toEmitValue.ts | 3 ++- src/testing/matchers/toEmitValueStrict.ts | 3 ++- src/utilities/graphql/__tests__/directives.ts | 3 +-- .../invariant/__tests__/invariant.test.ts | 3 +-- 65 files changed, 146 insertions(+), 151 deletions(-) diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 6716327df30..8428c46b973 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -19,11 +19,13 @@ import { ApolloLink } from "@apollo/client/link/core"; import { HttpLink } from "@apollo/client/link/http"; import { Masked } from "@apollo/client/masking"; import { MockLink } from "@apollo/client/testing"; +import { + ObservableStream, + spyOnConsole, +} from "@apollo/client/testing/internal"; import { DeepPartial } from "@apollo/client/utilities"; import { invariant } from "@apollo/client/utilities/invariant"; -import { ObservableStream, spyOnConsole } from "../testing/internal/index.js"; - describe("ApolloClient", () => { describe("constructor", () => { let oldFetch: any; diff --git a/src/__tests__/client.ts b/src/__tests__/client.ts index 173095046ed..42769fa7fa1 100644 --- a/src/__tests__/client.ts +++ b/src/__tests__/client.ts @@ -36,6 +36,10 @@ import { } from "@apollo/client/errors"; import { ApolloLink } from "@apollo/client/link/core"; import { MockLink, mockSingleLink, wait } from "@apollo/client/testing"; +import { + ObservableStream, + spyOnConsole, +} from "@apollo/client/testing/internal"; import { DocumentTransform, offsetLimitPagination, @@ -43,8 +47,6 @@ import { } from "@apollo/client/utilities"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { ObservableStream, spyOnConsole } from "../testing/internal/index.js"; - describe("client", () => { it("can be loaded via require", () => { /* tslint:disable */ diff --git a/src/__tests__/dataMasking.ts b/src/__tests__/dataMasking.ts index 7790848159a..7526cc7e680 100644 --- a/src/__tests__/dataMasking.ts +++ b/src/__tests__/dataMasking.ts @@ -25,11 +25,13 @@ import { MockSubscriptionLink, wait, } from "@apollo/client/testing"; +import { + ObservableStream, + spyOnConsole, +} from "@apollo/client/testing/internal"; import { isSubscriptionOperation } from "@apollo/client/utilities"; import { invariant } from "@apollo/client/utilities/invariant"; -import { ObservableStream, spyOnConsole } from "../testing/internal/index.js"; - const NO_CACHE_WARNING = '[%s]: Fragments masked by data masking are inaccessible when using fetch policy "no-cache". Please add `@unmask` to each fragment spread to access the data.'; diff --git a/src/__tests__/fetchMore.ts b/src/__tests__/fetchMore.ts index fc848f77f17..ee54ee4cb60 100644 --- a/src/__tests__/fetchMore.ts +++ b/src/__tests__/fetchMore.ts @@ -15,16 +15,15 @@ import { TypedDocumentNode, } from "@apollo/client/core"; import { MockedResponse, mockSingleLink } from "@apollo/client/testing"; +import { + ObservableStream, + setupPaginatedCase, +} from "@apollo/client/testing/internal"; import { concatPagination, offsetLimitPagination, } from "@apollo/client/utilities"; -import { - ObservableStream, - setupPaginatedCase, -} from "../testing/internal/index.js"; - describe("updateQuery on a simple query", () => { const query = gql` query thing { diff --git a/src/__tests__/graphqlSubscriptions.ts b/src/__tests__/graphqlSubscriptions.ts index 8481393038b..0183698df04 100644 --- a/src/__tests__/graphqlSubscriptions.ts +++ b/src/__tests__/graphqlSubscriptions.ts @@ -7,12 +7,11 @@ import { CombinedProtocolErrors, } from "@apollo/client/errors"; import { MockSubscriptionLink } from "@apollo/client/testing"; - import { mockMultipartSubscriptionStream, ObservableStream, spyOnConsole, -} from "../testing/internal/index.js"; +} from "@apollo/client/testing/internal"; describe("GraphQL Subscriptions", () => { const results = [ diff --git a/src/__tests__/local-state/export.ts b/src/__tests__/local-state/export.ts index 84be5ae0fcc..13d61ac5560 100644 --- a/src/__tests__/local-state/export.ts +++ b/src/__tests__/local-state/export.ts @@ -5,11 +5,10 @@ import { of } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; import { ApolloClient } from "@apollo/client/core"; import { ApolloLink } from "@apollo/client/link/core"; - import { ObservableStream, spyOnConsole, -} from "../../testing/internal/index.js"; +} from "@apollo/client/testing/internal"; describe("@client @export tests", () => { it("should not break @client only queries when the @export directive is used", async () => { diff --git a/src/__tests__/local-state/general.ts b/src/__tests__/local-state/general.ts index b89b00dc933..57fb46147c4 100644 --- a/src/__tests__/local-state/general.ts +++ b/src/__tests__/local-state/general.ts @@ -18,11 +18,10 @@ import { ApolloCache, InMemoryCache } from "@apollo/client/cache"; import { ApolloClient, NetworkStatus } from "@apollo/client/core"; import { CombinedGraphQLErrors } from "@apollo/client/errors"; import { ApolloLink, Operation } from "@apollo/client/link/core"; - import { ObservableStream, spyOnConsole, -} from "../../testing/internal/index.js"; +} from "@apollo/client/testing/internal"; describe("General functionality", () => { it("should not impact normal non-@client use", () => { diff --git a/src/__tests__/local-state/resolvers.ts b/src/__tests__/local-state/resolvers.ts index cbc966e56e7..96117b33ff4 100644 --- a/src/__tests__/local-state/resolvers.ts +++ b/src/__tests__/local-state/resolvers.ts @@ -11,9 +11,9 @@ import { } from "@apollo/client/core"; import { ApolloLink } from "@apollo/client/link/core"; import { MockLink } from "@apollo/client/testing"; +import { ObservableStream } from "@apollo/client/testing/internal"; import { LocalState } from "../../core/LocalState.js"; -import { ObservableStream } from "../../testing/internal/index.js"; const setupTestWithResolvers = ({ resolvers, diff --git a/src/__tests__/local-state/subscriptions.ts b/src/__tests__/local-state/subscriptions.ts index 3dac3ce8f22..fbf32e9549d 100644 --- a/src/__tests__/local-state/subscriptions.ts +++ b/src/__tests__/local-state/subscriptions.ts @@ -4,8 +4,7 @@ import { of } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; import { ApolloClient } from "@apollo/client/core"; import { ApolloLink } from "@apollo/client/link/core"; - -import { ObservableStream } from "../../testing/internal/index.js"; +import { ObservableStream } from "@apollo/client/testing/internal"; describe("Basic functionality", () => { it("should not break subscriptions", async () => { diff --git a/src/__tests__/mutationResults.ts b/src/__tests__/mutationResults.ts index 93b39687179..6e96278231c 100644 --- a/src/__tests__/mutationResults.ts +++ b/src/__tests__/mutationResults.ts @@ -8,8 +8,10 @@ import { ApolloClient, FetchResult } from "@apollo/client/core"; import { CombinedGraphQLErrors } from "@apollo/client/errors"; import { ApolloLink } from "@apollo/client/link/core"; import { MockedResponse, mockSingleLink } from "@apollo/client/testing"; - -import { ObservableStream, spyOnConsole } from "../testing/internal/index.js"; +import { + ObservableStream, + spyOnConsole, +} from "@apollo/client/testing/internal"; describe("mutation results", () => { const query = gql` diff --git a/src/__tests__/optimistic.ts b/src/__tests__/optimistic.ts index 084f15df711..6cfffab7c29 100644 --- a/src/__tests__/optimistic.ts +++ b/src/__tests__/optimistic.ts @@ -21,10 +21,9 @@ import { MockLink, mockSingleLink, } from "@apollo/client/testing"; +import { ObservableStream } from "@apollo/client/testing/internal"; import { addTypenameToDocument } from "@apollo/client/utilities"; -import { ObservableStream } from "../testing/internal/index.js"; - describe("optimistic mutation results", () => { const query = gql` query todoList { diff --git a/src/__tests__/refetchQueries.ts b/src/__tests__/refetchQueries.ts index 56a96ad93de..6f826f7f540 100644 --- a/src/__tests__/refetchQueries.ts +++ b/src/__tests__/refetchQueries.ts @@ -9,8 +9,7 @@ import { ObservableQuery, TypedDocumentNode, } from "@apollo/client/core"; - -import { ObservableStream } from "../testing/internal/index.js"; +import { ObservableStream } from "@apollo/client/testing/internal"; describe("client.refetchQueries", () => { it("is public and callable", async () => { diff --git a/src/__tests__/subscribeToMore.ts b/src/__tests__/subscribeToMore.ts index e8769061216..8d2f31d0962 100644 --- a/src/__tests__/subscribeToMore.ts +++ b/src/__tests__/subscribeToMore.ts @@ -9,8 +9,10 @@ import { mockSingleLink, wait, } from "@apollo/client/testing"; - -import { ObservableStream, spyOnConsole } from "../testing/internal/index.js"; +import { + ObservableStream, + spyOnConsole, +} from "@apollo/client/testing/internal"; const isSub = (operation: Operation) => (operation.query as DocumentNode).definitions diff --git a/src/cache/inmemory/__tests__/cache.ts b/src/cache/inmemory/__tests__/cache.ts index 254899069b3..6d0d652ed67 100644 --- a/src/cache/inmemory/__tests__/cache.ts +++ b/src/cache/inmemory/__tests__/cache.ts @@ -10,9 +10,9 @@ import { Reference, TypedDocumentNode, } from "@apollo/client/core"; +import { spyOnConsole } from "@apollo/client/testing/internal"; import { cloneDeep, defaultCacheSizes } from "@apollo/client/utilities"; -import { spyOnConsole } from "../../../testing/internal/index.js"; import { StoreReader } from "../readFromStore.js"; import { InMemoryCacheConfig } from "../types.js"; import { StoreWriter } from "../writeToStore.js"; diff --git a/src/cache/inmemory/__tests__/entityStore.ts b/src/cache/inmemory/__tests__/entityStore.ts index a26c4de80c7..0853744dd60 100644 --- a/src/cache/inmemory/__tests__/entityStore.ts +++ b/src/cache/inmemory/__tests__/entityStore.ts @@ -8,6 +8,7 @@ import { InMemoryCache, MissingFieldError, } from "@apollo/client/cache"; +import { spyOnConsole } from "@apollo/client/testing/internal"; import { isReference, makeReference, @@ -15,7 +16,6 @@ import { } from "@apollo/client/utilities"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { spyOnConsole } from "../../../testing/internal/index.js"; import { Reference, StoreValue, diff --git a/src/cache/inmemory/__tests__/fragmentRegistry.ts b/src/cache/inmemory/__tests__/fragmentRegistry.ts index 2093b06cbb1..73680008c5b 100644 --- a/src/cache/inmemory/__tests__/fragmentRegistry.ts +++ b/src/cache/inmemory/__tests__/fragmentRegistry.ts @@ -7,10 +7,9 @@ import { gql, NetworkStatus, } from "@apollo/client/core"; +import { ObservableStream } from "@apollo/client/testing/internal"; import { getFragmentDefinitions } from "@apollo/client/utilities"; -import { ObservableStream } from "../../../testing/internal/index.js"; - describe("FragmentRegistry", () => { it("can be passed to InMemoryCache", () => { const cache = new InMemoryCache({ diff --git a/src/cache/inmemory/__tests__/policies.ts b/src/cache/inmemory/__tests__/policies.ts index 3e9d7d83ab9..8e741429853 100644 --- a/src/cache/inmemory/__tests__/policies.ts +++ b/src/cache/inmemory/__tests__/policies.ts @@ -15,15 +15,15 @@ import { TypedDocumentNode, } from "@apollo/client/core"; import { MockLink } from "@apollo/client/testing/core"; +import { + ObservableStream, + spyOnConsole, +} from "@apollo/client/testing/internal"; import { relayStylePagination, stringifyForDisplay, } from "@apollo/client/utilities"; -import { - ObservableStream, - spyOnConsole, -} from "../../../testing/internal/index.js"; import { FieldPolicy, StorageType } from "../policies.js"; import { ReactiveVar } from "../reactiveVars.js"; diff --git a/src/cache/inmemory/__tests__/roundtrip.ts b/src/cache/inmemory/__tests__/roundtrip.ts index 9544e583de1..774fa2a2813 100644 --- a/src/cache/inmemory/__tests__/roundtrip.ts +++ b/src/cache/inmemory/__tests__/roundtrip.ts @@ -2,9 +2,9 @@ import { DocumentNode } from "graphql"; import { gql } from "graphql-tag"; import { EntityStore, InMemoryCache } from "@apollo/client/cache"; +import { spyOnConsole } from "@apollo/client/testing/internal"; import { __DEV__ } from "@apollo/client/utilities/environment"; -import { spyOnConsole } from "../../../testing/internal/index.js"; import { StoreReader } from "../readFromStore.js"; import { StoreWriter } from "../writeToStore.js"; diff --git a/src/cache/inmemory/__tests__/writeToStore.ts b/src/cache/inmemory/__tests__/writeToStore.ts index 5714fa100d7..0d4d91a4ca3 100644 --- a/src/cache/inmemory/__tests__/writeToStore.ts +++ b/src/cache/inmemory/__tests__/writeToStore.ts @@ -11,6 +11,7 @@ import { assign, omit } from "lodash"; import { InMemoryCache } from "@apollo/client/cache"; import { TypedDocumentNode } from "@apollo/client/core"; +import { spyOnConsole } from "@apollo/client/testing/internal"; import { addTypenameToDocument, cloneDeep, @@ -23,7 +24,6 @@ import { } from "@apollo/client/utilities"; import { invariant } from "@apollo/client/utilities/invariant"; -import { spyOnConsole } from "../../../testing/internal/index.js"; import { extractFragmentContext } from "../helpers.js"; import { KeyFieldsFunction } from "../policies.js"; import { StoreWriter } from "../writeToStore.js"; diff --git a/src/core/__tests__/ApolloClient/general.test.ts b/src/core/__tests__/ApolloClient/general.test.ts index 96aba2063e5..f1da43efc23 100644 --- a/src/core/__tests__/ApolloClient/general.test.ts +++ b/src/core/__tests__/ApolloClient/general.test.ts @@ -16,6 +16,11 @@ import { type RequestHandler, } from "@apollo/client/link/core"; import { wait } from "@apollo/client/testing/core"; +import { + mockDeferStream, + ObservableStream, + spyOnConsole, +} from "@apollo/client/testing/internal"; import { addTypenameToDocument, print } from "@apollo/client/utilities"; import { InvariantError, @@ -26,11 +31,6 @@ import { MockApolloLink, MockLink, } from "../../../testing/core/mocking/mockLink.js"; -import { - mockDeferStream, - ObservableStream, - spyOnConsole, -} from "../../../testing/internal/index.js"; import { QueryManager } from "../../QueryManager.js"; import { WatchQueryFetchPolicy, diff --git a/src/core/__tests__/ApolloClient/multiple-results.test.ts b/src/core/__tests__/ApolloClient/multiple-results.test.ts index f5780fcce44..f20e5673909 100644 --- a/src/core/__tests__/ApolloClient/multiple-results.test.ts +++ b/src/core/__tests__/ApolloClient/multiple-results.test.ts @@ -4,8 +4,7 @@ import { gql } from "graphql-tag"; import { InMemoryCache } from "@apollo/client/cache"; import { ApolloClient, NetworkStatus } from "@apollo/client/core"; import { MockSubscriptionLink, wait } from "@apollo/client/testing/core"; - -import { ObservableStream } from "../../../testing/internal/index.js"; +import { ObservableStream } from "@apollo/client/testing/internal"; describe("mutiple results", () => { it("allows multiple query results from link", async () => { diff --git a/src/core/__tests__/ObservableQuery.ts b/src/core/__tests__/ObservableQuery.ts index 77de556192e..cbdc4e86993 100644 --- a/src/core/__tests__/ObservableQuery.ts +++ b/src/core/__tests__/ObservableQuery.ts @@ -21,16 +21,16 @@ import { tick, wait, } from "@apollo/client/testing"; +import { + ObservableStream, + spyOnConsole, +} from "@apollo/client/testing/internal"; import { DeepPartial, DocumentTransform, removeDirectivesFromDocument, } from "@apollo/client/utilities"; -import { - ObservableStream, - spyOnConsole, -} from "../../testing/internal/index.js"; import type { ObservableAndInfo } from "../QueryManager.js"; import { QueryManager } from "../QueryManager.js"; diff --git a/src/core/__tests__/fetchPolicies.ts b/src/core/__tests__/fetchPolicies.ts index ce3161959ff..561790da82b 100644 --- a/src/core/__tests__/fetchPolicies.ts +++ b/src/core/__tests__/fetchPolicies.ts @@ -10,11 +10,11 @@ import { } from "@apollo/client/core"; import { ApolloLink } from "@apollo/client/link/core"; import { mockSingleLink } from "@apollo/client/testing"; - import { ObservableStream, spyOnConsole, -} from "../../testing/internal/index.js"; +} from "@apollo/client/testing/internal"; + import { ApolloQueryResult } from "../types.js"; import { WatchQueryFetchPolicy, diff --git a/src/link/batch-http/__tests__/batchHttpLink.ts b/src/link/batch-http/__tests__/batchHttpLink.ts index 7a3bff02704..e03761c3ef1 100644 --- a/src/link/batch-http/__tests__/batchHttpLink.ts +++ b/src/link/batch-http/__tests__/batchHttpLink.ts @@ -5,8 +5,7 @@ import { map, Observable, Observer, Subscription } from "rxjs"; import { BatchHttpLink } from "@apollo/client/link/batch-http"; import { ApolloLink, execute, FetchResult } from "@apollo/client/link/core"; - -import { ObservableStream } from "../../../testing/internal/index.js"; +import { ObservableStream } from "@apollo/client/testing/internal"; const sampleQuery = gql` query SampleQuery { diff --git a/src/link/batch/__tests__/batchLink.ts b/src/link/batch/__tests__/batchLink.ts index 0573de31612..d1404a11dce 100644 --- a/src/link/batch/__tests__/batchLink.ts +++ b/src/link/batch/__tests__/batchLink.ts @@ -5,8 +5,8 @@ import { EMPTY, map, Observable, of } from "rxjs"; import { BatchLink, OperationBatcher } from "@apollo/client/link/batch"; import { ApolloLink, execute } from "@apollo/client/link/core"; import { wait } from "@apollo/client/testing"; +import { ObservableStream } from "@apollo/client/testing/internal"; -import { ObservableStream } from "../../../testing/internal/index.js"; import { FetchResult, GraphQLRequest, Operation } from "../../core/types.js"; import { BatchableRequest, BatchHandler } from "../batchLink.js"; diff --git a/src/link/context/__tests__/index.ts b/src/link/context/__tests__/index.ts index a6d76d697b1..960d7564d6a 100644 --- a/src/link/context/__tests__/index.ts +++ b/src/link/context/__tests__/index.ts @@ -4,8 +4,7 @@ import { Observable, of } from "rxjs"; import { setContext } from "@apollo/client/link/context"; import { ApolloLink, execute } from "@apollo/client/link/core"; import { wait } from "@apollo/client/testing"; - -import { ObservableStream } from "../../../testing/internal/index.js"; +import { ObservableStream } from "@apollo/client/testing/internal"; const sleep = (ms: number) => new Promise((s) => setTimeout(s, ms)); const query = gql` diff --git a/src/link/core/__tests__/ApolloLink.ts b/src/link/core/__tests__/ApolloLink.ts index 49b2d566657..ff451f66895 100644 --- a/src/link/core/__tests__/ApolloLink.ts +++ b/src/link/core/__tests__/ApolloLink.ts @@ -3,8 +3,8 @@ import { gql } from "graphql-tag"; import { EMPTY, map, Observable, of } from "rxjs"; import { ApolloLink, execute } from "@apollo/client/link/core"; +import { ObservableStream } from "@apollo/client/testing/internal"; -import { ObservableStream } from "../../../testing/internal/index.js"; import { FetchResult, GraphQLRequest, NextLink, Operation } from "../types.js"; class SetContextLink extends ApolloLink { diff --git a/src/link/error/__tests__/index.ts b/src/link/error/__tests__/index.ts index 4d946403392..745baabef09 100644 --- a/src/link/error/__tests__/index.ts +++ b/src/link/error/__tests__/index.ts @@ -8,12 +8,11 @@ import { } from "@apollo/client/errors"; import { ApolloLink, execute } from "@apollo/client/link/core"; import { ErrorLink, onError } from "@apollo/client/link/error"; - import { mockDeferStream, mockMultipartSubscriptionStream, ObservableStream, -} from "../../../testing/internal/index.js"; +} from "@apollo/client/testing/internal"; describe("error handling", () => { it("has an easy way to handle GraphQL errors", async () => { diff --git a/src/link/http/__tests__/HttpLink.ts b/src/link/http/__tests__/HttpLink.ts index d50eba04bd9..c5159a4c401 100644 --- a/src/link/http/__tests__/HttpLink.ts +++ b/src/link/http/__tests__/HttpLink.ts @@ -15,8 +15,8 @@ import { import { ApolloLink, execute } from "@apollo/client/link/core"; import { createHttpLink, HttpLink } from "@apollo/client/link/http"; import { wait } from "@apollo/client/testing"; +import { ObservableStream } from "@apollo/client/testing/internal"; -import { ObservableStream } from "../../../testing/internal/index.js"; import { ClientParseError } from "../serializeFetchParameter.js"; import { voidFetchDuringEachTest } from "./helpers.js"; diff --git a/src/link/http/__tests__/responseIterator.ts b/src/link/http/__tests__/responseIterator.ts index 236301c7650..01e9b53113d 100644 --- a/src/link/http/__tests__/responseIterator.ts +++ b/src/link/http/__tests__/responseIterator.ts @@ -6,10 +6,9 @@ import { ReadableStream } from "web-streams-polyfill"; import { execute } from "@apollo/client/link/core"; import { HttpLink } from "@apollo/client/link/http"; +import { ObservableStream } from "@apollo/client/testing/internal"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { ObservableStream } from "../../../testing/internal/index.js"; - const sampleDeferredQuery = gql` query SampleDeferredQuery { stub { diff --git a/src/link/http/__tests__/responseIteratorNoAsyncIterator.ts b/src/link/http/__tests__/responseIteratorNoAsyncIterator.ts index 721b207abd9..f5263b60f27 100644 --- a/src/link/http/__tests__/responseIteratorNoAsyncIterator.ts +++ b/src/link/http/__tests__/responseIteratorNoAsyncIterator.ts @@ -5,8 +5,7 @@ import { ReadableStream } from "web-streams-polyfill"; import { execute } from "@apollo/client/link/core"; import { HttpLink } from "@apollo/client/link/http"; - -import { ObservableStream } from "../../../testing/internal/index.js"; +import { ObservableStream } from "@apollo/client/testing/internal"; const sampleDeferredQuery = gql` query SampleDeferredQuery { diff --git a/src/link/persisted-queries/__tests__/persisted-queries.test.ts b/src/link/persisted-queries/__tests__/persisted-queries.test.ts index f171481d956..3b356a5dfd8 100644 --- a/src/link/persisted-queries/__tests__/persisted-queries.test.ts +++ b/src/link/persisted-queries/__tests__/persisted-queries.test.ts @@ -13,8 +13,7 @@ import { VERSION, } from "@apollo/client/link/persisted-queries"; import { wait } from "@apollo/client/testing"; - -import { ObservableStream } from "../../../testing/internal/index.js"; +import { ObservableStream } from "@apollo/client/testing/internal"; // Necessary configuration in order to mock multiple requests // to a single (/graphql) endpoint diff --git a/src/link/retry/__tests__/retryLink.ts b/src/link/retry/__tests__/retryLink.ts index 3b1b23a3fa8..72fb7f2f73a 100644 --- a/src/link/retry/__tests__/retryLink.ts +++ b/src/link/retry/__tests__/retryLink.ts @@ -4,11 +4,10 @@ import { Observable, of, throwError } from "rxjs"; import { CombinedProtocolErrors } from "@apollo/client/core"; import { ApolloLink, execute } from "@apollo/client/link/core"; import { RetryLink } from "@apollo/client/link/retry"; - import { mockMultipartSubscriptionStream, ObservableStream, -} from "../../../testing/internal/index.js"; +} from "@apollo/client/testing/internal"; const query = gql` { diff --git a/src/link/schema/__tests__/schemaLink.ts b/src/link/schema/__tests__/schemaLink.ts index b9b47d600f0..65f357248df 100644 --- a/src/link/schema/__tests__/schemaLink.ts +++ b/src/link/schema/__tests__/schemaLink.ts @@ -3,8 +3,7 @@ import { gql } from "graphql-tag"; import { execute } from "@apollo/client/link/core"; import { SchemaLink } from "@apollo/client/link/schema"; - -import { ObservableStream } from "../../../testing/internal/index.js"; +import { ObservableStream } from "@apollo/client/testing/internal"; const sampleQuery = gql` query SampleQuery { diff --git a/src/link/ws/__tests__/webSocketLink.ts b/src/link/ws/__tests__/webSocketLink.ts index 3bf5aeb2430..38c3f7c432a 100644 --- a/src/link/ws/__tests__/webSocketLink.ts +++ b/src/link/ws/__tests__/webSocketLink.ts @@ -5,8 +5,7 @@ import { SubscriptionClient } from "subscriptions-transport-ws"; import { execute } from "@apollo/client/link/core"; import { WebSocketLink } from "@apollo/client/link/ws"; - -import { ObservableStream } from "../../../testing/internal/index.js"; +import { ObservableStream } from "@apollo/client/testing/internal"; const query = gql` query SampleQuery { diff --git a/src/masking/__tests__/maskFragment.test.ts b/src/masking/__tests__/maskFragment.test.ts index dd182746839..27c42b298ef 100644 --- a/src/masking/__tests__/maskFragment.test.ts +++ b/src/masking/__tests__/maskFragment.test.ts @@ -1,8 +1,8 @@ import { gql, InMemoryCache } from "@apollo/client/core"; import { maskFragment } from "@apollo/client/masking"; +import { spyOnConsole } from "@apollo/client/testing/internal"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { spyOnConsole } from "../../testing/internal/index.js"; import { deepFreeze } from "../../utilities/common/maybeDeepFreeze.js"; test("returns null when data is null", () => { diff --git a/src/masking/__tests__/maskOperation.test.ts b/src/masking/__tests__/maskOperation.test.ts index 7bc714a1663..ca00b753116 100644 --- a/src/masking/__tests__/maskOperation.test.ts +++ b/src/masking/__tests__/maskOperation.test.ts @@ -1,9 +1,9 @@ import { gql, InMemoryCache } from "@apollo/client/core"; import { maskOperation } from "@apollo/client/masking"; +import { spyOnConsole, withProdMode } from "@apollo/client/testing/internal"; import { __DEV__ } from "@apollo/client/utilities/environment"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { spyOnConsole, withProdMode } from "../../testing/internal/index.js"; import { deepFreeze } from "../../utilities/common/maybeDeepFreeze.js"; test("throws when passing document with no operation to maskOperation", () => { diff --git a/src/react/hooks/__tests__/useBackgroundQuery.test.tsx b/src/react/hooks/__tests__/useBackgroundQuery.test.tsx index 8e3f58a8d82..6999abe072c 100644 --- a/src/react/hooks/__tests__/useBackgroundQuery.test.tsx +++ b/src/react/hooks/__tests__/useBackgroundQuery.test.tsx @@ -42,6 +42,19 @@ import { MockSubscriptionLink, wait, } from "@apollo/client/testing"; +import { + addDelayToMocks, + createClientWrapper, + createMockWrapper, + PaginatedCaseData, + setupPaginatedCase, + setupSimpleCase, + setupVariablesCase, + SimpleCaseData, + spyOnConsole, + VariablesCaseData, + VariablesCaseVariables, +} from "@apollo/client/testing/internal"; import { MockedProvider } from "@apollo/client/testing/react"; import { concatPagination, @@ -55,19 +68,6 @@ import { SubscribeToMoreFunction, SubscribeToMoreOptions, } from "../../../core/watchQueryOptions.js"; -import { - addDelayToMocks, - createClientWrapper, - createMockWrapper, - PaginatedCaseData, - setupPaginatedCase, - setupSimpleCase, - setupVariablesCase, - SimpleCaseData, - spyOnConsole, - VariablesCaseData, - VariablesCaseVariables, -} from "../../../testing/internal/index.js"; import { MaskedVariablesCaseData, setupMaskedVariablesCase, diff --git a/src/react/hooks/__tests__/useFragment.test.tsx b/src/react/hooks/__tests__/useFragment.test.tsx index d9bca647c49..a89bc3bcdee 100644 --- a/src/react/hooks/__tests__/useFragment.test.tsx +++ b/src/react/hooks/__tests__/useFragment.test.tsx @@ -33,11 +33,10 @@ import { import { FragmentType } from "@apollo/client/masking"; import { ApolloProvider } from "@apollo/client/react/context"; import { useFragment, useQuery } from "@apollo/client/react/hooks"; +import { spyOnConsole } from "@apollo/client/testing/internal"; import { MockedProvider } from "@apollo/client/testing/react"; import { concatPagination } from "@apollo/client/utilities"; -import { spyOnConsole } from "../../../testing/internal/index.js"; - describe("useFragment", () => { it("is importable and callable", () => { expect(typeof useFragment).toBe("function"); diff --git a/src/react/hooks/__tests__/useLazyQuery.test.tsx b/src/react/hooks/__tests__/useLazyQuery.test.tsx index 8e3e7513b58..69f9cfae92d 100644 --- a/src/react/hooks/__tests__/useLazyQuery.test.tsx +++ b/src/react/hooks/__tests__/useLazyQuery.test.tsx @@ -32,17 +32,16 @@ import { MockSubscriptionLink, wait, } from "@apollo/client/testing"; -import { MockedProvider } from "@apollo/client/testing/react"; -import { DeepPartial } from "@apollo/client/utilities"; -import { InvariantError } from "@apollo/client/utilities/invariant"; - import { renderAsync, setupSimpleCase, setupVariablesCase, spyOnConsole, VariablesCaseVariables, -} from "../../../testing/internal/index.js"; +} from "@apollo/client/testing/internal"; +import { MockedProvider } from "@apollo/client/testing/react"; +import { DeepPartial } from "@apollo/client/utilities"; +import { InvariantError } from "@apollo/client/utilities/invariant"; describe("useLazyQuery Hook", () => { const helloQuery: TypedDocumentNode<{ diff --git a/src/react/hooks/__tests__/useLoadableQuery.test.tsx b/src/react/hooks/__tests__/useLoadableQuery.test.tsx index 809cf9777c1..36ae1b15a47 100644 --- a/src/react/hooks/__tests__/useLoadableQuery.test.tsx +++ b/src/react/hooks/__tests__/useLoadableQuery.test.tsx @@ -36,6 +36,13 @@ import { MockSubscriptionLink, wait, } from "@apollo/client/testing"; +import { + renderAsync, + setupPaginatedCase, + setupSimpleCase, + SimpleCaseData, + spyOnConsole, +} from "@apollo/client/testing/internal"; import { MockedProvider, MockedProviderProps, @@ -49,13 +56,6 @@ import { import { invariant, InvariantError } from "@apollo/client/utilities/invariant"; import { SubscribeToMoreFunction } from "../../../core/watchQueryOptions.js"; -import { - renderAsync, - setupPaginatedCase, - setupSimpleCase, - SimpleCaseData, - spyOnConsole, -} from "../../../testing/internal/index.js"; import { FetchMoreFunction, RefetchFunction } from "../../internal/types.js"; const IS_REACT_19 = React.version.startsWith("19"); diff --git a/src/react/hooks/__tests__/useMutation.test.tsx b/src/react/hooks/__tests__/useMutation.test.tsx index 64b4f9aec6b..9043cadb2ba 100644 --- a/src/react/hooks/__tests__/useMutation.test.tsx +++ b/src/react/hooks/__tests__/useMutation.test.tsx @@ -40,11 +40,10 @@ import { mockSingleLink, MockSubscriptionLink, } from "@apollo/client/testing"; +import { spyOnConsole } from "@apollo/client/testing/internal"; import { MockedProvider } from "@apollo/client/testing/react"; import { invariant } from "@apollo/client/utilities/invariant"; -import { spyOnConsole } from "../../../testing/internal/index.js"; - const IS_REACT_17 = React.version.startsWith("17"); const IS_REACT_18 = React.version.startsWith("18"); const IS_REACT_19 = React.version.startsWith("19"); diff --git a/src/react/hooks/__tests__/useQuery.test.tsx b/src/react/hooks/__tests__/useQuery.test.tsx index 8b00eb05fd8..7d08828ea2d 100644 --- a/src/react/hooks/__tests__/useQuery.test.tsx +++ b/src/react/hooks/__tests__/useQuery.test.tsx @@ -43,15 +43,15 @@ import { tick, wait, } from "@apollo/client/testing"; +import { + setupPaginatedCase, + spyOnConsole, +} from "@apollo/client/testing/internal"; import { MockedProvider } from "@apollo/client/testing/react"; import { concatPagination, Reference } from "@apollo/client/utilities"; import { InvariantError } from "@apollo/client/utilities/invariant"; import { mockFetchQuery } from "../../../core/__tests__/ObservableQuery.js"; -import { - setupPaginatedCase, - spyOnConsole, -} from "../../../testing/internal/index.js"; const IS_REACT_17 = React.version.startsWith("17"); const IS_REACT_18 = React.version.startsWith("18"); diff --git a/src/react/hooks/__tests__/useQueryRefHandlers.test.tsx b/src/react/hooks/__tests__/useQueryRefHandlers.test.tsx index eb9c8a95c7f..8f7e3743c01 100644 --- a/src/react/hooks/__tests__/useQueryRefHandlers.test.tsx +++ b/src/react/hooks/__tests__/useQueryRefHandlers.test.tsx @@ -28,19 +28,19 @@ import { MockLink, MockSubscriptionLink, } from "@apollo/client/testing"; -import { concatPagination, getMainDefinition } from "@apollo/client/utilities"; - -import { - SubscribeToMoreFunction, - SubscribeToMoreUpdateQueryFn, -} from "../../../core/watchQueryOptions.js"; import { createClientWrapper, PaginatedCaseData, setupPaginatedCase, setupSimpleCase, SimpleCaseData, -} from "../../../testing/internal/index.js"; +} from "@apollo/client/testing/internal"; +import { concatPagination, getMainDefinition } from "@apollo/client/utilities"; + +import { + SubscribeToMoreFunction, + SubscribeToMoreUpdateQueryFn, +} from "../../../core/watchQueryOptions.js"; test("does not interfere with updates from useReadQuery", async () => { const { query, mocks } = setupSimpleCase(); diff --git a/src/react/hooks/__tests__/useSubscription.test.tsx b/src/react/hooks/__tests__/useSubscription.test.tsx index 7f2cb599a6e..f8fee49c81f 100644 --- a/src/react/hooks/__tests__/useSubscription.test.tsx +++ b/src/react/hooks/__tests__/useSubscription.test.tsx @@ -24,10 +24,10 @@ import { Masked, MaskedDocumentNode } from "@apollo/client/masking"; import { ApolloProvider } from "@apollo/client/react/context"; import { useSubscription } from "@apollo/client/react/hooks"; import { MockSubscriptionLink, tick, wait } from "@apollo/client/testing"; +import { mockMultipartSubscriptionStream } from "@apollo/client/testing/internal"; import { InvariantError } from "@apollo/client/utilities/invariant"; import { MockedSubscriptionResult } from "../../../testing/core/mocking/mockSubscriptionLink.js"; -import { mockMultipartSubscriptionStream } from "../../../testing/internal/index.js"; const IS_REACT_17 = React.version.startsWith("17"); diff --git a/src/react/hooks/__tests__/useSuspenseFragment.test.tsx b/src/react/hooks/__tests__/useSuspenseFragment.test.tsx index 6dd1d4ab735..c8e80192e74 100644 --- a/src/react/hooks/__tests__/useSuspenseFragment.test.tsx +++ b/src/react/hooks/__tests__/useSuspenseFragment.test.tsx @@ -23,11 +23,10 @@ import { import { ApolloProvider } from "@apollo/client/react/context"; import { useSuspenseFragment } from "@apollo/client/react/hooks"; import { MockSubscriptionLink, wait } from "@apollo/client/testing"; +import { renderAsync, spyOnConsole } from "@apollo/client/testing/internal"; import { MockedProvider } from "@apollo/client/testing/react"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { renderAsync, spyOnConsole } from "../../../testing/internal/index.js"; - function createDefaultRenderStream() { return createRenderStream({ initialSnapshot: { diff --git a/src/react/hooks/__tests__/useSuspenseQuery.test.tsx b/src/react/hooks/__tests__/useSuspenseQuery.test.tsx index d34d0c548c7..610be1e62b6 100644 --- a/src/react/hooks/__tests__/useSuspenseQuery.test.tsx +++ b/src/react/hooks/__tests__/useSuspenseQuery.test.tsx @@ -43,6 +43,15 @@ import { MockLink, MockSubscriptionLink, } from "@apollo/client/testing"; +import { + actAsync, + PaginatedCaseData, + PaginatedCaseVariables, + renderAsync, + renderHookAsync, + setupPaginatedCase, + spyOnConsole, +} from "@apollo/client/testing/internal"; import { MockedProvider } from "@apollo/client/testing/react"; import { compact, @@ -57,15 +66,6 @@ import { RefetchWritePolicy, WatchQueryFetchPolicy, } from "../../../core/watchQueryOptions.js"; -import { - actAsync, - PaginatedCaseData, - PaginatedCaseVariables, - renderAsync, - renderHookAsync, - setupPaginatedCase, - spyOnConsole, -} from "../../../testing/internal/index.js"; const IS_REACT_19 = React.version.startsWith("19"); diff --git a/src/react/internal/cache/__tests__/QueryReference.test.tsx b/src/react/internal/cache/__tests__/QueryReference.test.tsx index a846e749fda..cc54ba471da 100644 --- a/src/react/internal/cache/__tests__/QueryReference.test.tsx +++ b/src/react/internal/cache/__tests__/QueryReference.test.tsx @@ -3,8 +3,8 @@ import { of } from "rxjs"; import { ApolloClient, ApolloLink, InMemoryCache } from "@apollo/client/core"; import { InternalQueryReference } from "@apollo/client/react/internal"; +import { setupSimpleCase } from "@apollo/client/testing/internal"; -import { setupSimpleCase } from "../../../../testing/internal/index.js"; import { PreloadedQueryRef, QueryRef, diff --git a/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx b/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx index 1c794a86277..7d20027613f 100644 --- a/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx +++ b/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx @@ -36,8 +36,6 @@ import { MockSubscriptionLink, wait, } from "@apollo/client/testing"; -import { DeepPartial } from "@apollo/client/utilities"; - import { createClientWrapper, renderHookAsync, @@ -46,7 +44,9 @@ import { SimpleCaseData, spyOnConsole, VariablesCaseData, -} from "../../../testing/internal/index.js"; +} from "@apollo/client/testing/internal"; +import { DeepPartial } from "@apollo/client/utilities"; + import { MaskedVariablesCaseData, setupMaskedVariablesCase, diff --git a/src/react/ssr/__tests__/useReactiveVar.test.tsx b/src/react/ssr/__tests__/useReactiveVar.test.tsx index b1d7fed6d92..c6b2528cae3 100644 --- a/src/react/ssr/__tests__/useReactiveVar.test.tsx +++ b/src/react/ssr/__tests__/useReactiveVar.test.tsx @@ -4,8 +4,7 @@ import React from "react"; import { makeVar } from "@apollo/client/core"; import { useReactiveVar } from "@apollo/client/react/hooks"; import { renderToStringWithData } from "@apollo/client/react/ssr"; - -import { spyOnConsole } from "../../../testing/internal/index.js"; +import { spyOnConsole } from "@apollo/client/testing/internal"; describe("useReactiveVar Hook SSR", () => { it("does not cause warnings", async () => { diff --git a/src/testing/core/mocking/__tests__/mockLink.ts b/src/testing/core/mocking/__tests__/mockLink.ts index 7bb6dd61eb5..99d94e54c01 100644 --- a/src/testing/core/mocking/__tests__/mockLink.ts +++ b/src/testing/core/mocking/__tests__/mockLink.ts @@ -1,12 +1,12 @@ import { gql } from "graphql-tag"; import { execute } from "@apollo/client/link/core"; - import { enableFakeTimers, ObservableStream, spyOnConsole, -} from "../../../internal/index.js"; +} from "@apollo/client/testing/internal"; + import { MockedResponse, MockLink } from "../mockLink.js"; describe("MockedResponse.newData", () => { diff --git a/src/testing/experimental/__tests__/createTestSchema.test.tsx b/src/testing/experimental/__tests__/createTestSchema.test.tsx index 29a154e5f24..a79f11eeedb 100644 --- a/src/testing/experimental/__tests__/createTestSchema.test.tsx +++ b/src/testing/experimental/__tests__/createTestSchema.test.tsx @@ -21,9 +21,12 @@ import { } from "@apollo/client/core"; import type { UseSuspenseQueryResult } from "@apollo/client/react"; import { useMutation, useSuspenseQuery } from "@apollo/client/react"; +import { + createClientWrapper, + spyOnConsole, +} from "@apollo/client/testing/internal"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { createClientWrapper, spyOnConsole } from "../../internal/index.js"; import { createSchemaFetch } from "../createSchemaFetch.js"; import { createTestSchema } from "../createTestSchema.js"; diff --git a/src/testing/experimental/createSchemaFetch.ts b/src/testing/experimental/createSchemaFetch.ts index e494d93f7ed..1421c8644f7 100644 --- a/src/testing/experimental/createSchemaFetch.ts +++ b/src/testing/experimental/createSchemaFetch.ts @@ -3,8 +3,7 @@ import { execute, GraphQLError, validate } from "graphql"; import { gql } from "@apollo/client/core"; import { wait } from "@apollo/client/testing"; - -import { withCleanup } from "../internal/index.js"; +import { withCleanup } from "@apollo/client/testing/internal"; /** * A function that accepts a static `schema` and a `mockFetchOpts` object and diff --git a/src/testing/matchers/toComplete.ts b/src/testing/matchers/toComplete.ts index e7fc6118ec9..15503fee9ad 100644 --- a/src/testing/matchers/toComplete.ts +++ b/src/testing/matchers/toComplete.ts @@ -1,6 +1,7 @@ import type { MatcherFunction } from "expect"; -import type { ObservableStream } from "../internal/index.js"; +import type { ObservableStream } from "@apollo/client/testing/internal"; + import type { TakeOptions } from "../internal/ObservableStream.js"; export const toComplete: MatcherFunction<[options?: TakeOptions]> = diff --git a/src/testing/matchers/toEmitAnything.ts b/src/testing/matchers/toEmitAnything.ts index 1676b4c4b64..7761449ae41 100644 --- a/src/testing/matchers/toEmitAnything.ts +++ b/src/testing/matchers/toEmitAnything.ts @@ -1,6 +1,7 @@ import type { MatcherFunction } from "expect"; -import type { ObservableStream } from "../internal/index.js"; +import type { ObservableStream } from "@apollo/client/testing/internal"; + import type { TakeOptions } from "../internal/ObservableStream.js"; export const toEmitAnything: MatcherFunction<[options?: TakeOptions]> = diff --git a/src/testing/matchers/toEmitApolloQueryResult.ts b/src/testing/matchers/toEmitApolloQueryResult.ts index 905472e481a..6675a7d7f6d 100644 --- a/src/testing/matchers/toEmitApolloQueryResult.ts +++ b/src/testing/matchers/toEmitApolloQueryResult.ts @@ -2,8 +2,8 @@ import { iterableEquality } from "@jest/expect-utils"; import type { MatcherFunction } from "expect"; import type { ApolloQueryResult } from "@apollo/client/core"; +import type { ObservableStream } from "@apollo/client/testing/internal"; -import type { ObservableStream } from "../internal/index.js"; import type { TakeOptions } from "../internal/ObservableStream.js"; export const toEmitApolloQueryResult: MatcherFunction< diff --git a/src/testing/matchers/toEmitError.ts b/src/testing/matchers/toEmitError.ts index 7c915149753..da44274e045 100644 --- a/src/testing/matchers/toEmitError.ts +++ b/src/testing/matchers/toEmitError.ts @@ -1,6 +1,7 @@ import type { MatcherContext, MatcherFunction } from "expect"; -import type { ObservableStream } from "../internal/index.js"; +import type { ObservableStream } from "@apollo/client/testing/internal"; + import type { TakeOptions } from "../internal/ObservableStream.js"; function isErrorEqual(this: MatcherContext, expected: any, actual: any) { diff --git a/src/testing/matchers/toEmitFetchResult.ts b/src/testing/matchers/toEmitFetchResult.ts index af1e4f5d82e..cf4bc05d237 100644 --- a/src/testing/matchers/toEmitFetchResult.ts +++ b/src/testing/matchers/toEmitFetchResult.ts @@ -2,8 +2,8 @@ import { iterableEquality } from "@jest/expect-utils"; import type { MatcherFunction } from "expect"; import type { FetchResult } from "@apollo/client/core"; +import type { ObservableStream } from "@apollo/client/testing/internal"; -import type { ObservableStream } from "../internal/index.js"; import type { TakeOptions } from "../internal/ObservableStream.js"; export const toEmitFetchResult: MatcherFunction< diff --git a/src/testing/matchers/toEmitMatchedValue.ts b/src/testing/matchers/toEmitMatchedValue.ts index 01dce8db893..aa19f19d784 100644 --- a/src/testing/matchers/toEmitMatchedValue.ts +++ b/src/testing/matchers/toEmitMatchedValue.ts @@ -5,7 +5,8 @@ import { } from "@jest/expect-utils"; import type { MatcherFunction } from "expect"; -import type { ObservableStream } from "../internal/index.js"; +import type { ObservableStream } from "@apollo/client/testing/internal"; + import type { TakeOptions } from "../internal/ObservableStream.js"; export const toEmitMatchedValue: MatcherFunction< diff --git a/src/testing/matchers/toEmitNext.ts b/src/testing/matchers/toEmitNext.ts index 7d51cf28004..37b591dba8a 100644 --- a/src/testing/matchers/toEmitNext.ts +++ b/src/testing/matchers/toEmitNext.ts @@ -1,6 +1,7 @@ import type { MatcherFunction } from "expect"; -import type { ObservableStream } from "../internal/index.js"; +import type { ObservableStream } from "@apollo/client/testing/internal"; + import type { TakeOptions } from "../internal/ObservableStream.js"; export const toEmitNext: MatcherFunction<[options?: TakeOptions]> = diff --git a/src/testing/matchers/toEmitStrictTyped.ts b/src/testing/matchers/toEmitStrictTyped.ts index 21a214a9ae7..8b8218e7a39 100644 --- a/src/testing/matchers/toEmitStrictTyped.ts +++ b/src/testing/matchers/toEmitStrictTyped.ts @@ -1,7 +1,8 @@ import { iterableEquality } from "@jest/expect-utils"; import type { MatcherFunction } from "expect"; -import type { ObservableStream } from "../internal/index.js"; +import type { ObservableStream } from "@apollo/client/testing/internal"; + import type { TakeOptions } from "../internal/ObservableStream.js"; import { getSerializableProperties } from "./utils/getSerializableProperties.js"; diff --git a/src/testing/matchers/toEmitValue.ts b/src/testing/matchers/toEmitValue.ts index 2443116975f..e59760b9d1b 100644 --- a/src/testing/matchers/toEmitValue.ts +++ b/src/testing/matchers/toEmitValue.ts @@ -1,7 +1,8 @@ import { iterableEquality } from "@jest/expect-utils"; import type { MatcherFunction } from "expect"; -import type { ObservableStream } from "../internal/index.js"; +import type { ObservableStream } from "@apollo/client/testing/internal"; + import type { TakeOptions } from "../internal/ObservableStream.js"; export const toEmitValue: MatcherFunction<[value: any, options?: TakeOptions]> = diff --git a/src/testing/matchers/toEmitValueStrict.ts b/src/testing/matchers/toEmitValueStrict.ts index 6a639f5b37e..250ac947d7e 100644 --- a/src/testing/matchers/toEmitValueStrict.ts +++ b/src/testing/matchers/toEmitValueStrict.ts @@ -6,7 +6,8 @@ import { } from "@jest/expect-utils"; import type { MatcherFunction } from "expect"; -import type { ObservableStream } from "../internal/index.js"; +import type { ObservableStream } from "@apollo/client/testing/internal"; + import type { TakeOptions } from "../internal/ObservableStream.js"; export const toEmitValueStrict: MatcherFunction< diff --git a/src/utilities/graphql/__tests__/directives.ts b/src/utilities/graphql/__tests__/directives.ts index cbd677a67d5..bcc73b8c641 100644 --- a/src/utilities/graphql/__tests__/directives.ts +++ b/src/utilities/graphql/__tests__/directives.ts @@ -3,6 +3,7 @@ import { BREAK, visit } from "graphql"; import { gql } from "graphql-tag"; import { cloneDeep } from "lodash"; +import { spyOnConsole } from "@apollo/client/testing/internal"; import { getFragmentMaskMode, getQueryDefinition, @@ -12,8 +13,6 @@ import { shouldInclude, } from "@apollo/client/utilities"; -import { spyOnConsole } from "../../../testing/internal/index.js"; - describe("hasDirectives", () => { it("should allow searching the ast for a directive", () => { const query = gql` diff --git a/src/utilities/invariant/__tests__/invariant.test.ts b/src/utilities/invariant/__tests__/invariant.test.ts index 793b8ee70c8..434cd9f412f 100644 --- a/src/utilities/invariant/__tests__/invariant.test.ts +++ b/src/utilities/invariant/__tests__/invariant.test.ts @@ -1,11 +1,10 @@ +import { spyOnConsole } from "@apollo/client/testing/internal"; import { ApolloErrorMessageHandler, invariant, InvariantError, } from "@apollo/client/utilities/invariant"; -import { spyOnConsole } from "../../../testing/internal/index.js"; - function withDev(): typeof import("../../../dev/index.js") & AsyncDisposable { const originalErrorMessageHandler = window[ApolloErrorMessageHandler]; window[ApolloErrorMessageHandler] = undefined; From 00ca05ed660b5c4a1eaa44c3ad7dfb8bee7c2e4d Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 2 Apr 2025 15:51:47 +0200 Subject: [PATCH 2/6] adjust type imports in tests --- src/__tests__/ApolloClient.ts | 16 +++--- src/__tests__/client.ts | 21 ++++---- src/__tests__/dataMasking.ts | 27 +++++----- src/__tests__/fetchMore.ts | 15 +++--- src/__tests__/local-state/general.ts | 12 +++-- src/__tests__/local-state/resolvers.ts | 10 ++-- src/__tests__/mutationResults.ts | 12 +++-- src/__tests__/optimistic.ts | 20 +++----- src/__tests__/refetchQueries.ts | 5 +- src/__tests__/resultCacheCleaning.ts | 3 +- src/__tests__/subscribeToMore.ts | 5 +- src/cache/core/__tests__/cache.ts | 7 +-- src/cache/inmemory/__tests__/cache.ts | 11 ++-- .../inmemory/__tests__/diffAgainstStore.ts | 2 +- src/cache/inmemory/__tests__/entityStore.ts | 12 ++--- .../inmemory/__tests__/fragmentMatcher.ts | 3 +- src/cache/inmemory/__tests__/helpers.ts | 8 +-- src/cache/inmemory/__tests__/key-extractor.ts | 2 +- src/cache/inmemory/__tests__/policies.ts | 9 ++-- src/cache/inmemory/__tests__/readFromStore.ts | 12 ++--- .../inmemory/__tests__/recordingCache.ts | 2 +- src/cache/inmemory/__tests__/roundtrip.ts | 2 +- src/cache/inmemory/__tests__/writeToStore.ts | 9 ++-- .../__tests__/ApolloClient/general.test.ts | 25 ++++----- src/core/__tests__/ApolloClient/links.test.ts | 11 ++-- src/core/__tests__/ObservableQuery.ts | 18 +++---- src/core/__tests__/equalByQuery.ts | 7 +-- src/core/__tests__/fetchPolicies.ts | 13 ++--- .../batch-http/__tests__/batchHttpLink.ts | 9 ++-- src/link/batch/__tests__/batchLink.ts | 8 ++- src/link/core/__tests__/ApolloLink.ts | 7 ++- src/link/http/__tests__/HttpLink.ts | 12 +++-- .../__tests__/selectHttpOptionsAndBody.ts | 3 +- .../__tests__/react.test.tsx | 3 +- .../__tests__/removeTypenameFromVariables.ts | 2 +- src/link/retry/__tests__/retryFunction.ts | 2 +- .../subscriptions/__tests__/graphqlWsLink.ts | 7 +-- src/link/ws/__tests__/webSocketLink.ts | 2 +- .../context/__tests__/ApolloProvider.test.tsx | 4 +- .../__tests__/useBackgroundQuery.test.tsx | 35 +++++++------ .../hooks/__tests__/useFragment.test.tsx | 17 ++++--- .../hooks/__tests__/useLazyQuery.test.tsx | 22 +++++--- .../hooks/__tests__/useLoadableQuery.test.tsx | 45 ++++++++-------- .../hooks/__tests__/useMutation.test.tsx | 16 +++--- src/react/hooks/__tests__/useQuery.test.tsx | 23 +++++---- .../__tests__/useQueryRefHandlers.test.tsx | 19 ++++--- .../hooks/__tests__/useSubscription.test.tsx | 14 ++--- .../__tests__/useSuspenseFragment.test.tsx | 6 +-- .../hooks/__tests__/useSuspenseQuery.test.tsx | 51 ++++++++++--------- .../cache/__tests__/QueryReference.test.tsx | 2 +- .../__tests__/createQueryPreloader.test.tsx | 34 ++++++------- .../ssr/__tests__/getDataFromTree.test.tsx | 9 ++-- .../ssr/__tests__/prerenderStatic.test.tsx | 10 ++-- src/react/ssr/__tests__/useQuery.test.tsx | 6 ++- .../core/mocking/__tests__/mockLink.ts | 3 +- .../__tests__/createTestSchema.test.tsx | 8 ++- .../react/__tests__/MockedProvider.test.tsx | 10 ++-- .../graphql/__tests__/DocumentTransform.ts | 3 +- src/utilities/graphql/__tests__/fragments.ts | 2 +- src/utilities/graphql/__tests__/getFromAST.ts | 7 +-- src/utilities/graphql/__tests__/transform.ts | 3 +- .../__tests__/relayStylePagination.test.ts | 5 +- 62 files changed, 352 insertions(+), 356 deletions(-) diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 8428c46b973..ae1492cfb5a 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -1,29 +1,31 @@ -import { TypedDocumentNode } from "@graphql-typed-document-node/core"; +import type { TypedDocumentNode } from "@graphql-typed-document-node/core"; import { expectTypeOf } from "expect-type"; import { Kind } from "graphql"; import { gql } from "graphql-tag"; import { Observable, of } from "rxjs"; import { createFragmentRegistry, InMemoryCache } from "@apollo/client/cache"; -import { - ApolloClient, +import type { ApolloQueryResult, DefaultOptions, - makeReference, MutateResult, - NetworkStatus, ObservableQuery, QueryOptions, } from "@apollo/client/core"; +import { + ApolloClient, + makeReference, + NetworkStatus, +} from "@apollo/client/core"; import { ApolloLink } from "@apollo/client/link/core"; import { HttpLink } from "@apollo/client/link/http"; -import { Masked } from "@apollo/client/masking"; +import type { Masked } from "@apollo/client/masking"; import { MockLink } from "@apollo/client/testing"; import { ObservableStream, spyOnConsole, } from "@apollo/client/testing/internal"; -import { DeepPartial } from "@apollo/client/utilities"; +import type { DeepPartial } from "@apollo/client/utilities"; import { invariant } from "@apollo/client/utilities/invariant"; describe("ApolloClient", () => { diff --git a/src/__tests__/client.ts b/src/__tests__/client.ts index 42769fa7fa1..fc8a78b7aac 100644 --- a/src/__tests__/client.ts +++ b/src/__tests__/client.ts @@ -1,35 +1,34 @@ import { waitFor } from "@testing-library/react"; -import { +import type { DocumentNode, FormattedExecutionResult, - GraphQLError, GraphQLFormattedError, - Kind, - print, - visit, } from "graphql"; +import { GraphQLError, Kind, print, visit } from "graphql"; import { gql } from "graphql-tag"; import { assign, cloneDeep } from "lodash"; -import { Observable, of, Subscription } from "rxjs"; +import { Observable, of } from "rxjs"; +import type { Subscription } from "rxjs"; +import type { + NormalizedCacheObject, + PossibleTypesMap, +} from "@apollo/client/cache"; import { createFragmentRegistry, InMemoryCache, makeVar, - NormalizedCacheObject, - PossibleTypesMap, } from "@apollo/client/cache"; -import { - ApolloClient, +import type { ApolloQueryResult, FetchPolicy, - NetworkStatus, ObservableQuery, Operation, QueryOptions, TypedDocumentNode, WatchQueryFetchPolicy, } from "@apollo/client/core"; +import { ApolloClient, NetworkStatus } from "@apollo/client/core"; import { CombinedGraphQLErrors, UnconventionalError, diff --git a/src/__tests__/dataMasking.ts b/src/__tests__/dataMasking.ts index 7526cc7e680..0f7a6c3504a 100644 --- a/src/__tests__/dataMasking.ts +++ b/src/__tests__/dataMasking.ts @@ -1,30 +1,29 @@ -import { FragmentSpreadNode, Kind, visit } from "graphql"; +import type { FragmentSpreadNode } from "graphql"; +import { Kind, visit } from "graphql"; import { of } from "rxjs"; import { createFragmentRegistry } from "@apollo/client/cache"; +import type { + Cache, + DataProxy, + FetchPolicy, + OperationVariables, + Reference, + TypedDocumentNode, +} from "@apollo/client/core"; import { ApolloCache, ApolloClient, ApolloLink, - Cache, - DataProxy, DocumentTransform, - FetchPolicy, gql, InMemoryCache, NetworkStatus, - OperationVariables, - Reference, - TypedDocumentNode, } from "@apollo/client/core"; import { CombinedGraphQLErrors } from "@apollo/client/errors"; -import { MaskedDocumentNode, Unmasked } from "@apollo/client/masking"; -import { - MockedResponse, - MockLink, - MockSubscriptionLink, - wait, -} from "@apollo/client/testing"; +import type { MaskedDocumentNode, Unmasked } from "@apollo/client/masking"; +import type { MockedResponse } from "@apollo/client/testing"; +import { MockLink, MockSubscriptionLink, wait } from "@apollo/client/testing"; import { ObservableStream, spyOnConsole, diff --git a/src/__tests__/fetchMore.ts b/src/__tests__/fetchMore.ts index ee54ee4cb60..ce607f9ca0d 100644 --- a/src/__tests__/fetchMore.ts +++ b/src/__tests__/fetchMore.ts @@ -2,19 +2,16 @@ import { gql } from "graphql-tag"; import { assign, cloneDeep } from "lodash"; import { Observable } from "rxjs"; -import { +import type { ApolloCache, FieldMergeFunction, - InMemoryCache, InMemoryCacheConfig, } from "@apollo/client/cache"; -import { - ApolloClient, - ApolloLink, - NetworkStatus, - TypedDocumentNode, -} from "@apollo/client/core"; -import { MockedResponse, mockSingleLink } from "@apollo/client/testing"; +import { InMemoryCache } from "@apollo/client/cache"; +import type { TypedDocumentNode } from "@apollo/client/core"; +import { ApolloClient, ApolloLink, NetworkStatus } from "@apollo/client/core"; +import type { MockedResponse } from "@apollo/client/testing"; +import { mockSingleLink } from "@apollo/client/testing"; import { ObservableStream, setupPaginatedCase, diff --git a/src/__tests__/local-state/general.ts b/src/__tests__/local-state/general.ts index 57fb46147c4..a0b2d1a4548 100644 --- a/src/__tests__/local-state/general.ts +++ b/src/__tests__/local-state/general.ts @@ -1,9 +1,8 @@ +import type { DocumentNode, GraphQLFormattedError } from "graphql"; import { - DocumentNode, getIntrospectionQuery, graphql, GraphQLError, - GraphQLFormattedError, GraphQLID, GraphQLInt, GraphQLObjectType, @@ -12,12 +11,15 @@ import { print, } from "graphql"; import { gql } from "graphql-tag"; -import { defer, Observable, of } from "rxjs"; +import type { Observable } from "rxjs"; +import { defer, of } from "rxjs"; -import { ApolloCache, InMemoryCache } from "@apollo/client/cache"; +import type { ApolloCache } from "@apollo/client/cache"; +import { InMemoryCache } from "@apollo/client/cache"; import { ApolloClient, NetworkStatus } from "@apollo/client/core"; import { CombinedGraphQLErrors } from "@apollo/client/errors"; -import { ApolloLink, Operation } from "@apollo/client/link/core"; +import type { Operation } from "@apollo/client/link/core"; +import { ApolloLink } from "@apollo/client/link/core"; import { ObservableStream, spyOnConsole, diff --git a/src/__tests__/local-state/resolvers.ts b/src/__tests__/local-state/resolvers.ts index 96117b33ff4..895291b112d 100644 --- a/src/__tests__/local-state/resolvers.ts +++ b/src/__tests__/local-state/resolvers.ts @@ -1,14 +1,10 @@ -import { DocumentNode, ExecutionResult } from "graphql"; +import type { DocumentNode, ExecutionResult } from "graphql"; import { gql } from "graphql-tag"; import { of } from "rxjs"; import { InMemoryCache, isReference } from "@apollo/client/cache"; -import { - ApolloClient, - NetworkStatus, - QueryResult, - Resolvers, -} from "@apollo/client/core"; +import type { QueryResult, Resolvers } from "@apollo/client/core"; +import { ApolloClient, NetworkStatus } from "@apollo/client/core"; import { ApolloLink } from "@apollo/client/link/core"; import { MockLink } from "@apollo/client/testing"; import { ObservableStream } from "@apollo/client/testing/internal"; diff --git a/src/__tests__/mutationResults.ts b/src/__tests__/mutationResults.ts index 6e96278231c..0396ed7eb67 100644 --- a/src/__tests__/mutationResults.ts +++ b/src/__tests__/mutationResults.ts @@ -1,13 +1,17 @@ -import { GraphQLError, GraphQLFormattedError } from "graphql"; +import type { GraphQLFormattedError } from "graphql"; +import { GraphQLError } from "graphql"; import { gql } from "graphql-tag"; import { cloneDeep } from "lodash"; -import { firstValueFrom, from, Observable, Subscription } from "rxjs"; +import type { Subscription } from "rxjs"; +import { firstValueFrom, from, Observable } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; -import { ApolloClient, FetchResult } from "@apollo/client/core"; +import type { FetchResult } from "@apollo/client/core"; +import { ApolloClient } from "@apollo/client/core"; import { CombinedGraphQLErrors } from "@apollo/client/errors"; import { ApolloLink } from "@apollo/client/link/core"; -import { MockedResponse, mockSingleLink } from "@apollo/client/testing"; +import type { MockedResponse } from "@apollo/client/testing"; +import { mockSingleLink } from "@apollo/client/testing"; import { ObservableStream, spyOnConsole, diff --git a/src/__tests__/optimistic.ts b/src/__tests__/optimistic.ts index 6cfffab7c29..6ef06714ccb 100644 --- a/src/__tests__/optimistic.ts +++ b/src/__tests__/optimistic.ts @@ -3,24 +3,16 @@ import { assign, cloneDeep } from "lodash"; import { firstValueFrom, from, lastValueFrom, Observable } from "rxjs"; import { map, take, toArray } from "rxjs/operators"; -import { - Cache, - InMemoryCache, - NormalizedCacheObject, -} from "@apollo/client/cache"; -import { +import type { Cache, NormalizedCacheObject } from "@apollo/client/cache"; +import { InMemoryCache } from "@apollo/client/cache"; +import type { ApolloCache, - ApolloClient, - ApolloLink, - makeReference, MutationQueryReducersMap, TypedDocumentNode, } from "@apollo/client/core"; -import { - MockedResponse, - MockLink, - mockSingleLink, -} from "@apollo/client/testing"; +import { ApolloClient, ApolloLink, makeReference } from "@apollo/client/core"; +import type { MockedResponse } from "@apollo/client/testing"; +import { MockLink, mockSingleLink } from "@apollo/client/testing"; import { ObservableStream } from "@apollo/client/testing/internal"; import { addTypenameToDocument } from "@apollo/client/utilities"; diff --git a/src/__tests__/refetchQueries.ts b/src/__tests__/refetchQueries.ts index 6f826f7f540..f851e8442df 100644 --- a/src/__tests__/refetchQueries.ts +++ b/src/__tests__/refetchQueries.ts @@ -1,5 +1,7 @@ -import { Observable, Subscription } from "rxjs"; +import type { Subscription } from "rxjs"; +import { Observable } from "rxjs"; +import type { TypedDocumentNode } from "@apollo/client/core"; import { ApolloClient, ApolloLink, @@ -7,7 +9,6 @@ import { InMemoryCache, NetworkStatus, ObservableQuery, - TypedDocumentNode, } from "@apollo/client/core"; import { ObservableStream } from "@apollo/client/testing/internal"; diff --git a/src/__tests__/resultCacheCleaning.ts b/src/__tests__/resultCacheCleaning.ts index 9d3bcc79544..e9394e4262d 100644 --- a/src/__tests__/resultCacheCleaning.ts +++ b/src/__tests__/resultCacheCleaning.ts @@ -1,7 +1,8 @@ import { makeExecutableSchema } from "@graphql-tools/schema"; import { InMemoryCache } from "@apollo/client/cache"; -import { ApolloClient, gql, Resolvers } from "@apollo/client/core"; +import type { Resolvers } from "@apollo/client/core"; +import { ApolloClient, gql } from "@apollo/client/core"; import { SchemaLink } from "@apollo/client/link/schema"; describe("resultCache cleaning", () => { diff --git a/src/__tests__/subscribeToMore.ts b/src/__tests__/subscribeToMore.ts index 8d2f31d0962..382d44ed7bb 100644 --- a/src/__tests__/subscribeToMore.ts +++ b/src/__tests__/subscribeToMore.ts @@ -1,9 +1,10 @@ -import { DocumentNode, OperationDefinitionNode } from "graphql"; +import type { DocumentNode, OperationDefinitionNode } from "graphql"; import { gql } from "graphql-tag"; import { InMemoryCache } from "@apollo/client/cache"; import { ApolloClient } from "@apollo/client/core"; -import { ApolloLink, Operation } from "@apollo/client/link/core"; +import type { Operation } from "@apollo/client/link/core"; +import { ApolloLink } from "@apollo/client/link/core"; import { mockObservableLink, mockSingleLink, diff --git a/src/cache/core/__tests__/cache.ts b/src/cache/core/__tests__/cache.ts index 666cbfa2a75..74b3fc0904b 100644 --- a/src/cache/core/__tests__/cache.ts +++ b/src/cache/core/__tests__/cache.ts @@ -1,10 +1,11 @@ import { expectTypeOf } from "expect-type"; import { gql } from "graphql-tag"; -import { ApolloCache, Cache, DataProxy } from "@apollo/client/cache"; -import { OperationVariables, Unmasked } from "@apollo/client/core"; +import type { Cache, DataProxy } from "@apollo/client/cache"; +import { ApolloCache } from "@apollo/client/cache"; +import type { OperationVariables, Unmasked } from "@apollo/client/core"; -import { Reference } from "../../../utilities/graphql/storeUtils.js"; +import type { Reference } from "../../../utilities/graphql/storeUtils.js"; class TestCache extends ApolloCache { constructor() { diff --git a/src/cache/inmemory/__tests__/cache.ts b/src/cache/inmemory/__tests__/cache.ts index 6d0d652ed67..95a7e3fa3b4 100644 --- a/src/cache/inmemory/__tests__/cache.ts +++ b/src/cache/inmemory/__tests__/cache.ts @@ -1,20 +1,19 @@ import { expectTypeOf } from "expect-type"; import { disableFragmentWarnings, gql } from "graphql-tag"; -import { Cache, InMemoryCache, MissingFieldError } from "@apollo/client/cache"; -import { +import type { Cache } from "@apollo/client/cache"; +import { InMemoryCache, MissingFieldError } from "@apollo/client/cache"; +import type { DocumentNode, - isReference, - makeReference, - makeVar, Reference, TypedDocumentNode, } from "@apollo/client/core"; +import { isReference, makeReference, makeVar } from "@apollo/client/core"; import { spyOnConsole } from "@apollo/client/testing/internal"; import { cloneDeep, defaultCacheSizes } from "@apollo/client/utilities"; import { StoreReader } from "../readFromStore.js"; -import { InMemoryCacheConfig } from "../types.js"; +import type { InMemoryCacheConfig } from "../types.js"; import { StoreWriter } from "../writeToStore.js"; disableFragmentWarnings(); diff --git a/src/cache/inmemory/__tests__/diffAgainstStore.ts b/src/cache/inmemory/__tests__/diffAgainstStore.ts index f49411db5b3..0275f24f4a4 100644 --- a/src/cache/inmemory/__tests__/diffAgainstStore.ts +++ b/src/cache/inmemory/__tests__/diffAgainstStore.ts @@ -4,7 +4,7 @@ import { defaultDataIdFromObject, InMemoryCache } from "@apollo/client/cache"; import { MissingFieldError } from "@apollo/client/core"; import { StoreReader } from "../readFromStore.js"; -import { NormalizedCache, Reference } from "../types.js"; +import type { NormalizedCache, Reference } from "../types.js"; import { StoreWriter } from "../writeToStore.js"; import { diff --git a/src/cache/inmemory/__tests__/entityStore.ts b/src/cache/inmemory/__tests__/entityStore.ts index 0853744dd60..8a8181a7444 100644 --- a/src/cache/inmemory/__tests__/entityStore.ts +++ b/src/cache/inmemory/__tests__/entityStore.ts @@ -1,9 +1,9 @@ -import { TypedDocumentNode } from "@graphql-typed-document-node/core"; -import { DocumentNode } from "graphql"; +import type { TypedDocumentNode } from "@graphql-typed-document-node/core"; +import type { DocumentNode } from "graphql"; import { gql } from "graphql-tag"; +import type { ApolloCache } from "@apollo/client/cache"; import { - ApolloCache, EntityStore, InMemoryCache, MissingFieldError, @@ -16,13 +16,13 @@ import { } from "@apollo/client/utilities"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { +import type { Reference, StoreValue, } from "../../../utilities/graphql/storeUtils.js"; -import { Cache } from "../../core/types/Cache.js"; +import type { Cache } from "../../core/types/Cache.js"; import { supportsResultCaching } from "../entityStore.js"; -import { StoreObject } from "../types.js"; +import type { StoreObject } from "../types.js"; describe("EntityStore", () => { it("should support result caching if so configured", () => { diff --git a/src/cache/inmemory/__tests__/fragmentMatcher.ts b/src/cache/inmemory/__tests__/fragmentMatcher.ts index 6023fdad739..f5534dab1e3 100644 --- a/src/cache/inmemory/__tests__/fragmentMatcher.ts +++ b/src/cache/inmemory/__tests__/fragmentMatcher.ts @@ -1,4 +1,5 @@ -import { FragmentDefinitionNode, visit } from "graphql"; +import type { FragmentDefinitionNode } from "graphql"; +import { visit } from "graphql"; import { gql } from "graphql-tag"; import { InMemoryCache } from "@apollo/client/cache"; diff --git a/src/cache/inmemory/__tests__/helpers.ts b/src/cache/inmemory/__tests__/helpers.ts index b785e279216..7b75d9a94e6 100644 --- a/src/cache/inmemory/__tests__/helpers.ts +++ b/src/cache/inmemory/__tests__/helpers.ts @@ -1,13 +1,13 @@ import { EntityStore, InMemoryCache } from "@apollo/client/cache"; -import { Cache } from "@apollo/client/core"; +import type { Cache } from "@apollo/client/core"; -import { StoreReader } from "../readFromStore.js"; -import { +import type { StoreReader } from "../readFromStore.js"; +import type { DiffQueryAgainstStoreOptions, NormalizedCache, NormalizedCacheObject, } from "../types.js"; -import { StoreWriter } from "../writeToStore.js"; +import type { StoreWriter } from "../writeToStore.js"; export function defaultNormalizedCacheFactory( seed?: NormalizedCacheObject diff --git a/src/cache/inmemory/__tests__/key-extractor.ts b/src/cache/inmemory/__tests__/key-extractor.ts index 26a5e93447d..bcd984ac6f1 100644 --- a/src/cache/inmemory/__tests__/key-extractor.ts +++ b/src/cache/inmemory/__tests__/key-extractor.ts @@ -5,7 +5,7 @@ import { extractKeyPath, getSpecifierPaths, } from "../key-extractor.js"; -import { KeySpecifier } from "../policies.js"; +import type { KeySpecifier } from "../policies.js"; describe("keyFields and keyArgs extraction", () => { it("getSpecifierPaths should work for various specifiers", () => { diff --git a/src/cache/inmemory/__tests__/policies.ts b/src/cache/inmemory/__tests__/policies.ts index 8e741429853..bd3264cee6c 100644 --- a/src/cache/inmemory/__tests__/policies.ts +++ b/src/cache/inmemory/__tests__/policies.ts @@ -5,15 +5,14 @@ import { makeVar, MissingFieldError, } from "@apollo/client/cache"; -import { - ApolloClient, +import type { DocumentNode, - NetworkStatus, OperationVariables, Reference, StoreObject, TypedDocumentNode, } from "@apollo/client/core"; +import { ApolloClient, NetworkStatus } from "@apollo/client/core"; import { MockLink } from "@apollo/client/testing/core"; import { ObservableStream, @@ -24,8 +23,8 @@ import { stringifyForDisplay, } from "@apollo/client/utilities"; -import { FieldPolicy, StorageType } from "../policies.js"; -import { ReactiveVar } from "../reactiveVars.js"; +import type { FieldPolicy, StorageType } from "../policies.js"; +import type { ReactiveVar } from "../reactiveVars.js"; function reverse(s: string) { return s.split("").reverse().join(""); diff --git a/src/cache/inmemory/__tests__/readFromStore.ts b/src/cache/inmemory/__tests__/readFromStore.ts index f49a83e03a1..96996e23ceb 100644 --- a/src/cache/inmemory/__tests__/readFromStore.ts +++ b/src/cache/inmemory/__tests__/readFromStore.ts @@ -2,17 +2,13 @@ import { gql } from "graphql-tag"; import { assign, omit } from "lodash"; import { InMemoryCache, MissingFieldError } from "@apollo/client/cache"; -import { - isReference, - makeReference, - Reference, - TypedDocumentNode, -} from "@apollo/client/core"; +import type { Reference, TypedDocumentNode } from "@apollo/client/core"; +import { isReference, makeReference } from "@apollo/client/core"; import { defaultCacheSizes } from "@apollo/client/utilities"; -import { Cache } from "../../core/types/Cache.js"; +import type { Cache } from "../../core/types/Cache.js"; import { StoreReader } from "../readFromStore.js"; -import { StoreObject } from "../types.js"; +import type { StoreObject } from "../types.js"; import { defaultNormalizedCacheFactory, diff --git a/src/cache/inmemory/__tests__/recordingCache.ts b/src/cache/inmemory/__tests__/recordingCache.ts index 5b7ab057e75..895c3e3b7e8 100644 --- a/src/cache/inmemory/__tests__/recordingCache.ts +++ b/src/cache/inmemory/__tests__/recordingCache.ts @@ -1,6 +1,6 @@ import { EntityStore, InMemoryCache, Policies } from "@apollo/client/cache"; -import { NormalizedCacheObject, StoreObject } from "../types.js"; +import type { NormalizedCacheObject, StoreObject } from "../types.js"; describe("Optimistic EntityStore layering", () => { function makeLayer(root: EntityStore) { diff --git a/src/cache/inmemory/__tests__/roundtrip.ts b/src/cache/inmemory/__tests__/roundtrip.ts index 774fa2a2813..aa58430940f 100644 --- a/src/cache/inmemory/__tests__/roundtrip.ts +++ b/src/cache/inmemory/__tests__/roundtrip.ts @@ -1,4 +1,4 @@ -import { DocumentNode } from "graphql"; +import type { DocumentNode } from "graphql"; import { gql } from "graphql-tag"; import { EntityStore, InMemoryCache } from "@apollo/client/cache"; diff --git a/src/cache/inmemory/__tests__/writeToStore.ts b/src/cache/inmemory/__tests__/writeToStore.ts index 0d4d91a4ca3..3e66f5b6ea8 100644 --- a/src/cache/inmemory/__tests__/writeToStore.ts +++ b/src/cache/inmemory/__tests__/writeToStore.ts @@ -1,4 +1,4 @@ -import { +import type { ASTNode, DefinitionNode, DocumentNode, @@ -10,22 +10,21 @@ import { gql } from "graphql-tag"; import { assign, omit } from "lodash"; import { InMemoryCache } from "@apollo/client/cache"; -import { TypedDocumentNode } from "@apollo/client/core"; +import type { TypedDocumentNode } from "@apollo/client/core"; import { spyOnConsole } from "@apollo/client/testing/internal"; +import type { Reference, StoreObject } from "@apollo/client/utilities"; import { addTypenameToDocument, cloneDeep, getMainDefinition, isReference, makeReference, - Reference, storeKeyNameFromField, - StoreObject, } from "@apollo/client/utilities"; import { invariant } from "@apollo/client/utilities/invariant"; import { extractFragmentContext } from "../helpers.js"; -import { KeyFieldsFunction } from "../policies.js"; +import type { KeyFieldsFunction } from "../policies.js"; import { StoreWriter } from "../writeToStore.js"; import { defaultNormalizedCacheFactory, writeQueryToStore } from "./helpers.js"; diff --git a/src/core/__tests__/ApolloClient/general.test.ts b/src/core/__tests__/ApolloClient/general.test.ts index f1da43efc23..a6a6abe366b 100644 --- a/src/core/__tests__/ApolloClient/general.test.ts +++ b/src/core/__tests__/ApolloClient/general.test.ts @@ -1,16 +1,15 @@ // externals -import { DocumentNode, GraphQLError } from "graphql"; +import type { DocumentNode } from "graphql"; +import { GraphQLError } from "graphql"; import { gql } from "graphql-tag"; -import { Observable, Observer } from "rxjs"; +import type { Observer } from "rxjs"; +import { Observable } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; -import { - ApolloClient, - ApolloQueryResult, - NetworkStatus, -} from "@apollo/client/core"; +import type { ApolloQueryResult } from "@apollo/client/core"; +import { ApolloClient, NetworkStatus } from "@apollo/client/core"; import { CombinedGraphQLErrors } from "@apollo/client/errors"; -import { +import type { ApolloLink, FetchResult, type RequestHandler, @@ -27,12 +26,10 @@ import { setVerbosity, } from "@apollo/client/utilities/invariant"; -import { - MockApolloLink, - MockLink, -} from "../../../testing/core/mocking/mockLink.js"; -import { QueryManager } from "../../QueryManager.js"; -import { +import type { MockApolloLink } from "../../../testing/core/mocking/mockLink.js"; +import { MockLink } from "../../../testing/core/mocking/mockLink.js"; +import type { QueryManager } from "../../QueryManager.js"; +import type { WatchQueryFetchPolicy, WatchQueryOptions, } from "../../watchQueryOptions.js"; diff --git a/src/core/__tests__/ApolloClient/links.test.ts b/src/core/__tests__/ApolloClient/links.test.ts index 2b1c08625ce..7fb459c005f 100644 --- a/src/core/__tests__/ApolloClient/links.test.ts +++ b/src/core/__tests__/ApolloClient/links.test.ts @@ -1,14 +1,11 @@ import { print } from "graphql"; import { gql } from "graphql-tag"; -import { map, of, Subscription } from "rxjs"; +import type { Subscription } from "rxjs"; +import { map, of } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; -import { - ApolloClient, - NextLink, - Operation, - Reference, -} from "@apollo/client/core"; +import type { NextLink, Operation, Reference } from "@apollo/client/core"; +import { ApolloClient } from "@apollo/client/core"; import { ApolloLink } from "@apollo/client/link/core"; import { MockSubscriptionLink } from "@apollo/client/testing/core"; diff --git a/src/core/__tests__/ObservableQuery.ts b/src/core/__tests__/ObservableQuery.ts index cbdc4e86993..acdd49231b7 100644 --- a/src/core/__tests__/ObservableQuery.ts +++ b/src/core/__tests__/ObservableQuery.ts @@ -1,20 +1,21 @@ -import { TypedDocumentNode } from "@graphql-typed-document-node/core"; +import type { TypedDocumentNode } from "@graphql-typed-document-node/core"; import { waitFor } from "@testing-library/react"; import { expectTypeOf } from "expect-type"; import { GraphQLError } from "graphql"; import { gql } from "graphql-tag"; -import { from, Observable, ObservedValueOf, Observer, of, Subject } from "rxjs"; +import type { ObservedValueOf, Observer } from "rxjs"; +import { from, Observable, of, Subject } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; -import { - ApolloClient, +import type { ApolloQueryResult, - NetworkStatus, ObservableQuery, WatchQueryFetchPolicy, } from "@apollo/client/core"; +import { ApolloClient, NetworkStatus } from "@apollo/client/core"; import { CombinedGraphQLErrors } from "@apollo/client/errors"; -import { ApolloLink, FetchResult } from "@apollo/client/link/core"; +import type { FetchResult } from "@apollo/client/link/core"; +import { ApolloLink } from "@apollo/client/link/core"; import { MockLink, MockSubscriptionLink, @@ -25,14 +26,13 @@ import { ObservableStream, spyOnConsole, } from "@apollo/client/testing/internal"; +import type { DeepPartial } from "@apollo/client/utilities"; import { - DeepPartial, DocumentTransform, removeDirectivesFromDocument, } from "@apollo/client/utilities"; -import type { ObservableAndInfo } from "../QueryManager.js"; -import { QueryManager } from "../QueryManager.js"; +import type { ObservableAndInfo, QueryManager } from "../QueryManager.js"; export const mockFetchQuery = (queryManager: QueryManager) => { const mocks = { diff --git a/src/core/__tests__/equalByQuery.ts b/src/core/__tests__/equalByQuery.ts index 05886dbaebb..89685606fa1 100644 --- a/src/core/__tests__/equalByQuery.ts +++ b/src/core/__tests__/equalByQuery.ts @@ -1,10 +1,7 @@ import { GraphQLError } from "graphql"; -import { - CombinedGraphQLErrors, - gql, - TypedDocumentNode, -} from "@apollo/client/core"; +import type { TypedDocumentNode } from "@apollo/client/core"; +import { CombinedGraphQLErrors, gql } from "@apollo/client/core"; import { equalByQuery } from "../equalByQuery.js"; diff --git a/src/core/__tests__/fetchPolicies.ts b/src/core/__tests__/fetchPolicies.ts index 561790da82b..2cb797fa5f0 100644 --- a/src/core/__tests__/fetchPolicies.ts +++ b/src/core/__tests__/fetchPolicies.ts @@ -1,13 +1,10 @@ -import { TypedDocumentNode } from "@graphql-typed-document-node/core"; +import type { TypedDocumentNode } from "@graphql-typed-document-node/core"; import { gql } from "graphql-tag"; import { map, Observable } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; -import { - ApolloClient, - NetworkStatus, - ObservableQuery, -} from "@apollo/client/core"; +import type { ObservableQuery } from "@apollo/client/core"; +import { ApolloClient, NetworkStatus } from "@apollo/client/core"; import { ApolloLink } from "@apollo/client/link/core"; import { mockSingleLink } from "@apollo/client/testing"; import { @@ -15,8 +12,8 @@ import { spyOnConsole, } from "@apollo/client/testing/internal"; -import { ApolloQueryResult } from "../types.js"; -import { +import type { ApolloQueryResult } from "../types.js"; +import type { WatchQueryFetchPolicy, WatchQueryOptions, } from "../watchQueryOptions.js"; diff --git a/src/link/batch-http/__tests__/batchHttpLink.ts b/src/link/batch-http/__tests__/batchHttpLink.ts index e03761c3ef1..be8930f0ac8 100644 --- a/src/link/batch-http/__tests__/batchHttpLink.ts +++ b/src/link/batch-http/__tests__/batchHttpLink.ts @@ -1,10 +1,13 @@ import fetchMock from "fetch-mock"; -import { ASTNode, print, stripIgnoredCharacters } from "graphql"; +import type { ASTNode } from "graphql"; +import { print, stripIgnoredCharacters } from "graphql"; import { gql } from "graphql-tag"; -import { map, Observable, Observer, Subscription } from "rxjs"; +import type { Observer, Subscription } from "rxjs"; +import { map, Observable } from "rxjs"; import { BatchHttpLink } from "@apollo/client/link/batch-http"; -import { ApolloLink, execute, FetchResult } from "@apollo/client/link/core"; +import type { FetchResult } from "@apollo/client/link/core"; +import { ApolloLink, execute } from "@apollo/client/link/core"; import { ObservableStream } from "@apollo/client/testing/internal"; const sampleQuery = gql` diff --git a/src/link/batch/__tests__/batchLink.ts b/src/link/batch/__tests__/batchLink.ts index d1404a11dce..bfe9a1e1552 100644 --- a/src/link/batch/__tests__/batchLink.ts +++ b/src/link/batch/__tests__/batchLink.ts @@ -7,8 +7,12 @@ import { ApolloLink, execute } from "@apollo/client/link/core"; import { wait } from "@apollo/client/testing"; import { ObservableStream } from "@apollo/client/testing/internal"; -import { FetchResult, GraphQLRequest, Operation } from "../../core/types.js"; -import { BatchableRequest, BatchHandler } from "../batchLink.js"; +import type { + FetchResult, + GraphQLRequest, + Operation, +} from "../../core/types.js"; +import type { BatchableRequest, BatchHandler } from "../batchLink.js"; interface MockedResponse { request: GraphQLRequest; diff --git a/src/link/core/__tests__/ApolloLink.ts b/src/link/core/__tests__/ApolloLink.ts index ff451f66895..bb7d828990d 100644 --- a/src/link/core/__tests__/ApolloLink.ts +++ b/src/link/core/__tests__/ApolloLink.ts @@ -5,7 +5,12 @@ import { EMPTY, map, Observable, of } from "rxjs"; import { ApolloLink, execute } from "@apollo/client/link/core"; import { ObservableStream } from "@apollo/client/testing/internal"; -import { FetchResult, GraphQLRequest, NextLink, Operation } from "../types.js"; +import type { + FetchResult, + GraphQLRequest, + NextLink, + Operation, +} from "../types.js"; class SetContextLink extends ApolloLink { constructor( diff --git a/src/link/http/__tests__/HttpLink.ts b/src/link/http/__tests__/HttpLink.ts index c5159a4c401..663fbb6a441 100644 --- a/src/link/http/__tests__/HttpLink.ts +++ b/src/link/http/__tests__/HttpLink.ts @@ -1,23 +1,25 @@ import { TextDecoder } from "util"; import fetchMock from "fetch-mock"; -import { ASTNode, print, stripIgnoredCharacters } from "graphql"; +import type { ASTNode } from "graphql"; +import { print, stripIgnoredCharacters } from "graphql"; import { gql } from "graphql-tag"; -import { map, Observable, Observer, Subscription } from "rxjs"; +import type { Observer, Subscription } from "rxjs"; +import { map, Observable } from "rxjs"; import { ReadableStream } from "web-streams-polyfill"; -import { FetchResult, ServerError } from "@apollo/client"; +import type { FetchResult, ServerError } from "@apollo/client"; +import type { ServerParseError } from "@apollo/client/errors"; import { CombinedProtocolErrors, PROTOCOL_ERRORS_SYMBOL, - ServerParseError, } from "@apollo/client/errors"; import { ApolloLink, execute } from "@apollo/client/link/core"; import { createHttpLink, HttpLink } from "@apollo/client/link/http"; import { wait } from "@apollo/client/testing"; import { ObservableStream } from "@apollo/client/testing/internal"; -import { ClientParseError } from "../serializeFetchParameter.js"; +import type { ClientParseError } from "../serializeFetchParameter.js"; import { voidFetchDuringEachTest } from "./helpers.js"; diff --git a/src/link/http/__tests__/selectHttpOptionsAndBody.ts b/src/link/http/__tests__/selectHttpOptionsAndBody.ts index eaa3366e16d..8e9cedb434e 100644 --- a/src/link/http/__tests__/selectHttpOptionsAndBody.ts +++ b/src/link/http/__tests__/selectHttpOptionsAndBody.ts @@ -1,4 +1,5 @@ -import { ASTNode, print, stripIgnoredCharacters } from "graphql"; +import type { ASTNode, print } from "graphql"; +import { stripIgnoredCharacters } from "graphql"; import { gql } from "graphql-tag"; import { diff --git a/src/link/persisted-queries/__tests__/react.test.tsx b/src/link/persisted-queries/__tests__/react.test.tsx index c06d3cfa4a8..bb173e3f314 100644 --- a/src/link/persisted-queries/__tests__/react.test.tsx +++ b/src/link/persisted-queries/__tests__/react.test.tsx @@ -8,7 +8,8 @@ import * as React from "react"; import * as ReactDOM from "react-dom/server"; import { InMemoryCache as Cache } from "@apollo/client/cache"; -import { ApolloClient, OperationVariables } from "@apollo/client/core"; +import type { OperationVariables } from "@apollo/client/core"; +import { ApolloClient } from "@apollo/client/core"; import { createHttpLink } from "@apollo/client/link/http"; import { createPersistedQueryLink as createPersistedQuery, diff --git a/src/link/remove-typename/__tests__/removeTypenameFromVariables.ts b/src/link/remove-typename/__tests__/removeTypenameFromVariables.ts index 5a27405e1ea..f9683038715 100644 --- a/src/link/remove-typename/__tests__/removeTypenameFromVariables.ts +++ b/src/link/remove-typename/__tests__/removeTypenameFromVariables.ts @@ -1,7 +1,7 @@ import { firstValueFrom, of } from "rxjs"; import { gql } from "@apollo/client/core"; -import { ApolloLink, Operation } from "@apollo/client/link/core"; +import type { ApolloLink, Operation } from "@apollo/client/link/core"; import { KEEP, removeTypenameFromVariables, diff --git a/src/link/retry/__tests__/retryFunction.ts b/src/link/retry/__tests__/retryFunction.ts index 16cd6a44caa..414bffa4f02 100644 --- a/src/link/retry/__tests__/retryFunction.ts +++ b/src/link/retry/__tests__/retryFunction.ts @@ -1,4 +1,4 @@ -import { Operation } from "../../core/types.js"; +import type { Operation } from "../../core/types.js"; import { buildRetryFunction } from "../retryFunction.js"; describe("buildRetryFunction", () => { diff --git a/src/link/subscriptions/__tests__/graphqlWsLink.ts b/src/link/subscriptions/__tests__/graphqlWsLink.ts index 17aacdba16a..43a696be48a 100644 --- a/src/link/subscriptions/__tests__/graphqlWsLink.ts +++ b/src/link/subscriptions/__tests__/graphqlWsLink.ts @@ -1,7 +1,8 @@ -import { ExecutionResult, GraphQLError } from "graphql"; +import type { ExecutionResult } from "graphql"; +import { GraphQLError } from "graphql"; import { gql } from "graphql-tag"; -import { Client } from "graphql-ws"; -import { Observable } from "rxjs"; +import type { Client } from "graphql-ws"; +import type { Observable } from "rxjs"; import { CombinedGraphQLErrors } from "@apollo/client/errors"; import { execute } from "@apollo/client/link/core"; diff --git a/src/link/ws/__tests__/webSocketLink.ts b/src/link/ws/__tests__/webSocketLink.ts index 38c3f7c432a..3f8af17f98d 100644 --- a/src/link/ws/__tests__/webSocketLink.ts +++ b/src/link/ws/__tests__/webSocketLink.ts @@ -1,4 +1,4 @@ -import { ExecutionResult } from "graphql"; +import type { ExecutionResult } from "graphql"; import { gql } from "graphql-tag"; import { Observable, of } from "rxjs"; import { SubscriptionClient } from "subscriptions-transport-ws"; diff --git a/src/react/context/__tests__/ApolloProvider.test.tsx b/src/react/context/__tests__/ApolloProvider.test.tsx index 97a49154e50..002529a724e 100644 --- a/src/react/context/__tests__/ApolloProvider.test.tsx +++ b/src/react/context/__tests__/ApolloProvider.test.tsx @@ -6,8 +6,8 @@ import { ApolloClient } from "@apollo/client/core"; import { ApolloLink } from "@apollo/client/link/core"; import { ApolloProvider, getApolloContext } from "@apollo/client/react/context"; -import { ApolloContextValue } from "../ApolloContext.js"; -import { ApolloProviderProps } from "../ApolloProvider.js"; +import type { ApolloContextValue } from "../ApolloContext.js"; +import type { ApolloProviderProps } from "../ApolloProvider.js"; describe(" Component", () => { const client = new ApolloClient({ diff --git a/src/react/hooks/__tests__/useBackgroundQuery.test.tsx b/src/react/hooks/__tests__/useBackgroundQuery.test.tsx index 6999abe072c..4db0eb5656a 100644 --- a/src/react/hooks/__tests__/useBackgroundQuery.test.tsx +++ b/src/react/hooks/__tests__/useBackgroundQuery.test.tsx @@ -1,8 +1,8 @@ import { act, renderHook, screen } from "@testing-library/react"; +import type { RenderStream } from "@testing-library/react-render-stream"; import { createRenderStream, disableActEnvironment, - RenderStream, useTrackRenders, } from "@testing-library/react-render-stream"; import { userEvent } from "@testing-library/user-event"; @@ -10,69 +10,68 @@ import equal from "@wry/equality"; import { expectTypeOf } from "expect-type"; import { GraphQLError } from "graphql"; import React, { Suspense } from "react"; -import { - ErrorBoundary as ReactErrorBoundary, - FallbackProps, -} from "react-error-boundary"; +import type { FallbackProps } from "react-error-boundary"; +import { ErrorBoundary as ReactErrorBoundary } from "react-error-boundary"; import { Observable, of } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; +import type { ErrorPolicy, TypedDocumentNode } from "@apollo/client/core"; import { ApolloClient, ApolloLink, CombinedGraphQLErrors, - ErrorPolicy, gql, NetworkStatus, split, - TypedDocumentNode, } from "@apollo/client/core"; -import { Masked, MaskedDocumentNode } from "@apollo/client/masking"; +import type { Masked, MaskedDocumentNode } from "@apollo/client/masking"; import { ApolloProvider } from "@apollo/client/react/context"; import { skipToken, useBackgroundQuery, useReadQuery, } from "@apollo/client/react/hooks"; -import { QueryRef, QueryReference } from "@apollo/client/react/internal"; +import type { QueryRef, QueryReference } from "@apollo/client/react/internal"; +import type { MockedResponse } from "@apollo/client/testing"; import { - MockedResponse, MockLink, mockSingleLink, MockSubscriptionLink, wait, } from "@apollo/client/testing"; +import type { + PaginatedCaseData, + SimpleCaseData, + VariablesCaseData, + VariablesCaseVariables, +} from "@apollo/client/testing/internal"; import { addDelayToMocks, createClientWrapper, createMockWrapper, - PaginatedCaseData, setupPaginatedCase, setupSimpleCase, setupVariablesCase, - SimpleCaseData, spyOnConsole, - VariablesCaseData, - VariablesCaseVariables, } from "@apollo/client/testing/internal"; import { MockedProvider } from "@apollo/client/testing/react"; +import type { DeepPartial } from "@apollo/client/utilities"; import { concatPagination, - DeepPartial, getMainDefinition, offsetLimitPagination, } from "@apollo/client/utilities"; -import { +import type { RefetchWritePolicy, SubscribeToMoreFunction, SubscribeToMoreOptions, } from "../../../core/watchQueryOptions.js"; -import { +import type { MaskedVariablesCaseData, - setupMaskedVariablesCase, UnmaskedVariablesCaseData, } from "../../../testing/internal/scenarios/index.js"; +import { setupMaskedVariablesCase } from "../../../testing/internal/scenarios/index.js"; afterEach(() => { jest.useRealTimers(); diff --git a/src/react/hooks/__tests__/useFragment.test.tsx b/src/react/hooks/__tests__/useFragment.test.tsx index a89bc3bcdee..d3a70251ff4 100644 --- a/src/react/hooks/__tests__/useFragment.test.tsx +++ b/src/react/hooks/__tests__/useFragment.test.tsx @@ -17,20 +17,23 @@ import { import { userEvent } from "@testing-library/user-event"; import { expectTypeOf } from "expect-type"; import * as React from "react"; -import { Observable, Observer } from "rxjs"; +import type { Observer } from "rxjs"; +import { Observable } from "rxjs"; -import { - ApolloClient, - ApolloLink, +import type { DocumentNode, FetchResult, - gql, - InMemoryCache, Reference, StoreObject, TypedDocumentNode, } from "@apollo/client/core"; -import { FragmentType } from "@apollo/client/masking"; +import { + ApolloClient, + ApolloLink, + gql, + InMemoryCache, +} from "@apollo/client/core"; +import type { FragmentType } from "@apollo/client/masking"; import { ApolloProvider } from "@apollo/client/react/context"; import { useFragment, useQuery } from "@apollo/client/react/hooks"; import { spyOnConsole } from "@apollo/client/testing/internal"; diff --git a/src/react/hooks/__tests__/useLazyQuery.test.tsx b/src/react/hooks/__tests__/useLazyQuery.test.tsx index 69f9cfae92d..e5e73075a45 100644 --- a/src/react/hooks/__tests__/useLazyQuery.test.tsx +++ b/src/react/hooks/__tests__/useLazyQuery.test.tsx @@ -11,19 +11,25 @@ import React from "react"; import { ErrorBoundary } from "react-error-boundary"; import { Observable } from "rxjs"; +import type { + ErrorPolicy, + QueryResult, + RefetchWritePolicy, + TypedDocumentNode, + WatchQueryFetchPolicy, +} from "@apollo/client/core"; import { ApolloClient, ApolloLink, CombinedGraphQLErrors, - ErrorPolicy, InMemoryCache, NetworkStatus, - QueryResult, - RefetchWritePolicy, - TypedDocumentNode, - WatchQueryFetchPolicy, } from "@apollo/client/core"; -import { Masked, MaskedDocumentNode, Unmasked } from "@apollo/client/masking"; +import type { + Masked, + MaskedDocumentNode, + Unmasked, +} from "@apollo/client/masking"; import { ApolloProvider } from "@apollo/client/react"; import { useLazyQuery } from "@apollo/client/react/hooks"; import { @@ -32,15 +38,15 @@ import { MockSubscriptionLink, wait, } from "@apollo/client/testing"; +import type { VariablesCaseVariables } from "@apollo/client/testing/internal"; import { renderAsync, setupSimpleCase, setupVariablesCase, spyOnConsole, - VariablesCaseVariables, } from "@apollo/client/testing/internal"; import { MockedProvider } from "@apollo/client/testing/react"; -import { DeepPartial } from "@apollo/client/utilities"; +import type { DeepPartial } from "@apollo/client/utilities"; import { InvariantError } from "@apollo/client/utilities/invariant"; describe("useLazyQuery Hook", () => { diff --git a/src/react/hooks/__tests__/useLoadableQuery.test.tsx b/src/react/hooks/__tests__/useLoadableQuery.test.tsx index 36ae1b15a47..8542612e78f 100644 --- a/src/react/hooks/__tests__/useLoadableQuery.test.tsx +++ b/src/react/hooks/__tests__/useLoadableQuery.test.tsx @@ -1,9 +1,11 @@ import { act, renderHook, screen, waitFor } from "@testing-library/react"; -import { +import type { AsyncRenderFn, + RenderStream, +} from "@testing-library/react-render-stream"; +import { createRenderStream, disableActEnvironment, - RenderStream, useTrackRenders, } from "@testing-library/react-render-stream"; import { userEvent } from "@testing-library/user-event"; @@ -14,49 +16,48 @@ import { ErrorBoundary as ReactErrorBoundary } from "react-error-boundary"; import { Observable } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; +import type { + ErrorPolicy, + OperationVariables, + RefetchWritePolicy, + SubscribeToMoreOptions, + TypedDocumentNode, +} from "@apollo/client/core"; import { ApolloClient, ApolloLink, CombinedGraphQLErrors, - ErrorPolicy, gql, NetworkStatus, - OperationVariables, - RefetchWritePolicy, split, - SubscribeToMoreOptions, - TypedDocumentNode, } from "@apollo/client/core"; -import { QueryRef } from "@apollo/client/react"; +import type { QueryRef } from "@apollo/client/react"; import { ApolloProvider } from "@apollo/client/react/context"; import { useLoadableQuery, useReadQuery } from "@apollo/client/react/hooks"; -import { - MockedResponse, - MockLink, - MockSubscriptionLink, - wait, -} from "@apollo/client/testing"; +import type { MockedResponse } from "@apollo/client/testing"; +import { MockLink, MockSubscriptionLink, wait } from "@apollo/client/testing"; +import type { SimpleCaseData } from "@apollo/client/testing/internal"; import { renderAsync, setupPaginatedCase, setupSimpleCase, - SimpleCaseData, spyOnConsole, } from "@apollo/client/testing/internal"; -import { - MockedProvider, - MockedProviderProps, -} from "@apollo/client/testing/react"; +import type { MockedProviderProps } from "@apollo/client/testing/react"; +import { MockedProvider } from "@apollo/client/testing/react"; +import type { DeepPartial } from "@apollo/client/utilities"; import { concatPagination, - DeepPartial, getMainDefinition, offsetLimitPagination, } from "@apollo/client/utilities"; import { invariant, InvariantError } from "@apollo/client/utilities/invariant"; -import { SubscribeToMoreFunction } from "../../../core/watchQueryOptions.js"; -import { FetchMoreFunction, RefetchFunction } from "../../internal/types.js"; +import type { SubscribeToMoreFunction } from "../../../core/watchQueryOptions.js"; +import type { + FetchMoreFunction, + RefetchFunction, +} from "../../internal/types.js"; const IS_REACT_19 = React.version.startsWith("19"); diff --git a/src/react/hooks/__tests__/useMutation.test.tsx b/src/react/hooks/__tests__/useMutation.test.tsx index 9043cadb2ba..d845bdf8103 100644 --- a/src/react/hooks/__tests__/useMutation.test.tsx +++ b/src/react/hooks/__tests__/useMutation.test.tsx @@ -19,23 +19,25 @@ import React, { useEffect } from "react"; import { Observable } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; +import type { + Cache, + ObservableQuery, + QueryResult, + TypedDocumentNode, +} from "@apollo/client/core"; import { ApolloClient, ApolloLink, - Cache, CombinedGraphQLErrors, NetworkStatus, - ObservableQuery, - QueryResult, - TypedDocumentNode, } from "@apollo/client/core"; import { BatchHttpLink } from "@apollo/client/link/batch-http"; -import { FetchResult } from "@apollo/client/link/core"; -import { Masked } from "@apollo/client/masking"; +import type { FetchResult } from "@apollo/client/link/core"; +import type { Masked } from "@apollo/client/masking"; import { ApolloProvider } from "@apollo/client/react/context"; import { useMutation, useQuery } from "@apollo/client/react/hooks"; +import type { MockedResponse } from "@apollo/client/testing"; import { - MockedResponse, MockLink, mockSingleLink, MockSubscriptionLink, diff --git a/src/react/hooks/__tests__/useQuery.test.tsx b/src/react/hooks/__tests__/useQuery.test.tsx index 7d08828ea2d..b4fc8911420 100644 --- a/src/react/hooks/__tests__/useQuery.test.tsx +++ b/src/react/hooks/__tests__/useQuery.test.tsx @@ -11,32 +11,36 @@ import { renderHookToSnapshotStream, } from "@testing-library/react-render-stream"; import { userEvent } from "@testing-library/user-event"; -import { DocumentNode, GraphQLError, GraphQLFormattedError } from "graphql"; +import type { DocumentNode, GraphQLFormattedError } from "graphql"; +import { GraphQLError } from "graphql"; import { gql } from "graphql-tag"; -import React, { Fragment, ReactNode, useEffect, useState } from "react"; +import type { ReactNode } from "react"; +import React, { Fragment, useEffect, useState } from "react"; import { asapScheduler, Observable, observeOn, of } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; -import { - ApolloClient, - CombinedGraphQLErrors, +import type { FetchPolicy, - NetworkStatus, OperationVariables, TypedDocumentNode, WatchQueryFetchPolicy, WatchQueryOptions, } from "@apollo/client/core"; +import { + ApolloClient, + CombinedGraphQLErrors, + NetworkStatus, +} from "@apollo/client/core"; import { ApolloLink } from "@apollo/client/link/core"; -import { Unmasked } from "@apollo/client/masking"; +import type { Unmasked } from "@apollo/client/masking"; import { ApolloProvider } from "@apollo/client/react/context"; import { useLazyQuery, useMutation, useQuery, } from "@apollo/client/react/hooks"; +import type { MockedResponse } from "@apollo/client/testing"; import { - MockedResponse, MockLink, mockSingleLink, MockSubscriptionLink, @@ -48,7 +52,8 @@ import { spyOnConsole, } from "@apollo/client/testing/internal"; import { MockedProvider } from "@apollo/client/testing/react"; -import { concatPagination, Reference } from "@apollo/client/utilities"; +import type { Reference } from "@apollo/client/utilities"; +import { concatPagination } from "@apollo/client/utilities"; import { InvariantError } from "@apollo/client/utilities/invariant"; import { mockFetchQuery } from "../../../core/__tests__/ObservableQuery.js"; diff --git a/src/react/hooks/__tests__/useQueryRefHandlers.test.tsx b/src/react/hooks/__tests__/useQueryRefHandlers.test.tsx index 8f7e3743c01..631332b2318 100644 --- a/src/react/hooks/__tests__/useQueryRefHandlers.test.tsx +++ b/src/react/hooks/__tests__/useQueryRefHandlers.test.tsx @@ -7,13 +7,13 @@ import { import { userEvent } from "@testing-library/user-event"; import React, { Suspense } from "react"; +import type { TypedDocumentNode } from "@apollo/client/core"; import { ApolloClient, gql, InMemoryCache, NetworkStatus, split, - TypedDocumentNode, } from "@apollo/client/core"; import { createQueryPreloader } from "@apollo/client/react"; import { @@ -22,22 +22,21 @@ import { useQueryRefHandlers, useReadQuery, } from "@apollo/client/react/hooks"; -import { QueryRef } from "@apollo/client/react/internal"; -import { - MockedResponse, - MockLink, - MockSubscriptionLink, -} from "@apollo/client/testing"; +import type { QueryRef } from "@apollo/client/react/internal"; +import type { MockedResponse } from "@apollo/client/testing"; +import { MockLink, MockSubscriptionLink } from "@apollo/client/testing"; +import type { + PaginatedCaseData, + SimpleCaseData, +} from "@apollo/client/testing/internal"; import { createClientWrapper, - PaginatedCaseData, setupPaginatedCase, setupSimpleCase, - SimpleCaseData, } from "@apollo/client/testing/internal"; import { concatPagination, getMainDefinition } from "@apollo/client/utilities"; -import { +import type { SubscribeToMoreFunction, SubscribeToMoreUpdateQueryFn, } from "../../../core/watchQueryOptions.js"; diff --git a/src/react/hooks/__tests__/useSubscription.test.tsx b/src/react/hooks/__tests__/useSubscription.test.tsx index f8fee49c81f..cc4487cb82f 100644 --- a/src/react/hooks/__tests__/useSubscription.test.tsx +++ b/src/react/hooks/__tests__/useSubscription.test.tsx @@ -4,30 +4,26 @@ import { renderHookToSnapshotStream, } from "@testing-library/react-render-stream"; import { expectTypeOf } from "expect-type"; -import { GraphQLFormattedError } from "graphql"; +import type { GraphQLFormattedError } from "graphql"; import { gql } from "graphql-tag"; import React from "react"; import { ErrorBoundary } from "react-error-boundary"; import { InMemoryCache as Cache } from "@apollo/client/cache"; -import { - ApolloClient, - ApolloLink, - concat, - TypedDocumentNode, -} from "@apollo/client/core"; +import type { TypedDocumentNode } from "@apollo/client/core"; +import { ApolloClient, ApolloLink, concat } from "@apollo/client/core"; import { CombinedGraphQLErrors, CombinedProtocolErrors, } from "@apollo/client/errors"; -import { Masked, MaskedDocumentNode } from "@apollo/client/masking"; +import type { Masked, MaskedDocumentNode } from "@apollo/client/masking"; import { ApolloProvider } from "@apollo/client/react/context"; import { useSubscription } from "@apollo/client/react/hooks"; import { MockSubscriptionLink, tick, wait } from "@apollo/client/testing"; import { mockMultipartSubscriptionStream } from "@apollo/client/testing/internal"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { MockedSubscriptionResult } from "../../../testing/core/mocking/mockSubscriptionLink.js"; +import type { MockedSubscriptionResult } from "../../../testing/core/mocking/mockSubscriptionLink.js"; const IS_REACT_17 = React.version.startsWith("17"); diff --git a/src/react/hooks/__tests__/useSuspenseFragment.test.tsx b/src/react/hooks/__tests__/useSuspenseFragment.test.tsx index c8e80192e74..d64df730cbe 100644 --- a/src/react/hooks/__tests__/useSuspenseFragment.test.tsx +++ b/src/react/hooks/__tests__/useSuspenseFragment.test.tsx @@ -9,17 +9,15 @@ import { userEvent } from "@testing-library/user-event"; import { expectTypeOf } from "expect-type"; import React, { Suspense } from "react"; -import { - ApolloClient, +import type { FragmentType, - gql, - InMemoryCache, Masked, MaskedDocumentNode, MaybeMasked, OperationVariables, TypedDocumentNode, } from "@apollo/client/core"; +import { ApolloClient, gql, InMemoryCache } from "@apollo/client/core"; import { ApolloProvider } from "@apollo/client/react/context"; import { useSuspenseFragment } from "@apollo/client/react/hooks"; import { MockSubscriptionLink, wait } from "@apollo/client/testing"; diff --git a/src/react/hooks/__tests__/useSuspenseQuery.test.tsx b/src/react/hooks/__tests__/useSuspenseQuery.test.tsx index 610be1e62b6..125ac8eae51 100644 --- a/src/react/hooks/__tests__/useSuspenseQuery.test.tsx +++ b/src/react/hooks/__tests__/useSuspenseQuery.test.tsx @@ -1,10 +1,5 @@ -import { - act, - renderHook, - RenderHookOptions, - screen, - waitFor, -} from "@testing-library/react"; +import type { RenderHookOptions } from "@testing-library/react"; +import { act, renderHook, screen, waitFor } from "@testing-library/react"; import { createRenderStream, disableActEnvironment, @@ -15,54 +10,60 @@ import { equal } from "@wry/equality"; import { expectTypeOf } from "expect-type"; import { GraphQLError } from "graphql"; import React, { Fragment, StrictMode, Suspense, useTransition } from "react"; -import { ErrorBoundary, FallbackProps } from "react-error-boundary"; +import type { FallbackProps } from "react-error-boundary"; +import { ErrorBoundary } from "react-error-boundary"; import { Observable, of } from "rxjs"; -import { +import type { ApolloCache, + DocumentNode, + ErrorPolicy, + OperationVariables, + QueryResult, + SubscribeToMoreOptions, + TypedDocumentNode, +} from "@apollo/client/core"; +import { ApolloClient, ApolloLink, CombinedGraphQLErrors, - DocumentNode, - ErrorPolicy, gql, InMemoryCache, NetworkStatus, - OperationVariables, - QueryResult, split, - SubscribeToMoreOptions, - TypedDocumentNode, } from "@apollo/client/core"; -import { Masked, MaskedDocumentNode, Unmasked } from "@apollo/client/masking"; +import type { + Masked, + MaskedDocumentNode, + Unmasked, +} from "@apollo/client/masking"; import { skipToken } from "@apollo/client/react"; import { ApolloProvider } from "@apollo/client/react/context"; import { useSuspenseQuery } from "@apollo/client/react/hooks"; -import { - MockedResponse, - MockLink, - MockSubscriptionLink, -} from "@apollo/client/testing"; -import { - actAsync, +import type { MockedResponse } from "@apollo/client/testing"; +import { MockLink, MockSubscriptionLink } from "@apollo/client/testing"; +import type { PaginatedCaseData, PaginatedCaseVariables, +} from "@apollo/client/testing/internal"; +import { + actAsync, renderAsync, renderHookAsync, setupPaginatedCase, spyOnConsole, } from "@apollo/client/testing/internal"; import { MockedProvider } from "@apollo/client/testing/react"; +import type { DeepPartial } from "@apollo/client/utilities"; import { compact, concatPagination, - DeepPartial, getMainDefinition, offsetLimitPagination, } from "@apollo/client/utilities"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { +import type { RefetchWritePolicy, WatchQueryFetchPolicy, } from "../../../core/watchQueryOptions.js"; diff --git a/src/react/internal/cache/__tests__/QueryReference.test.tsx b/src/react/internal/cache/__tests__/QueryReference.test.tsx index cc54ba471da..c368e9f3cf3 100644 --- a/src/react/internal/cache/__tests__/QueryReference.test.tsx +++ b/src/react/internal/cache/__tests__/QueryReference.test.tsx @@ -5,7 +5,7 @@ import { ApolloClient, ApolloLink, InMemoryCache } from "@apollo/client/core"; import { InternalQueryReference } from "@apollo/client/react/internal"; import { setupSimpleCase } from "@apollo/client/testing/internal"; -import { +import type { PreloadedQueryRef, QueryRef, QueryReference, diff --git a/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx b/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx index 7d20027613f..823b910e95d 100644 --- a/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx +++ b/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx @@ -11,6 +11,10 @@ import React, { Suspense } from "react"; import { ErrorBoundary } from "react-error-boundary"; import { Observable } from "rxjs"; +import type { + OperationVariables, + TypedDocumentNode, +} from "@apollo/client/core"; import { ApolloClient, ApolloLink, @@ -18,39 +22,33 @@ import { gql, InMemoryCache, NetworkStatus, - OperationVariables, - TypedDocumentNode, } from "@apollo/client/core"; -import { Masked } from "@apollo/client/masking"; +import type { Masked } from "@apollo/client/masking"; import { createQueryPreloader } from "@apollo/client/react"; import { ApolloProvider } from "@apollo/client/react/context"; import { useReadQuery } from "@apollo/client/react/hooks"; -import { +import type { PreloadedQueryRef, QueryRef, - unwrapQueryRef, } from "@apollo/client/react/internal"; -import { - MockedResponse, - MockLink, - MockSubscriptionLink, - wait, -} from "@apollo/client/testing"; +import { unwrapQueryRef } from "@apollo/client/react/internal"; +import type { MockedResponse } from "@apollo/client/testing"; +import { MockLink, MockSubscriptionLink, wait } from "@apollo/client/testing"; +import type { + SimpleCaseData, + VariablesCaseData, +} from "@apollo/client/testing/internal"; import { createClientWrapper, renderHookAsync, setupSimpleCase, setupVariablesCase, - SimpleCaseData, spyOnConsole, - VariablesCaseData, } from "@apollo/client/testing/internal"; -import { DeepPartial } from "@apollo/client/utilities"; +import type { DeepPartial } from "@apollo/client/utilities"; -import { - MaskedVariablesCaseData, - setupMaskedVariablesCase, -} from "../../../testing/internal/scenarios/index.js"; +import type { MaskedVariablesCaseData } from "../../../testing/internal/scenarios/index.js"; +import { setupMaskedVariablesCase } from "../../../testing/internal/scenarios/index.js"; function createDefaultClient(mocks: MockedResponse[]) { return new ApolloClient({ diff --git a/src/react/ssr/__tests__/getDataFromTree.test.tsx b/src/react/ssr/__tests__/getDataFromTree.test.tsx index 1ad472f9b3d..ccd9f1f0ed0 100644 --- a/src/react/ssr/__tests__/getDataFromTree.test.tsx +++ b/src/react/ssr/__tests__/getDataFromTree.test.tsx @@ -1,14 +1,11 @@ import "../../../testing/internal/messageChannelPolyfill.js"; -import { DocumentNode } from "graphql"; +import type { DocumentNode } from "graphql"; import { gql } from "graphql-tag"; import React from "react"; import { InMemoryCache as Cache } from "@apollo/client/cache"; -import { - ApolloClient, - CombinedGraphQLErrors, - TypedDocumentNode, -} from "@apollo/client/core"; +import type { TypedDocumentNode } from "@apollo/client/core"; +import { ApolloClient, CombinedGraphQLErrors } from "@apollo/client/core"; import { ApolloProvider, getApolloContext } from "@apollo/client/react/context"; import { useQuery } from "@apollo/client/react/hooks"; import { getDataFromTree } from "@apollo/client/react/ssr"; diff --git a/src/react/ssr/__tests__/prerenderStatic.test.tsx b/src/react/ssr/__tests__/prerenderStatic.test.tsx index f14ddb062a2..5ec949a1c54 100644 --- a/src/react/ssr/__tests__/prerenderStatic.test.tsx +++ b/src/react/ssr/__tests__/prerenderStatic.test.tsx @@ -11,12 +11,12 @@ import { renderToStaticMarkup, renderToString } from "react-dom/server"; import { prerender } from "react-dom/static"; import { prerenderToNodeStream } from "react-dom/static.node"; +import type { TypedDocumentNode } from "@apollo/client/core"; import { ApolloClient, ApolloLink, gql, InMemoryCache, - TypedDocumentNode, } from "@apollo/client/core"; import { ApolloProvider, @@ -25,12 +25,8 @@ import { useSuspenseQuery, } from "@apollo/client/react"; import { prerenderStatic } from "@apollo/client/react/ssr"; -import { - MockedResponse, - MockLink, - MockSubscriptionLink, - wait, -} from "@apollo/client/testing"; +import type { MockedResponse } from "@apollo/client/testing"; +import { MockLink, MockSubscriptionLink, wait } from "@apollo/client/testing"; import { InvariantError } from "@apollo/client/utilities/invariant"; import { resetApolloContext } from "../../../testing/internal/resetApolloContext.js"; diff --git a/src/react/ssr/__tests__/useQuery.test.tsx b/src/react/ssr/__tests__/useQuery.test.tsx index a6e2ace5ca2..c64c9a9b527 100644 --- a/src/react/ssr/__tests__/useQuery.test.tsx +++ b/src/react/ssr/__tests__/useQuery.test.tsx @@ -4,14 +4,16 @@ import React from "react"; import { renderToStaticMarkup, renderToString } from "react-dom/server"; import { InMemoryCache } from "@apollo/client/cache"; -import { ApolloClient, TypedDocumentNode } from "@apollo/client/core"; +import type { TypedDocumentNode } from "@apollo/client/core"; +import { ApolloClient } from "@apollo/client/core"; import { ApolloProvider } from "@apollo/client/react/context"; import { useApolloClient, useQuery } from "@apollo/client/react/hooks"; import { prerenderStatic, renderToStringWithData, } from "@apollo/client/react/ssr"; -import { MockedResponse, mockSingleLink } from "@apollo/client/testing"; +import type { MockedResponse } from "@apollo/client/testing"; +import { mockSingleLink } from "@apollo/client/testing"; import { MockedProvider } from "@apollo/client/testing/react"; import { resetApolloContext } from "../../../testing/internal/resetApolloContext.js"; diff --git a/src/testing/core/mocking/__tests__/mockLink.ts b/src/testing/core/mocking/__tests__/mockLink.ts index 99d94e54c01..8a4775baedc 100644 --- a/src/testing/core/mocking/__tests__/mockLink.ts +++ b/src/testing/core/mocking/__tests__/mockLink.ts @@ -7,7 +7,8 @@ import { spyOnConsole, } from "@apollo/client/testing/internal"; -import { MockedResponse, MockLink } from "../mockLink.js"; +import type { MockedResponse } from "../mockLink.js"; +import { MockLink } from "../mockLink.js"; describe("MockedResponse.newData", () => { const setup = () => { diff --git a/src/testing/experimental/__tests__/createTestSchema.test.tsx b/src/testing/experimental/__tests__/createTestSchema.test.tsx index a79f11eeedb..84b8bebd8d5 100644 --- a/src/testing/experimental/__tests__/createTestSchema.test.tsx +++ b/src/testing/experimental/__tests__/createTestSchema.test.tsx @@ -1,16 +1,14 @@ import { screen } from "@testing-library/react"; +import type { RenderStream } from "@testing-library/react-render-stream"; import { createRenderStream, disableActEnvironment, - RenderStream, } from "@testing-library/react-render-stream"; import { userEvent } from "@testing-library/user-event"; import { buildSchema } from "graphql"; import * as React from "react"; -import { - ErrorBoundary as ReactErrorBoundary, - FallbackProps, -} from "react-error-boundary"; +import type { FallbackProps } from "react-error-boundary"; +import { ErrorBoundary as ReactErrorBoundary } from "react-error-boundary"; import type { TypedDocumentNode } from "@apollo/client/core"; import { diff --git a/src/testing/react/__tests__/MockedProvider.test.tsx b/src/testing/react/__tests__/MockedProvider.test.tsx index ef77da7f618..feb878a911d 100644 --- a/src/testing/react/__tests__/MockedProvider.test.tsx +++ b/src/testing/react/__tests__/MockedProvider.test.tsx @@ -1,13 +1,15 @@ import { act, render, screen, waitFor } from "@testing-library/react"; -import { DocumentNode } from "graphql"; +import type { DocumentNode } from "graphql"; import { gql } from "graphql-tag"; import React from "react"; -import { Observable } from "rxjs"; +import type { Observable } from "rxjs"; import { InMemoryCache } from "@apollo/client/cache"; -import { ApolloLink, FetchResult } from "@apollo/client/link/core"; +import type { FetchResult } from "@apollo/client/link/core"; +import { ApolloLink } from "@apollo/client/link/core"; import { useQuery } from "@apollo/client/react"; -import { MockedResponse, MockLink } from "@apollo/client/testing/core"; +import type { MockedResponse } from "@apollo/client/testing/core"; +import { MockLink } from "@apollo/client/testing/core"; import { MockedProvider } from "../MockedProvider.js"; diff --git a/src/utilities/graphql/__tests__/DocumentTransform.ts b/src/utilities/graphql/__tests__/DocumentTransform.ts index 815d96be7eb..eb87dc954bb 100644 --- a/src/utilities/graphql/__tests__/DocumentTransform.ts +++ b/src/utilities/graphql/__tests__/DocumentTransform.ts @@ -1,4 +1,5 @@ -import { DocumentNode, Kind, visit } from "graphql"; +import type { DocumentNode } from "graphql"; +import { Kind, visit } from "graphql"; import { gql } from "graphql-tag"; import { diff --git a/src/utilities/graphql/__tests__/fragments.ts b/src/utilities/graphql/__tests__/fragments.ts index a691045aa8a..060fc125256 100644 --- a/src/utilities/graphql/__tests__/fragments.ts +++ b/src/utilities/graphql/__tests__/fragments.ts @@ -10,7 +10,7 @@ import { getFragmentQueryDocument, } from "@apollo/client/utilities"; -import { FragmentMap } from "../fragments.js"; +import type { FragmentMap } from "../fragments.js"; describe("getFragmentQueryDocument", () => { it("will throw an error if there is an operation", () => { diff --git a/src/utilities/graphql/__tests__/getFromAST.ts b/src/utilities/graphql/__tests__/getFromAST.ts index 0168d9c51a4..bd1204a038d 100644 --- a/src/utilities/graphql/__tests__/getFromAST.ts +++ b/src/utilities/graphql/__tests__/getFromAST.ts @@ -1,8 +1,5 @@ -import { - FragmentDefinitionNode, - OperationDefinitionNode, - print, -} from "graphql"; +import type { FragmentDefinitionNode, OperationDefinitionNode } from "graphql"; +import { print } from "graphql"; import { gql } from "graphql-tag"; import { diff --git a/src/utilities/graphql/__tests__/transform.ts b/src/utilities/graphql/__tests__/transform.ts index 0fc2887937d..3aa51241f68 100644 --- a/src/utilities/graphql/__tests__/transform.ts +++ b/src/utilities/graphql/__tests__/transform.ts @@ -1,4 +1,5 @@ -import { DocumentNode, Kind, print } from "graphql"; +import type { DocumentNode } from "graphql"; +import { Kind, print } from "graphql"; import { disableFragmentWarnings, gql } from "graphql-tag"; // Turn off warnings for repeated fragment names diff --git a/src/utilities/policies/__tests__/relayStylePagination.test.ts b/src/utilities/policies/__tests__/relayStylePagination.test.ts index f8f6b645345..54be5928301 100644 --- a/src/utilities/policies/__tests__/relayStylePagination.test.ts +++ b/src/utilities/policies/__tests__/relayStylePagination.test.ts @@ -1,13 +1,12 @@ +import type { FieldFunctionOptions, StoreObject } from "@apollo/client/cache"; import { - FieldFunctionOptions, InMemoryCache, isReference, makeReference, - StoreObject, } from "@apollo/client/cache"; import { relayStylePagination } from "@apollo/client/utilities"; -import { TRelayPageInfo } from "../pagination.js"; +import type { TRelayPageInfo } from "../pagination.js"; describe("relayStylePagination", () => { const policy = relayStylePagination(); From a4bbf0b6223eb230e1f7aa35aef610b81de5b772 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 2 Apr 2025 16:26:56 +0200 Subject: [PATCH 3/6] import from entry points where possible, ignore lint rule otherwise --- src/__tests__/exports.ts | 1 + src/__tests__/local-state/resolvers.ts | 2 ++ src/cache/inmemory/__tests__/cache.ts | 4 ++++ src/cache/inmemory/__tests__/diffAgainstStore.ts | 4 ++++ src/cache/inmemory/__tests__/entityStore.ts | 2 ++ src/cache/inmemory/__tests__/fragmentMatcher.ts | 4 +--- src/cache/inmemory/__tests__/key-extractor.ts | 2 ++ src/cache/inmemory/__tests__/readFromStore.ts | 2 ++ src/cache/inmemory/__tests__/roundtrip.ts | 4 ++++ src/cache/inmemory/__tests__/writeToStore.ts | 4 ++++ src/core/__tests__/ApolloClient/general.test.ts | 9 +++------ src/core/__tests__/equalByQuery.ts | 2 ++ src/link/retry/__tests__/delayFunction.ts | 2 ++ src/link/retry/__tests__/retryFunction.ts | 2 ++ src/masking/__tests__/maskFragment.test.ts | 2 ++ src/masking/__tests__/maskOperation.test.ts | 2 ++ .../hooks/__tests__/useBackgroundQuery.test.tsx | 2 +- src/react/hooks/__tests__/useQuery.test.tsx | 13 +++++++++---- .../hooks/internal/__tests__/useDeepMemo.test.ts | 2 ++ .../internal/__tests__/useRenderGuard.test.tsx | 2 ++ .../__tests__/createQueryPreloader.test.tsx | 5 ++--- src/react/ssr/__tests__/getDataFromTree.test.tsx | 2 ++ src/react/ssr/__tests__/prerenderStatic.test.tsx | 5 +++-- src/react/ssr/__tests__/useQuery.test.tsx | 3 +-- src/testing/core/mocking/__tests__/mockLink.ts | 5 ++--- .../__tests__/createTestSchema.test.tsx | 7 ++++--- .../internal/__tests__/ObservableStream.test.ts | 2 +- .../disposables/__tests__/spyOnConsole.test.ts | 2 +- .../disposables/__tests__/withCleanup.test.ts | 2 +- src/testing/internal/index.ts | 2 ++ src/testing/react/__tests__/MockedProvider.test.tsx | 3 +-- .../caching/__tests__/getMemoryInternals.ts | 3 ++- 32 files changed, 75 insertions(+), 33 deletions(-) diff --git a/src/__tests__/exports.ts b/src/__tests__/exports.ts index 34ea8f54f1d..c981fa15d34 100644 --- a/src/__tests__/exports.ts +++ b/src/__tests__/exports.ts @@ -42,6 +42,7 @@ import * as utilitiesGlobals from "@apollo/client/utilities/globals"; import * as utilitiesInternal from "@apollo/client/utilities/internal"; import * as utilitiesInvariant from "@apollo/client/utilities/invariant"; +// eslint-disable-next-line local-rules/no-relative-imports import { entryPoints } from "../../config/entryPoints.js"; type Namespace = object; diff --git a/src/__tests__/local-state/resolvers.ts b/src/__tests__/local-state/resolvers.ts index 895291b112d..7eae74c8d82 100644 --- a/src/__tests__/local-state/resolvers.ts +++ b/src/__tests__/local-state/resolvers.ts @@ -9,6 +9,8 @@ import { ApolloLink } from "@apollo/client/link/core"; import { MockLink } from "@apollo/client/testing"; import { ObservableStream } from "@apollo/client/testing/internal"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { LocalState } from "../../core/LocalState.js"; const setupTestWithResolvers = ({ diff --git a/src/cache/inmemory/__tests__/cache.ts b/src/cache/inmemory/__tests__/cache.ts index 95a7e3fa3b4..f171ee11a3f 100644 --- a/src/cache/inmemory/__tests__/cache.ts +++ b/src/cache/inmemory/__tests__/cache.ts @@ -12,8 +12,12 @@ import { isReference, makeReference, makeVar } from "@apollo/client/core"; import { spyOnConsole } from "@apollo/client/testing/internal"; import { cloneDeep, defaultCacheSizes } from "@apollo/client/utilities"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { StoreReader } from "../readFromStore.js"; import type { InMemoryCacheConfig } from "../types.js"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { StoreWriter } from "../writeToStore.js"; disableFragmentWarnings(); diff --git a/src/cache/inmemory/__tests__/diffAgainstStore.ts b/src/cache/inmemory/__tests__/diffAgainstStore.ts index 0275f24f4a4..47b2442d5f1 100644 --- a/src/cache/inmemory/__tests__/diffAgainstStore.ts +++ b/src/cache/inmemory/__tests__/diffAgainstStore.ts @@ -3,8 +3,12 @@ import { disableFragmentWarnings, gql } from "graphql-tag"; import { defaultDataIdFromObject, InMemoryCache } from "@apollo/client/cache"; import { MissingFieldError } from "@apollo/client/core"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { StoreReader } from "../readFromStore.js"; import type { NormalizedCache, Reference } from "../types.js"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { StoreWriter } from "../writeToStore.js"; import { diff --git a/src/cache/inmemory/__tests__/entityStore.ts b/src/cache/inmemory/__tests__/entityStore.ts index 8a8181a7444..68990cc14a7 100644 --- a/src/cache/inmemory/__tests__/entityStore.ts +++ b/src/cache/inmemory/__tests__/entityStore.ts @@ -21,6 +21,8 @@ import type { StoreValue, } from "../../../utilities/graphql/storeUtils.js"; import type { Cache } from "../../core/types/Cache.js"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { supportsResultCaching } from "../entityStore.js"; import type { StoreObject } from "../types.js"; diff --git a/src/cache/inmemory/__tests__/fragmentMatcher.ts b/src/cache/inmemory/__tests__/fragmentMatcher.ts index f5534dab1e3..0f43c536187 100644 --- a/src/cache/inmemory/__tests__/fragmentMatcher.ts +++ b/src/cache/inmemory/__tests__/fragmentMatcher.ts @@ -4,8 +4,6 @@ import { gql } from "graphql-tag"; import { InMemoryCache } from "@apollo/client/cache"; -import { hasOwn } from "../helpers.js"; - describe("fragment matching", () => { it("can match exact types with or without possibleTypes", () => { const cacheWithoutPossibleTypes = new InMemoryCache(); @@ -283,7 +281,7 @@ describe("policies.fragmentMatches", () => { const supertype = frag.typeCondition.name.value; expect("ABCDEF".split("")).toContain(supertype); - if (hasOwn.call(expected, supertype)) { + if (expected.hasOwnProperty(supertype)) { Object.keys(expected[supertype]).forEach((subtype) => { check(subtype, expected[supertype][subtype]); }); diff --git a/src/cache/inmemory/__tests__/key-extractor.ts b/src/cache/inmemory/__tests__/key-extractor.ts index bcd984ac6f1..19074281691 100644 --- a/src/cache/inmemory/__tests__/key-extractor.ts +++ b/src/cache/inmemory/__tests__/key-extractor.ts @@ -4,6 +4,8 @@ import { collectSpecifierPaths, extractKeyPath, getSpecifierPaths, + // not exported + // eslint-disable-next-line local-rules/no-relative-imports } from "../key-extractor.js"; import type { KeySpecifier } from "../policies.js"; diff --git a/src/cache/inmemory/__tests__/readFromStore.ts b/src/cache/inmemory/__tests__/readFromStore.ts index 96996e23ceb..cca9d118ee7 100644 --- a/src/cache/inmemory/__tests__/readFromStore.ts +++ b/src/cache/inmemory/__tests__/readFromStore.ts @@ -7,6 +7,8 @@ import { isReference, makeReference } from "@apollo/client/core"; import { defaultCacheSizes } from "@apollo/client/utilities"; import type { Cache } from "../../core/types/Cache.js"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { StoreReader } from "../readFromStore.js"; import type { StoreObject } from "../types.js"; diff --git a/src/cache/inmemory/__tests__/roundtrip.ts b/src/cache/inmemory/__tests__/roundtrip.ts index aa58430940f..7fb629ec444 100644 --- a/src/cache/inmemory/__tests__/roundtrip.ts +++ b/src/cache/inmemory/__tests__/roundtrip.ts @@ -5,7 +5,11 @@ import { EntityStore, InMemoryCache } from "@apollo/client/cache"; import { spyOnConsole } from "@apollo/client/testing/internal"; import { __DEV__ } from "@apollo/client/utilities/environment"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { StoreReader } from "../readFromStore.js"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { StoreWriter } from "../writeToStore.js"; import { readQueryFromStore, withError, writeQueryToStore } from "./helpers.js"; diff --git a/src/cache/inmemory/__tests__/writeToStore.ts b/src/cache/inmemory/__tests__/writeToStore.ts index 3e66f5b6ea8..9c1c27430c8 100644 --- a/src/cache/inmemory/__tests__/writeToStore.ts +++ b/src/cache/inmemory/__tests__/writeToStore.ts @@ -23,8 +23,12 @@ import { } from "@apollo/client/utilities"; import { invariant } from "@apollo/client/utilities/invariant"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { extractFragmentContext } from "../helpers.js"; import type { KeyFieldsFunction } from "../policies.js"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { StoreWriter } from "../writeToStore.js"; import { defaultNormalizedCacheFactory, writeQueryToStore } from "./helpers.js"; diff --git a/src/core/__tests__/ApolloClient/general.test.ts b/src/core/__tests__/ApolloClient/general.test.ts index a6a6abe366b..aa1f97da4a1 100644 --- a/src/core/__tests__/ApolloClient/general.test.ts +++ b/src/core/__tests__/ApolloClient/general.test.ts @@ -9,11 +9,9 @@ import { InMemoryCache } from "@apollo/client/cache"; import type { ApolloQueryResult } from "@apollo/client/core"; import { ApolloClient, NetworkStatus } from "@apollo/client/core"; import { CombinedGraphQLErrors } from "@apollo/client/errors"; -import type { - ApolloLink, - FetchResult, - type RequestHandler, -} from "@apollo/client/link/core"; +import type { FetchResult, RequestHandler } from "@apollo/client/link/core"; +import { ApolloLink } from "@apollo/client/link/core"; +import { MockLink } from "@apollo/client/testing"; import { wait } from "@apollo/client/testing/core"; import { mockDeferStream, @@ -27,7 +25,6 @@ import { } from "@apollo/client/utilities/invariant"; import type { MockApolloLink } from "../../../testing/core/mocking/mockLink.js"; -import { MockLink } from "../../../testing/core/mocking/mockLink.js"; import type { QueryManager } from "../../QueryManager.js"; import type { WatchQueryFetchPolicy, diff --git a/src/core/__tests__/equalByQuery.ts b/src/core/__tests__/equalByQuery.ts index 89685606fa1..abec4f44d88 100644 --- a/src/core/__tests__/equalByQuery.ts +++ b/src/core/__tests__/equalByQuery.ts @@ -3,6 +3,8 @@ import { GraphQLError } from "graphql"; import type { TypedDocumentNode } from "@apollo/client/core"; import { CombinedGraphQLErrors, gql } from "@apollo/client/core"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { equalByQuery } from "../equalByQuery.js"; describe("equalByQuery", () => { diff --git a/src/link/retry/__tests__/delayFunction.ts b/src/link/retry/__tests__/delayFunction.ts index d63be510c12..bb1f9c00ace 100644 --- a/src/link/retry/__tests__/delayFunction.ts +++ b/src/link/retry/__tests__/delayFunction.ts @@ -1,3 +1,5 @@ +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { buildDelayFunction } from "../delayFunction.js"; describe("buildDelayFunction", () => { diff --git a/src/link/retry/__tests__/retryFunction.ts b/src/link/retry/__tests__/retryFunction.ts index 414bffa4f02..7a9b49bab1d 100644 --- a/src/link/retry/__tests__/retryFunction.ts +++ b/src/link/retry/__tests__/retryFunction.ts @@ -1,4 +1,6 @@ import type { Operation } from "../../core/types.js"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { buildRetryFunction } from "../retryFunction.js"; describe("buildRetryFunction", () => { diff --git a/src/masking/__tests__/maskFragment.test.ts b/src/masking/__tests__/maskFragment.test.ts index 27c42b298ef..6ba684c40dd 100644 --- a/src/masking/__tests__/maskFragment.test.ts +++ b/src/masking/__tests__/maskFragment.test.ts @@ -3,6 +3,8 @@ import { maskFragment } from "@apollo/client/masking"; import { spyOnConsole } from "@apollo/client/testing/internal"; import { InvariantError } from "@apollo/client/utilities/invariant"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { deepFreeze } from "../../utilities/common/maybeDeepFreeze.js"; test("returns null when data is null", () => { diff --git a/src/masking/__tests__/maskOperation.test.ts b/src/masking/__tests__/maskOperation.test.ts index ca00b753116..f62336e24bf 100644 --- a/src/masking/__tests__/maskOperation.test.ts +++ b/src/masking/__tests__/maskOperation.test.ts @@ -4,6 +4,8 @@ import { spyOnConsole, withProdMode } from "@apollo/client/testing/internal"; import { __DEV__ } from "@apollo/client/utilities/environment"; import { InvariantError } from "@apollo/client/utilities/invariant"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { deepFreeze } from "../../utilities/common/maybeDeepFreeze.js"; test("throws when passing document with no operation to maskOperation", () => { diff --git a/src/react/hooks/__tests__/useBackgroundQuery.test.tsx b/src/react/hooks/__tests__/useBackgroundQuery.test.tsx index 4db0eb5656a..6c819bed675 100644 --- a/src/react/hooks/__tests__/useBackgroundQuery.test.tsx +++ b/src/react/hooks/__tests__/useBackgroundQuery.test.tsx @@ -49,6 +49,7 @@ import { addDelayToMocks, createClientWrapper, createMockWrapper, + setupMaskedVariablesCase, setupPaginatedCase, setupSimpleCase, setupVariablesCase, @@ -71,7 +72,6 @@ import type { MaskedVariablesCaseData, UnmaskedVariablesCaseData, } from "../../../testing/internal/scenarios/index.js"; -import { setupMaskedVariablesCase } from "../../../testing/internal/scenarios/index.js"; afterEach(() => { jest.useRealTimers(); diff --git a/src/react/hooks/__tests__/useQuery.test.tsx b/src/react/hooks/__tests__/useQuery.test.tsx index b4fc8911420..02a38eacbd6 100644 --- a/src/react/hooks/__tests__/useQuery.test.tsx +++ b/src/react/hooks/__tests__/useQuery.test.tsx @@ -56,7 +56,7 @@ import type { Reference } from "@apollo/client/utilities"; import { concatPagination } from "@apollo/client/utilities"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { mockFetchQuery } from "../../../core/__tests__/ObservableQuery.js"; +import type { QueryManager } from "../../../core/QueryManager.js"; const IS_REACT_17 = React.version.startsWith("17"); const IS_REACT_18 = React.version.startsWith("18"); @@ -7389,14 +7389,19 @@ describe("useQuery Hook", () => { link, }); - const mocks = mockFetchQuery(client["queryManager"]); + const fetchQueryByPolicy = jest.spyOn( + client["queryManager"] as any as { + fetchQueryByPolicy: QueryManager["fetchQueryByPolicy"]; + }, + "fetchQueryByPolicy" + ); const expectQueryTriggered = ( nth: number, fetchPolicy: WatchQueryFetchPolicy ) => { - expect(mocks.fetchQueryByPolicy).toHaveBeenCalledTimes(nth); - expect(mocks.fetchQueryByPolicy).toHaveBeenNthCalledWith( + expect(fetchQueryByPolicy).toHaveBeenCalledTimes(nth); + expect(fetchQueryByPolicy).toHaveBeenNthCalledWith( nth, expect.anything(), expect.objectContaining({ fetchPolicy }), diff --git a/src/react/hooks/internal/__tests__/useDeepMemo.test.ts b/src/react/hooks/internal/__tests__/useDeepMemo.test.ts index cb95af88e41..fb19c4e444e 100644 --- a/src/react/hooks/internal/__tests__/useDeepMemo.test.ts +++ b/src/react/hooks/internal/__tests__/useDeepMemo.test.ts @@ -1,5 +1,7 @@ import { renderHook } from "@testing-library/react"; +//not exported +// eslint-disable-next-line local-rules/no-relative-imports import { useDeepMemo } from "../useDeepMemo.js"; describe("useDeepMemo", () => { diff --git a/src/react/hooks/internal/__tests__/useRenderGuard.test.tsx b/src/react/hooks/internal/__tests__/useRenderGuard.test.tsx index 11b45c8b85b..411577ed2dd 100644 --- a/src/react/hooks/internal/__tests__/useRenderGuard.test.tsx +++ b/src/react/hooks/internal/__tests__/useRenderGuard.test.tsx @@ -2,6 +2,8 @@ import { render, waitFor } from "@testing-library/react"; import * as React from "react"; +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import { useRenderGuard } from "../useRenderGuard.js"; const UNDEF = {}; diff --git a/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx b/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx index 823b910e95d..494ceb7e2f9 100644 --- a/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx +++ b/src/react/query-preloader/__tests__/createQueryPreloader.test.tsx @@ -35,21 +35,20 @@ import { unwrapQueryRef } from "@apollo/client/react/internal"; import type { MockedResponse } from "@apollo/client/testing"; import { MockLink, MockSubscriptionLink, wait } from "@apollo/client/testing"; import type { + MaskedVariablesCaseData, SimpleCaseData, VariablesCaseData, } from "@apollo/client/testing/internal"; import { createClientWrapper, renderHookAsync, + setupMaskedVariablesCase, setupSimpleCase, setupVariablesCase, spyOnConsole, } from "@apollo/client/testing/internal"; import type { DeepPartial } from "@apollo/client/utilities"; -import type { MaskedVariablesCaseData } from "../../../testing/internal/scenarios/index.js"; -import { setupMaskedVariablesCase } from "../../../testing/internal/scenarios/index.js"; - function createDefaultClient(mocks: MockedResponse[]) { return new ApolloClient({ cache: new InMemoryCache(), diff --git a/src/react/ssr/__tests__/getDataFromTree.test.tsx b/src/react/ssr/__tests__/getDataFromTree.test.tsx index ccd9f1f0ed0..db4d108d77d 100644 --- a/src/react/ssr/__tests__/getDataFromTree.test.tsx +++ b/src/react/ssr/__tests__/getDataFromTree.test.tsx @@ -1,3 +1,5 @@ +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import "../../../testing/internal/messageChannelPolyfill.js"; import type { DocumentNode } from "graphql"; import { gql } from "graphql-tag"; diff --git a/src/react/ssr/__tests__/prerenderStatic.test.tsx b/src/react/ssr/__tests__/prerenderStatic.test.tsx index 5ec949a1c54..2bab86fca45 100644 --- a/src/react/ssr/__tests__/prerenderStatic.test.tsx +++ b/src/react/ssr/__tests__/prerenderStatic.test.tsx @@ -1,4 +1,6 @@ /* eslint-disable testing-library/render-result-naming-convention */ +// not exported +// eslint-disable-next-line local-rules/no-relative-imports import "../../../testing/internal/messageChannelPolyfill.js"; import "./polyfillReactDomTypes.d.ts"; @@ -27,10 +29,9 @@ import { import { prerenderStatic } from "@apollo/client/react/ssr"; import type { MockedResponse } from "@apollo/client/testing"; import { MockLink, MockSubscriptionLink, wait } from "@apollo/client/testing"; +import { resetApolloContext } from "@apollo/client/testing/internal"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { resetApolloContext } from "../../../testing/internal/resetApolloContext.js"; - beforeEach(() => { // We are running tests with multiple different renderers, and that can result in a warning like // > Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported. diff --git a/src/react/ssr/__tests__/useQuery.test.tsx b/src/react/ssr/__tests__/useQuery.test.tsx index c64c9a9b527..2f2263ac8bc 100644 --- a/src/react/ssr/__tests__/useQuery.test.tsx +++ b/src/react/ssr/__tests__/useQuery.test.tsx @@ -14,10 +14,9 @@ import { } from "@apollo/client/react/ssr"; import type { MockedResponse } from "@apollo/client/testing"; import { mockSingleLink } from "@apollo/client/testing"; +import { resetApolloContext } from "@apollo/client/testing/internal"; import { MockedProvider } from "@apollo/client/testing/react"; -import { resetApolloContext } from "../../../testing/internal/resetApolloContext.js"; - beforeEach(() => { // We are running tests with multiple different renderers, and that can result in a warning like // > Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported. diff --git a/src/testing/core/mocking/__tests__/mockLink.ts b/src/testing/core/mocking/__tests__/mockLink.ts index 8a4775baedc..cd58d993b1c 100644 --- a/src/testing/core/mocking/__tests__/mockLink.ts +++ b/src/testing/core/mocking/__tests__/mockLink.ts @@ -1,15 +1,14 @@ import { gql } from "graphql-tag"; import { execute } from "@apollo/client/link/core"; +import type { MockedResponse } from "@apollo/client/testing"; +import { MockLink } from "@apollo/client/testing"; import { enableFakeTimers, ObservableStream, spyOnConsole, } from "@apollo/client/testing/internal"; -import type { MockedResponse } from "../mockLink.js"; -import { MockLink } from "../mockLink.js"; - describe("MockedResponse.newData", () => { const setup = () => { const weaklyTypedMockResponse: MockedResponse = { diff --git a/src/testing/experimental/__tests__/createTestSchema.test.tsx b/src/testing/experimental/__tests__/createTestSchema.test.tsx index 84b8bebd8d5..1baad944581 100644 --- a/src/testing/experimental/__tests__/createTestSchema.test.tsx +++ b/src/testing/experimental/__tests__/createTestSchema.test.tsx @@ -19,15 +19,16 @@ import { } from "@apollo/client/core"; import type { UseSuspenseQueryResult } from "@apollo/client/react"; import { useMutation, useSuspenseQuery } from "@apollo/client/react"; +import { + createSchemaFetch, + createTestSchema, +} from "@apollo/client/testing/experimental"; import { createClientWrapper, spyOnConsole, } from "@apollo/client/testing/internal"; import { InvariantError } from "@apollo/client/utilities/invariant"; -import { createSchemaFetch } from "../createSchemaFetch.js"; -import { createTestSchema } from "../createTestSchema.js"; - const IS_REACT_19 = React.version.startsWith("19"); const typeDefs = /* GraphQL */ ` diff --git a/src/testing/internal/__tests__/ObservableStream.test.ts b/src/testing/internal/__tests__/ObservableStream.test.ts index 2add7918ec5..54348b547e2 100644 --- a/src/testing/internal/__tests__/ObservableStream.test.ts +++ b/src/testing/internal/__tests__/ObservableStream.test.ts @@ -1,6 +1,6 @@ import { Observable } from "rxjs"; -import { ObservableStream } from "../ObservableStream.js"; +import { ObservableStream } from "@apollo/client/testing/internal"; it("allows to step through an observable until completion", async () => { const stream = new ObservableStream( diff --git a/src/testing/internal/disposables/__tests__/spyOnConsole.test.ts b/src/testing/internal/disposables/__tests__/spyOnConsole.test.ts index 44a356b9ac6..6ecf23780ba 100644 --- a/src/testing/internal/disposables/__tests__/spyOnConsole.test.ts +++ b/src/testing/internal/disposables/__tests__/spyOnConsole.test.ts @@ -1,4 +1,4 @@ -import { spyOnConsole } from "../index.js"; +import { spyOnConsole } from "@apollo/client/testing/internal"; const originalLog = console.log; const originalWarn = console.warn; diff --git a/src/testing/internal/disposables/__tests__/withCleanup.test.ts b/src/testing/internal/disposables/__tests__/withCleanup.test.ts index dc7fa965754..5a1ac8eedf0 100644 --- a/src/testing/internal/disposables/__tests__/withCleanup.test.ts +++ b/src/testing/internal/disposables/__tests__/withCleanup.test.ts @@ -1,4 +1,4 @@ -import { withCleanup } from "../index.js"; +import { withCleanup } from "@apollo/client/testing/internal"; describe("withCleanup", () => { it("calls cleanup", () => { let cleanedUp = false; diff --git a/src/testing/internal/index.ts b/src/testing/internal/index.ts index f38c071cf10..5851ff32860 100644 --- a/src/testing/internal/index.ts +++ b/src/testing/internal/index.ts @@ -7,6 +7,7 @@ export { export { ObservableStream } from "./ObservableStream.js"; export type { + MaskedVariablesCaseData, PaginatedCaseData, PaginatedCaseVariables, SimpleCaseData, @@ -15,6 +16,7 @@ export type { } from "./scenarios/index.js"; export { addDelayToMocks, + setupMaskedVariablesCase, setupPaginatedCase, setupSimpleCase, setupVariablesCase, diff --git a/src/testing/react/__tests__/MockedProvider.test.tsx b/src/testing/react/__tests__/MockedProvider.test.tsx index feb878a911d..ef0559848a2 100644 --- a/src/testing/react/__tests__/MockedProvider.test.tsx +++ b/src/testing/react/__tests__/MockedProvider.test.tsx @@ -10,8 +10,7 @@ import { ApolloLink } from "@apollo/client/link/core"; import { useQuery } from "@apollo/client/react"; import type { MockedResponse } from "@apollo/client/testing/core"; import { MockLink } from "@apollo/client/testing/core"; - -import { MockedProvider } from "../MockedProvider.js"; +import { MockedProvider } from "@apollo/client/testing/react"; const variables = { username: "mock_username", diff --git a/src/utilities/caching/__tests__/getMemoryInternals.ts b/src/utilities/caching/__tests__/getMemoryInternals.ts index fc82f5b02db..03900b5ad18 100644 --- a/src/utilities/caching/__tests__/getMemoryInternals.ts +++ b/src/utilities/caching/__tests__/getMemoryInternals.ts @@ -10,11 +10,12 @@ import { } from "@apollo/client/core"; import { createPersistedQueryLink } from "@apollo/client/link/persisted-queries"; import { removeTypenameFromVariables } from "@apollo/client/link/remove-typename"; - // importing react so the `parser` cache initializes import "@apollo/client/react"; import { cacheSizes } from "@apollo/client/utilities"; +// this is compiled away so we need to import it from sources +// eslint-disable-next-line local-rules/no-relative-imports import { defaultCacheSizes } from "../sizes.js"; function sha256(data: string) { From e62573c2ff05c8a0f29dde0db0d359dbe1535370 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 2 Apr 2025 16:27:35 +0200 Subject: [PATCH 4/6] add `"local-rules/no-relative-imports"` lint rule --- eslint-local-rules/import-from-export.ts | 57 ++++++++++++++++++++++++ eslint-local-rules/index.mjs | 2 + eslint.config.mjs | 21 +++++---- package.json | 1 + 4 files changed, 72 insertions(+), 9 deletions(-) diff --git a/eslint-local-rules/import-from-export.ts b/eslint-local-rules/import-from-export.ts index 595f90a1561..b5b9bd861e6 100644 --- a/eslint-local-rules/import-from-export.ts +++ b/eslint-local-rules/import-from-export.ts @@ -265,3 +265,60 @@ export const noInternalImportOfficialExport = }, defaultOptions: [], }); + +/** + * to be used in tests, so the test imports from the library instead of testing internals + * (where possible) + */ +export const noRelativeImports = ESLintUtils.RuleCreator.withoutDocs({ + create(context, options) { + return { + ImportDeclaration(node) { + if (!node.source.value.startsWith("..")) { + // we're only interested in imports from parent folders outside of the test folder + return; + } + if (node.importKind === "type") { + // we're okay with internal types for now, although in most cases + // they should probably be exports if they are important enough + // that we need them for a test + return; + } + const resolvedTarget = resolve( + dirname(context.physicalFilename), + node.source.value + ); + if (options[0].ignoreFrom.includes(resolvedTarget)) { + return; + } + context.report({ + node: node.source, + messageId: "noRelativeImports", + }); + }, + }; + }, + meta: { + messages: { + noRelativeImports: + "Don't use relative imports in tests, import from official entry points instead.", + }, + type: "problem", + schema: [ + { + type: "object", + properties: { + ignoreFrom: { + type: "array", + items: { type: "string" }, + }, + }, + }, + ], + }, + defaultOptions: [ + { + ignoreFrom: [], + }, + ], +}); diff --git a/eslint-local-rules/index.mjs b/eslint-local-rules/index.mjs index 8955d4e6a08..0d5245dfbe1 100644 --- a/eslint-local-rules/index.mjs +++ b/eslint-local-rules/index.mjs @@ -4,6 +4,7 @@ import { importFromInsideOtherExport, noDuplicateExports, noInternalImportOfficialExport, + noRelativeImports, } from "./import-from-export.ts"; import { rule as requireDisableActEnvironment } from "./require-disable-act-environment.ts"; import { rule as requireUsingDisposable } from "./require-using-disposable.ts"; @@ -16,4 +17,5 @@ export default { "import-from-inside-other-export": importFromInsideOtherExport, "no-internal-import-official-export": noInternalImportOfficialExport, "no-duplicate-exports": noDuplicateExports, + "no-relative-imports": noRelativeImports, }; diff --git a/eslint.config.mjs b/eslint.config.mjs index 6fdc0c9ac37..e80d2e4fea5 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -72,6 +72,7 @@ export default [ }, }, + // rules for the whole repo rules: { "import/no-unresolved": "error", "import/order": [ @@ -107,6 +108,14 @@ export default [ }, ], "local-rules/no-duplicate-exports": "error", + "@typescript-eslint/consistent-type-imports": [ + "error", + { + prefer: "type-imports", + disallowTypeAnnotations: false, + fixStyle: "separate-type-imports", + }, + ], }, }, ...fixupConfigRules(compat.extends("plugin:react-hooks/recommended")).map( @@ -138,17 +147,9 @@ export default [ }, }, + // rules for source files, but no tests rules: { "react-compiler/react-compiler": "error", - "@typescript-eslint/consistent-type-imports": [ - "error", - { - prefer: "type-imports", - disallowTypeAnnotations: false, - fixStyle: "separate-type-imports", - }, - ], - "@typescript-eslint/consistent-type-exports": ["error"], "@typescript-eslint/no-import-type-side-effects": "error", @@ -215,6 +216,7 @@ export default [ }, }, + // rules for tests only rules: { "testing-library/prefer-user-event": "error", "testing-library/no-wait-for-multiple-assertions": "off", @@ -224,6 +226,7 @@ export default [ "local-rules/import-from-inside-other-export": "off", "local-rules/no-internal-import-official-export": runExtendedRules ? "error" : "off", + "local-rules/no-relative-imports": "error", "import/no-duplicates": "warn", "@typescript-eslint/no-floating-promises": "warn", }, diff --git a/package.json b/package.json index 19dd164a0bb..aff6fc00fe5 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "./testing/core": "./src/testing/core/index.ts", "./testing/experimental": "./src/testing/experimental/index.ts", "./testing/react": "./src/testing/react/index.ts", + "./testing/internal": "./src/testing/internal/index.ts", "./utilities": "./src/utilities/index.ts", "./utilities/internal": { "production": "./src/utilities/internal/index.production.ts", From ecf2294514ad261b908046df7b0325e0d992dedc Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 2 Apr 2025 16:35:51 +0200 Subject: [PATCH 5/6] chores --- .../api-report-testing_internal.api.md | 279 ++++++++++++++++++ src/__tests__/__snapshots__/exports.ts.snap | 23 ++ src/__tests__/exports.ts | 2 + 3 files changed, 304 insertions(+) create mode 100644 .api-reports/api-report-testing_internal.api.md diff --git a/.api-reports/api-report-testing_internal.api.md b/.api-reports/api-report-testing_internal.api.md new file mode 100644 index 00000000000..fa07f6a9333 --- /dev/null +++ b/.api-reports/api-report-testing_internal.api.md @@ -0,0 +1,279 @@ +## API Report File for "@apollo/client" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import type { ApolloClient } from '@apollo/client/core'; +import { ApolloLink } from '@apollo/client/core'; +import type { ApolloPayloadResult } from '@apollo/client/core'; +import { FetchResult } from '@apollo/client/core'; +import type { GraphQLFormattedError } from 'graphql-17-alpha2'; +import { GraphQLRequest } from '@apollo/client/core'; +import { HttpLink } from '@apollo/client/link/http'; +import type { InitialIncrementalExecutionResult } from 'graphql-17-alpha2'; +import type { MaskedDocumentNode } from '@apollo/client/masking'; +import type { MockedProviderProps } from '@apollo/client/testing/react'; +import type { MockedResponse } from '@apollo/client/testing/core'; +import type { Observable } from 'rxjs'; +import type { Queries } from '@testing-library/dom'; +import type { queries } from '@testing-library/dom'; +import * as React_2 from 'react'; +import type * as ReactDOMClient from 'react-dom/client'; +import type { RenderHookOptions } from '@testing-library/react'; +import type { RenderHookResult } from '@testing-library/react'; +import type { RenderOptions } from '@testing-library/react'; +import type { RenderResult } from '@testing-library/react'; +import { ResultFunction } from '@apollo/client/testing/core'; +import type { Subscribable } from 'rxjs'; +import type { SubsequentIncrementalExecutionResult } from 'graphql-17-alpha2'; +import type { TypedDocumentNode } from '@apollo/client/core'; + +// @public (undocumented) +export function actAsync(scope: () => T | Promise): Promise; + +// @public (undocumented) +export function addDelayToMocks[]>(mocks: T, delay?: number, override?: boolean): { + delay: number; + request: GraphQLRequest>; + maxUsageCount?: number; + result?: FetchResult | ResultFunction, Record> | undefined; + error?: Error; + variableMatcher?: ((arg: Record) => boolean) | undefined; + newData?: ResultFunction, Record> | undefined; +}[]; + +// @public (undocumented) +type ConsoleMethod = "log" | "info" | "warn" | "error" | "debug"; + +// @public (undocumented) +export function createClientWrapper(client: ApolloClient, Wrapper?: React_2.JSXElementConstructor<{ + children: React_2.ReactNode; +}>): React_2.JSXElementConstructor<{ + children: React_2.ReactNode; +}>; + +// @public (undocumented) +export function createMockWrapper(renderOptions: MockedProviderProps, Wrapper?: React_2.JSXElementConstructor<{ + children: React_2.ReactNode; +}>): React_2.JSXElementConstructor<{ + children: React_2.ReactNode; +}>; + +// @public (undocumented) +export function enableFakeTimers(config?: FakeTimersConfig | LegacyFakeTimersConfig): Disposable; + +// @public (undocumented) +type HydrateableContainer = Parameters<(typeof ReactDOMClient)["hydrateRoot"]>[0]; + +// @public (undocumented) +type HydrateableContainer_2 = Parameters<(typeof ReactDOMClient)["hydrateRoot"]>[0]; + +// @public (undocumented) +interface Letter { + // (undocumented) + __typename: "Letter"; + // (undocumented) + letter: string; + // (undocumented) + position: number; +} + +// @public (undocumented) +export interface MaskedVariablesCaseData { + // (undocumented) + character: { + __typename: "Character"; + id: string; + } & { + " $fragmentRefs"?: { + MaskedVariablesCaseFragment: MaskedVariablesCaseFragment; + }; + }; +} + +// @public (undocumented) +type MaskedVariablesCaseFragment = { + __typename: "Character"; + name: string; +} & { + " $fragmentName"?: "MaskedVariablesCaseFragment"; +}; + +// @public (undocumented) +export function mockDeferStream, TExtensions = Record>(): { + httpLink: HttpLink; + enqueueInitialChunk(chunk: InitialIncrementalExecutionResult): void; + enqueueSubsequentChunk(chunk: SubsequentIncrementalExecutionResult): void; + enqueueErrorChunk(errors: GraphQLFormattedError[]): void; +}; + +// @public (undocumented) +export function mockMultipartSubscriptionStream, TExtensions = Record>(): { + httpLink: HttpLink; + enqueueHeartbeat: () => void; + enqueuePayloadResult(payload: ApolloPayloadResult["payload"], hasNext?: boolean): void; + enqueueProtocolErrors(errors: ApolloPayloadResult["errors"]): void; +}; + +// @public (undocumented) +type ObservableEvent = { + type: "next"; + value: T; +} | { + type: "error"; + error: any; +} | { + type: "complete"; +}; + +// @public (undocumented) +export class ObservableStream { + constructor(observable: Observable | Subscribable); + // Warning: (ae-forgotten-export) The symbol "TakeOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "ObservableEvent" needs to be exported by the entry point index.d.ts + // + // (undocumented) + peek({ timeout }?: TakeOptions): Promise>; + // (undocumented) + take({ timeout }?: TakeOptions): Promise>; + // (undocumented) + takeComplete(options?: TakeOptions): Promise; + // (undocumented) + takeError(options?: TakeOptions): Promise; + // (undocumented) + takeNext(options?: TakeOptions): Promise; + // (undocumented) + unsubscribe(): void; +} + +// @public (undocumented) +export interface PaginatedCaseData { + // Warning: (ae-forgotten-export) The symbol "Letter" needs to be exported by the entry point index.d.ts + // + // (undocumented) + letters: Letter[]; +} + +// @public (undocumented) +export interface PaginatedCaseVariables { + // (undocumented) + limit?: number; + // (undocumented) + offset?: number; +} + +// Warning: (ae-forgotten-export) The symbol "RendererableContainer" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "HydrateableContainer" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export function renderAsync(ui: React.ReactNode, options: RenderOptions): Promise>; + +// @public (undocumented) +export function renderAsync(ui: React.ReactNode, options?: Omit | undefined): Promise; + +// @public (undocumented) +type RendererableContainer = ReactDOMClient.Container; + +// @public (undocumented) +type RendererableContainer_2 = ReactDOMClient.Container; + +// Warning: (ae-forgotten-export) The symbol "RendererableContainer_2" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "HydrateableContainer_2" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export function renderHookAsync(renderCallback: (initialProps: Props) => Result, options?: RenderHookOptions | undefined): Promise>; + +// @public +export function resetApolloContext(): void; + +// @public (undocumented) +export function setupMaskedVariablesCase(): { + mocks: MockedResponse>[]; + query: MaskedDocumentNode; + unmaskedQuery: TypedDocumentNode; +}; + +// @public (undocumented) +export function setupPaginatedCase(): { + query: TypedDocumentNode; + link: ApolloLink; + data: { + __typename: string; + letter: string; + position: number; + }[]; +}; + +// @public (undocumented) +export function setupSimpleCase(): { + query: TypedDocumentNode>; + mocks: MockedResponse>[]; +}; + +// @public (undocumented) +export function setupVariablesCase(): { + mocks: MockedResponse>[]; + query: TypedDocumentNode; +}; + +// @public (undocumented) +export interface SimpleCaseData { + // (undocumented) + greeting: string; +} + +// Warning: (ae-forgotten-export) The symbol "ConsoleMethod" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +type Spies = Record>; + +// Warning: (ae-forgotten-export) The symbol "Spies" needs to be exported by the entry point index.d.ts +// Warning: (ae-internal-mixed-release-tag) Mixed release tags are not allowed for "spyOnConsole" because one of its declarations is marked as @internal +// +// @internal (undocumented) +export function spyOnConsole(...spyOn: Keys): Spies & Disposable; + +// @public (undocumented) +export namespace spyOnConsole { + var // (undocumented) + takeSnapshots: (...spyOn: Keys) => Spies & Disposable; +} + +// @public (undocumented) +interface TakeOptions { + // (undocumented) + timeout?: number; +} + +// @public (undocumented) +export interface VariablesCaseData { + // (undocumented) + character: { + __typename: "Character"; + id: string; + name: string; + }; +} + +// @public (undocumented) +export interface VariablesCaseVariables { + // (undocumented) + id: string; +} + +// @internal (undocumented) +export function withCleanup(item: T, cleanup: (item: T) => void): T & Disposable; + +// @public (undocumented) +export function withProdMode(): { + prevDEV: boolean; +} & Disposable; + +// Warnings were encountered during analysis: +// +// src/testing/internal/scenarios/index.ts:80:7 - (ae-forgotten-export) The symbol "MaskedVariablesCaseFragment" needs to be exported by the entry point index.d.ts + +// (No @packageDocumentation comment for this package) + +``` diff --git a/src/__tests__/__snapshots__/exports.ts.snap b/src/__tests__/__snapshots__/exports.ts.snap index f1806949851..a70879b2e68 100644 --- a/src/__tests__/__snapshots__/exports.ts.snap +++ b/src/__tests__/__snapshots__/exports.ts.snap @@ -390,6 +390,29 @@ Array [ ] `; +exports[`exports of public entry points @apollo/client/testing/internal 1`] = ` +Array [ + "ObservableStream", + "actAsync", + "addDelayToMocks", + "createClientWrapper", + "createMockWrapper", + "enableFakeTimers", + "mockDeferStream", + "mockMultipartSubscriptionStream", + "renderAsync", + "renderHookAsync", + "resetApolloContext", + "setupMaskedVariablesCase", + "setupPaginatedCase", + "setupSimpleCase", + "setupVariablesCase", + "spyOnConsole", + "withCleanup", + "withProdMode", +] +`; + exports[`exports of public entry points @apollo/client/testing/react 1`] = ` Array [ "MockedProvider", diff --git a/src/__tests__/exports.ts b/src/__tests__/exports.ts index c981fa15d34..4e8105f75bb 100644 --- a/src/__tests__/exports.ts +++ b/src/__tests__/exports.ts @@ -35,6 +35,7 @@ import * as reactSSR from "@apollo/client/react/ssr"; import * as testing from "@apollo/client/testing"; import * as testingCore from "@apollo/client/testing/core"; import * as testingExperimental from "@apollo/client/testing/experimental"; +import * as testingInternal from "@apollo/client/testing/internal"; import * as testingReact from "@apollo/client/testing/react"; import * as utilities from "@apollo/client/utilities"; import * as utilitiesEnvironment from "@apollo/client/utilities/environment"; @@ -97,6 +98,7 @@ describe("exports of public entry points", () => { check("@apollo/client/testing", testing); check("@apollo/client/testing/core", testingCore); check("@apollo/client/testing/experimental", testingExperimental); + check("@apollo/client/testing/internal", testingInternal); check("@apollo/client/testing/react", testingReact); check("@apollo/client/utilities", utilities); check("@apollo/client/utilities/internal", utilitiesInternal); From d176cbdf3786d5e85ff89be2dd3a15bc90ad0e0b Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 2 Apr 2025 16:51:40 +0200 Subject: [PATCH 6/6] fix up mixed release tag problem --- .api-reports/api-report-testing_internal.api.md | 3 +-- src/testing/internal/disposables/spyOnConsole.ts | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.api-reports/api-report-testing_internal.api.md b/.api-reports/api-report-testing_internal.api.md index fa07f6a9333..82ebd8ea64c 100644 --- a/.api-reports/api-report-testing_internal.api.md +++ b/.api-reports/api-report-testing_internal.api.md @@ -229,9 +229,8 @@ export interface SimpleCaseData { type Spies = Record>; // Warning: (ae-forgotten-export) The symbol "Spies" needs to be exported by the entry point index.d.ts -// Warning: (ae-internal-mixed-release-tag) Mixed release tags are not allowed for "spyOnConsole" because one of its declarations is marked as @internal // -// @internal (undocumented) +// @public (undocumented) export function spyOnConsole(...spyOn: Keys): Spies & Disposable; // @public (undocumented) diff --git a/src/testing/internal/disposables/spyOnConsole.ts b/src/testing/internal/disposables/spyOnConsole.ts index 143de49fd7c..152d7ef404b 100644 --- a/src/testing/internal/disposables/spyOnConsole.ts +++ b/src/testing/internal/disposables/spyOnConsole.ts @@ -10,7 +10,6 @@ type Spies = Record< jest.SpyInstance >; -/** @internal */ export function spyOnConsole( ...spyOn: Keys ): Spies & Disposable {