Skip to content

Commit bd43410

Browse files
Upgrade to TypeScript 5.x (#7454)
This PR upgrades the Apollo Server repo to use TS 5.x. This change suggests we drop `importsNotUsedAsValues` in favor of the new [`verbatimModuleSyntax`](https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#verbatimmodulesyntax). However, this rule [isn't really recommended or expected to be adopted by CommonJS packages](microsoft/TypeScript#52203 (comment)). So instead of opting in to the new option, I've taken the recommendation in the comment to enforce this via a lint rule which seems to have accomplished the thing we hoped to get out of `importsNotUsedAsValues` in the first place (but better, for some reason?). --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent 7256cb5 commit bd43410

22 files changed

+94
-67
lines changed

.changeset/shaggy-donkeys-joke.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@apollo/server-integration-testsuite': patch
3+
'@apollo/server-plugin-response-cache': patch
4+
'@apollo/server': patch
5+
---
6+
7+
Start building packages with TS 5.x, which should have no effect for users

.eslintrc.cjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ module.exports = {
1010
// need this on tests because Jest doesn't require it.
1111
files: ['**/*.ts'],
1212
excludedFiles: '**/__tests__/**/*.ts',
13-
rules: { 'import/extensions': ['error', 'ignorePackages'] },
13+
rules: {
14+
'import/extensions': ['error', 'ignorePackages'],
15+
'@typescript-eslint/consistent-type-imports': [
16+
'error',
17+
{
18+
prefer: 'type-imports',
19+
fixStyle: 'inline-type-imports',
20+
},
21+
],
22+
},
1423
},
1524
],
1625
};

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"supertest": "6.3.3",
103103
"test-listen": "1.1.0",
104104
"ts-jest": "29.0.5",
105-
"typescript": "4.9.5"
105+
"typescript": "5.0.2"
106106
},
107107
"jest": {
108108
"projects": [

packages/integration-testsuite/src/apolloFetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fetch, { RequestInit, Response } from 'node-fetch';
1+
import fetch, { type RequestInit, type Response } from 'node-fetch';
22

33
export interface ApolloFetch {
44
(operation: GraphQLRequest): Promise<FetchResult>;

packages/integration-testsuite/src/apolloServerTests.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {
1111
GraphQLObjectType,
1212
GraphQLString,
1313
GraphQLError,
14-
ValidationContext,
15-
DocumentNode,
14+
type ValidationContext,
15+
type DocumentNode,
1616
printSchema,
17-
FieldNode,
18-
GraphQLFormattedError,
17+
type FieldNode,
18+
type GraphQLFormattedError,
1919
GraphQLScalarType,
2020
} from 'graphql';
2121

@@ -26,21 +26,21 @@ import { createPersistedQueryLink } from '@apollo/client/link/persisted-queries'
2626

2727
import {
2828
createApolloFetch,
29-
ApolloFetch,
30-
ParsedResponse,
29+
type ApolloFetch,
30+
type ParsedResponse,
3131
} from './apolloFetch.js';
3232
import {
33-
ApolloServerOptions,
33+
type ApolloServerOptions,
3434
ApolloServer,
35-
BaseContext,
36-
ApolloServerPlugin,
35+
type BaseContext,
36+
type ApolloServerPlugin,
3737
HeaderMap,
3838
} from '@apollo/server';
3939
import fetch, { type Headers } from 'node-fetch';
4040

41-
import resolvable, { Resolvable } from '@josephg/resolvable';
41+
import resolvable, { type Resolvable } from '@josephg/resolvable';
4242
import type { AddressInfo } from 'net';
43-
import request, { Response } from 'supertest';
43+
import request, { type Response } from 'supertest';
4444
import { InMemoryLRUCache } from '@apollo/utils.keyvaluecache';
4545
import type {
4646
CreateServerForIntegrationTests,
@@ -49,7 +49,7 @@ import type {
4949
} from '.';
5050
import gql from 'graphql-tag';
5151
import {
52-
ApolloServerPluginUsageReportingOptions,
52+
type ApolloServerPluginUsageReportingOptions,
5353
ApolloServerPluginUsageReporting,
5454
} from '@apollo/server/plugin/usageReporting';
5555
import { ApolloServerPluginInlineTrace } from '@apollo/server/plugin/inlineTrace';

packages/integration-testsuite/src/httpServerTests.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createHash } from '@apollo/utils.createhash';
77
import resolvable, { type Resolvable } from '@josephg/resolvable';
88
import {
99
BREAK,
10-
DocumentNode,
10+
type DocumentNode,
1111
getIntrospectionQuery,
1212
getOperationAST,
1313
GraphQLError,
@@ -17,10 +17,13 @@ import {
1717
GraphQLScalarType,
1818
GraphQLSchema,
1919
GraphQLString,
20-
ValidationContext,
20+
type ValidationContext,
2121
} from 'graphql';
2222
import gql from 'graphql-tag';
23-
import { InMemoryLRUCache, KeyValueCache } from '@apollo/utils.keyvaluecache';
23+
import {
24+
InMemoryLRUCache,
25+
type KeyValueCache,
26+
} from '@apollo/utils.keyvaluecache';
2427
import superagent, { type HTTPError } from 'superagent';
2528
import request from 'supertest';
2629
import type {

packages/plugin-response-cache/src/ApolloServerPluginResponseCache.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import type { CacheHint } from '@apollo/cache-control-types';
22
import {
3-
ApolloServerPlugin,
4-
BaseContext,
5-
GraphQLRequestContext,
6-
GraphQLRequestListener,
7-
GraphQLResponse,
3+
type ApolloServerPlugin,
4+
type BaseContext,
5+
type GraphQLRequestContext,
6+
type GraphQLRequestListener,
7+
type GraphQLResponse,
88
HeaderMap,
99
} from '@apollo/server';
1010
import { createHash } from '@apollo/utils.createhash';
1111
import {
12-
KeyValueCache,
12+
type KeyValueCache,
1313
PrefixingKeyValueCache,
1414
} from '@apollo/utils.keyvaluecache';
1515

packages/server/src/ApolloServer.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { isNodeLike } from '@apollo/utils.isnodelike';
22
import type { Logger } from '@apollo/utils.logger';
33
import { makeExecutableSchema } from '@graphql-tools/schema';
4-
import resolvable, { Resolvable } from '@josephg/resolvable';
4+
import resolvable, { type Resolvable } from '@josephg/resolvable';
55
import {
66
assertValidSchema,
7-
DocumentNode,
7+
type DocumentNode,
88
GraphQLError,
9-
GraphQLFieldResolver,
10-
GraphQLFormattedError,
11-
GraphQLSchema,
12-
ParseOptions,
9+
type GraphQLFieldResolver,
10+
type GraphQLFormattedError,
11+
type GraphQLSchema,
12+
type ParseOptions,
1313
print,
14-
TypedQueryDocumentNode,
15-
ValidationContext,
16-
ValidationRule,
14+
type TypedQueryDocumentNode,
15+
type ValidationContext,
16+
type ValidationRule,
1717
} from 'graphql';
1818
import {
1919
type KeyValueCache,
@@ -53,7 +53,7 @@ import type {
5353
HTTPGraphQLHead,
5454
} from './externalTypes/index.js';
5555
import { runPotentiallyBatchedHttpQuery } from './httpBatching.js';
56-
import { InternalPluginId, pluginIsInternal } from './internalPlugin.js';
56+
import { type InternalPluginId, pluginIsInternal } from './internalPlugin.js';
5757
import {
5858
preventCsrf,
5959
recommendedCsrfPreventionRequestHeaders,

packages/server/src/errorNormalize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import {
44
GraphQLError,
5-
GraphQLErrorExtensions,
6-
GraphQLFormattedError,
5+
type GraphQLErrorExtensions,
6+
type GraphQLFormattedError,
77
} from 'graphql';
88
import { ApolloServerErrorCode } from './errors/index.js';
99
import type { HTTPGraphQLHead } from './externalTypes/http.js';

packages/server/src/incrementalDeliveryPolyfill.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { execute, ExecutionArgs, ExecutionResult, GraphQLError } from 'graphql';
1+
import {
2+
execute,
3+
type ExecutionArgs,
4+
type ExecutionResult,
5+
type GraphQLError,
6+
} from 'graphql';
27

38
// This file "polyfills" graphql@17's experimentalExecuteIncrementally (by
49
// returning a function that does not understand incremental directives if

packages/server/src/internalErrorClasses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GraphQLError, GraphQLErrorOptions } from 'graphql';
1+
import { GraphQLError, type GraphQLErrorOptions } from 'graphql';
22
import { ApolloServerErrorCode } from './errors/index.js';
33
import { newHTTPGraphQLHead } from './runHttpQuery.js';
44
import { HeaderMap } from './utils/HeaderMap.js';

packages/server/src/plugin/cacheControl/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { ApolloServerPlugin } from '../../externalTypes/index.js';
22
import {
3-
DirectiveNode,
3+
type DirectiveNode,
44
getNamedType,
5-
GraphQLCompositeType,
6-
GraphQLField,
5+
type GraphQLCompositeType,
6+
type GraphQLField,
77
isCompositeType,
88
isInterfaceType,
99
isObjectType,

packages/server/src/plugin/schemaIsSubgraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
GraphQLSchema,
2+
type GraphQLSchema,
33
isObjectType,
44
isScalarType,
55
isNonNullType,

packages/server/src/plugin/traceTreeBuilder.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// This class is a helper for ApolloServerPluginUsageReporting and
22
// ApolloServerPluginInlineTrace.
3-
import { GraphQLError, GraphQLResolveInfo, ResponsePath } from 'graphql';
3+
import {
4+
GraphQLError,
5+
type GraphQLResolveInfo,
6+
type ResponsePath,
7+
} from 'graphql';
48
import { Trace, google } from '@apollo/usage-reporting-protobuf';
59
import type { Logger } from '@apollo/utils.logger';
610
import type { SendErrorsOptions } from './usageReporting';

packages/server/src/plugin/usageReporting/plugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import type { Fetcher, FetcherResponse } from '@apollo/utils.fetcher';
33
import {
44
usageReportingSignature,
55
calculateReferencedFieldsByType,
6-
ReferencedFieldsByType,
6+
type ReferencedFieldsByType,
77
} from '@apollo/utils.usagereporting';
88
import retry from 'async-retry';
9-
import { GraphQLSchema, printSchema } from 'graphql';
9+
import { type GraphQLSchema, printSchema } from 'graphql';
1010
import type LRUCache from 'lru-cache';
1111
import { AbortController } from 'node-abort-controller';
1212
import fetch from 'node-fetch';
@@ -26,7 +26,7 @@ import { dateToProtoTimestamp, TraceTreeBuilder } from '../traceTreeBuilder.js';
2626
import { defaultSendOperationsAsTrace } from './defaultSendOperationsAsTrace.js';
2727
import {
2828
createOperationDerivedDataCache,
29-
OperationDerivedData,
29+
type OperationDerivedData,
3030
operationDerivedDataCacheKey,
3131
} from './operationDerivedDataCache.js';
3232
import type {

packages/server/src/plugin/usageReporting/stats.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '@apollo/usage-reporting-protobuf';
1515
import type { ReferencedFieldsByType } from '@apollo/utils.usagereporting';
1616
import { DurationHistogram } from './durationHistogram.js';
17-
import { iterateOverTrace, ResponseNamePath } from './iterateOverTrace.js';
17+
import { iterateOverTrace, type ResponseNamePath } from './iterateOverTrace.js';
1818

1919
// protobuf.js exports both a class and an interface (starting with I) for each
2020
// message type. The class is what it produces when it decodes the message; the

packages/server/src/requestPipeline.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
validate,
77
parse,
88
Kind,
9-
ExecutionResult,
9+
type ExecutionResult,
1010
} from 'graphql';
1111
import {
1212
symbolExecutionDispatcherWillResolveField,
@@ -64,8 +64,8 @@ import type {
6464
} from './externalTypes/requestPipeline.js';
6565
import {
6666
executeIncrementally,
67-
GraphQLExperimentalInitialIncrementalExecutionResult,
68-
GraphQLExperimentalSubsequentIncrementalExecutionResult,
67+
type GraphQLExperimentalInitialIncrementalExecutionResult,
68+
type GraphQLExperimentalSubsequentIncrementalExecutionResult,
6969
} from './incrementalDeliveryPolyfill.js';
7070
import { HeaderMap } from './utils/HeaderMap.js';
7171

packages/server/src/runHttpQuery.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import type {
99
HTTPGraphQLResponse,
1010
} from './externalTypes/index.js';
1111
import {
12-
ApolloServer,
13-
ApolloServerInternals,
12+
type ApolloServer,
13+
type ApolloServerInternals,
1414
chooseContentTypeForSingleResultResponse,
1515
internalExecuteOperation,
1616
MEDIA_TYPES,
17-
SchemaDerivedData,
17+
type SchemaDerivedData,
1818
} from './ApolloServer.js';
19-
import { FormattedExecutionResult, Kind } from 'graphql';
19+
import { type FormattedExecutionResult, Kind } from 'graphql';
2020
import { BadRequestError } from './internalErrorClasses.js';
2121
import Negotiator from 'negotiator';
2222
import { HeaderMap } from './utils/HeaderMap.js';

packages/server/src/standalone/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { WithRequired } from '@apollo/utils.withrequired';
22
import bodyParser from 'body-parser'; // note that importing 'json' directly doesn't work in ESM
33
import cors from 'cors';
44
import express from 'express';
5-
import http, { IncomingMessage, ServerResponse } from 'http';
5+
import http, { type IncomingMessage, type ServerResponse } from 'http';
66
import type { ListenOptions } from 'net';
77
import type { ApolloServer } from '../ApolloServer.js';
88
import { expressMiddleware } from '../express4/index.js';

packages/server/src/utils/schemaInstrumentation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
2-
GraphQLSchema,
3-
GraphQLField,
2+
type GraphQLSchema,
3+
type GraphQLField,
44
getNamedType,
55
GraphQLObjectType,
6-
GraphQLFieldResolver,
6+
type GraphQLFieldResolver,
77
defaultFieldResolver,
88
} from 'graphql';
99
import type {

tsconfig.base.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"noUnusedParameters": true,
1818
"noUnusedLocals": true,
1919
"forceConsistentCasingInFileNames": true,
20-
"importsNotUsedAsValues": "error",
2120
"lib": ["es2021"],
2221
"types": ["node"],
2322
"baseUrl": ".",

0 commit comments

Comments
 (0)