Skip to content

Commit

Permalink
reduce bundle size by adjusting imports (#161)
Browse files Browse the repository at this point in the history
* use type imports where possible

* import `print` from `@apollo/client/utilities`

* adjust one more import
  • Loading branch information
phryneas authored Jan 5, 2024
1 parent e466b37 commit 10fc3e5
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 28 deletions.
8 changes: 8 additions & 0 deletions package/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@ module.exports = {
varsIgnorePattern: "^_",
},
],
"@typescript-eslint/consistent-type-imports": [
"error",
{
prefer: "type-imports",
disallowTypeAnnotations: false,
fixStyle: "separate-type-imports",
},
],
},
};
7 changes: 4 additions & 3 deletions package/src/ssr/AccumulateMultipartResponsesLink.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type {
ExecutionPatchResult,
FetchResult} from "@apollo/client";
import {
ApolloLink,
ExecutionPatchResult,
FetchResult,
Observable,
gql,
} from "@apollo/client";
import { AccumulateMultipartResponsesLink } from "./AccumulateMultipartResponsesLink";
import { test, expect, assert, beforeEach, afterEach, vi } from "vitest";
import { fromPartial } from "@total-typescript/shoehorn";
import { SubscriptionObserver } from "zen-observable-ts";
import type { SubscriptionObserver } from "zen-observable-ts";

beforeEach(() => {
vi.useFakeTimers();
Expand Down
3 changes: 2 additions & 1 deletion package/src/ssr/AccumulateMultipartResponsesLink.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApolloLink, Operation, NextLink, FetchResult } from "@apollo/client";
import type { Operation, NextLink, FetchResult } from "@apollo/client";
import { ApolloLink } from "@apollo/client";
import {
Observable,
hasDirectives,
Expand Down
6 changes: 4 additions & 2 deletions package/src/ssr/ApolloNextAppProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"use client";
import * as React from "react";
import type {
ApolloClient} from "@apollo/client";
import {
ApolloClient,
ApolloProvider as _ApolloProvider,
} from "@apollo/client";
import type {
HydrationContextOptions} from "./RehydrationContext";
import {
HydrationContextOptions,
RehydrationContextProvider,
} from "./RehydrationContext";

Expand Down
4 changes: 2 additions & 2 deletions package/src/ssr/ApolloRehydrateSymbols.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SuperJSONResult } from "superjson/dist/types";
import {
import type { SuperJSONResult } from "superjson/dist/types";
import type {
RehydrationCache,
ResultsCache,
BackgroundQueriesCache,
Expand Down
13 changes: 7 additions & 6 deletions package/src/ssr/NextSSRApolloClient.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {
ApolloClient,
import type {
ApolloClientOptions,
OperationVariables,
WatchQueryOptions,
Observable,
FetchResult,
DocumentNode,
DocumentNode} from "@apollo/client";
import {
ApolloClient,
Observable
} from "@apollo/client";
import type { QueryManager } from "@apollo/client/core/QueryManager";
import { print } from "graphql";
import { print } from "@apollo/client/utilities";
import { canonicalStringify } from "@apollo/client/cache";
import { RehydrationContextValue } from "./types";
import type { RehydrationContextValue } from "./types";
import { registerLateInitializingQueue } from "./lateInitializingQueue";
import {
ApolloBackgroundQueryTransport,
Expand Down
9 changes: 5 additions & 4 deletions package/src/ssr/NextSSRInMemoryCache.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
InMemoryCache,
import type {
InMemoryCacheConfig,
Cache,
Reference,
Reference} from "@apollo/client";
import {
InMemoryCache
} from "@apollo/client";
import { RehydrationContextValue } from "./types";
import type { RehydrationContextValue } from "./types";

export class NextSSRInMemoryCache extends InMemoryCache {
private rehydrationContext: Pick<
Expand Down
2 changes: 1 addition & 1 deletion package/src/ssr/RehydrationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useApolloClient } from "@apollo/client";
import React from "react";
import { NextSSRInMemoryCache } from "./NextSSRInMemoryCache";
import { ServerInsertedHTMLContext } from "next/navigation";
import { RehydrationContextValue } from "./types";
import type { RehydrationContextValue } from "./types";
import { registerDataTransport, transportDataToJS } from "./dataTransport";
import invariant from "ts-invariant";
import { NextSSRApolloClient } from "./NextSSRApolloClient";
Expand Down
3 changes: 2 additions & 1 deletion package/src/ssr/RemoveMultipartDirectivesLink.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { RemoveMultipartDirectivesLink } from "./RemoveMultipartDirectivesLink";
import { fromPartial } from "@total-typescript/shoehorn";
import { gql, DocumentNode, Observable } from "@apollo/client";
import type { DocumentNode} from "@apollo/client";
import { gql, Observable } from "@apollo/client";
import { print } from "graphql";
import { it, expect } from "vitest";

Expand Down
8 changes: 5 additions & 3 deletions package/src/ssr/RemoveMultipartDirectivesLink.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ApolloLink, Operation, NextLink, DocumentNode } from "@apollo/client";
import type { Operation, NextLink, DocumentNode } from "@apollo/client";
import { ApolloLink } from "@apollo/client";
import type {
RemoveDirectiveConfig} from "@apollo/client/utilities";
import {
Observable,
RemoveDirectiveConfig,
removeDirectivesFromDocument,
} from "@apollo/client/utilities";
import { DirectiveNode } from "graphql";
import type { DirectiveNode } from "graphql";

interface RemoveMultipartDirectivesConfig {
/**
Expand Down
4 changes: 2 additions & 2 deletions package/src/ssr/dataTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
ApolloResultCache,
ApolloBackgroundQueryTransport,
} from "./ApolloRehydrateSymbols";
import { RehydrationCache } from "./types";
import type { RehydrationCache } from "./types";
import { registerLateInitializingQueue } from "./lateInitializingQueue";
import { Cache, WatchQueryOptions } from "@apollo/client";
import type { Cache, WatchQueryOptions } from "@apollo/client";
import invariant from "ts-invariant";

export type DataTransport<T> = Array<T> | { push(...args: T[]): void };
Expand Down
6 changes: 3 additions & 3 deletions package/src/ssr/types.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Cache, WatchQueryOptions } from "@apollo/client";
import React from "react";
import { DataTransport } from "./dataTransport";
import type { Cache, WatchQueryOptions } from "@apollo/client";
import type React from "react";
import type { DataTransport } from "./dataTransport";

export type RehydrationCache = Record<string, unknown>;
export type ResultsCache = DataTransport<Cache.WriteOptions>;
Expand Down

0 comments on commit 10fc3e5

Please sign in to comment.