Skip to content

Commit

Permalink
Upgrade to TypeScript 5.x (#7454)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
trevor-scheer and renovate[bot] committed Mar 29, 2023
1 parent a1d549e commit f6e3ae0
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 67 deletions.
7 changes: 7 additions & 0 deletions .changeset/shaggy-donkeys-joke.md
@@ -0,0 +1,7 @@
---
'@apollo/server-integration-testsuite': patch
'@apollo/server-plugin-response-cache': patch
'@apollo/server': patch
---

Start building packages with TS 5.x, which should have no effect for users
11 changes: 10 additions & 1 deletion .eslintrc.cjs
Expand Up @@ -10,7 +10,16 @@ module.exports = {
// need this on tests because Jest doesn't require it.
files: ['**/*.ts'],
excludedFiles: '**/__tests__/**/*.ts',
rules: { 'import/extensions': ['error', 'ignorePackages'] },
rules: {
'import/extensions': ['error', 'ignorePackages'],
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
fixStyle: 'inline-type-imports',
},
],
},
},
],
};
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -102,7 +102,7 @@
"supertest": "6.3.3",
"test-listen": "1.1.0",
"ts-jest": "29.0.5",
"typescript": "4.9.5"
"typescript": "5.0.2"
},
"jest": {
"projects": [
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-testsuite/src/apolloFetch.ts
@@ -1,4 +1,4 @@
import fetch, { RequestInit, Response } from 'node-fetch';
import fetch, { type RequestInit, type Response } from 'node-fetch';

export interface ApolloFetch {
(operation: GraphQLRequest): Promise<FetchResult>;
Expand Down
24 changes: 12 additions & 12 deletions packages/integration-testsuite/src/apolloServerTests.ts
Expand Up @@ -11,11 +11,11 @@ import {
GraphQLObjectType,
GraphQLString,
GraphQLError,
ValidationContext,
DocumentNode,
type ValidationContext,
type DocumentNode,
printSchema,
FieldNode,
GraphQLFormattedError,
type FieldNode,
type GraphQLFormattedError,
GraphQLScalarType,
} from 'graphql';

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

import {
createApolloFetch,
ApolloFetch,
ParsedResponse,
type ApolloFetch,
type ParsedResponse,
} from './apolloFetch.js';
import {
ApolloServerOptions,
type ApolloServerOptions,
ApolloServer,
BaseContext,
ApolloServerPlugin,
type BaseContext,
type ApolloServerPlugin,
HeaderMap,
} from '@apollo/server';
import fetch, { type Headers } from 'node-fetch';

import resolvable, { Resolvable } from '@josephg/resolvable';
import resolvable, { type Resolvable } from '@josephg/resolvable';
import type { AddressInfo } from 'net';
import request, { Response } from 'supertest';
import request, { type Response } from 'supertest';
import { InMemoryLRUCache } from '@apollo/utils.keyvaluecache';
import type {
CreateServerForIntegrationTests,
Expand All @@ -49,7 +49,7 @@ import type {
} from '.';
import gql from 'graphql-tag';
import {
ApolloServerPluginUsageReportingOptions,
type ApolloServerPluginUsageReportingOptions,
ApolloServerPluginUsageReporting,
} from '@apollo/server/plugin/usageReporting';
import { ApolloServerPluginInlineTrace } from '@apollo/server/plugin/inlineTrace';
Expand Down
9 changes: 6 additions & 3 deletions packages/integration-testsuite/src/httpServerTests.ts
Expand Up @@ -7,7 +7,7 @@ import { createHash } from '@apollo/utils.createhash';
import resolvable, { type Resolvable } from '@josephg/resolvable';
import {
BREAK,
DocumentNode,
type DocumentNode,
getIntrospectionQuery,
getOperationAST,
GraphQLError,
Expand All @@ -17,10 +17,13 @@ import {
GraphQLScalarType,
GraphQLSchema,
GraphQLString,
ValidationContext,
type ValidationContext,
} from 'graphql';
import gql from 'graphql-tag';
import { InMemoryLRUCache, KeyValueCache } from '@apollo/utils.keyvaluecache';
import {
InMemoryLRUCache,
type KeyValueCache,
} from '@apollo/utils.keyvaluecache';
import superagent, { type HTTPError } from 'superagent';
import request from 'supertest';
import type {
Expand Down
@@ -1,15 +1,15 @@
import type { CacheHint } from '@apollo/cache-control-types';
import {
ApolloServerPlugin,
BaseContext,
GraphQLRequestContext,
GraphQLRequestListener,
GraphQLResponse,
type ApolloServerPlugin,
type BaseContext,
type GraphQLRequestContext,
type GraphQLRequestListener,
type GraphQLResponse,
HeaderMap,
} from '@apollo/server';
import { createHash } from '@apollo/utils.createhash';
import {
KeyValueCache,
type KeyValueCache,
PrefixingKeyValueCache,
} from '@apollo/utils.keyvaluecache';

Expand Down
20 changes: 10 additions & 10 deletions packages/server/src/ApolloServer.ts
@@ -1,19 +1,19 @@
import { isNodeLike } from '@apollo/utils.isnodelike';
import type { Logger } from '@apollo/utils.logger';
import { makeExecutableSchema } from '@graphql-tools/schema';
import resolvable, { Resolvable } from '@josephg/resolvable';
import resolvable, { type Resolvable } from '@josephg/resolvable';
import {
assertValidSchema,
DocumentNode,
type DocumentNode,
GraphQLError,
GraphQLFieldResolver,
GraphQLFormattedError,
GraphQLSchema,
ParseOptions,
type GraphQLFieldResolver,
type GraphQLFormattedError,
type GraphQLSchema,
type ParseOptions,
print,
TypedQueryDocumentNode,
ValidationContext,
ValidationRule,
type TypedQueryDocumentNode,
type ValidationContext,
type ValidationRule,
} from 'graphql';
import {
type KeyValueCache,
Expand Down Expand Up @@ -53,7 +53,7 @@ import type {
HTTPGraphQLHead,
} from './externalTypes/index.js';
import { runPotentiallyBatchedHttpQuery } from './httpBatching.js';
import { InternalPluginId, pluginIsInternal } from './internalPlugin.js';
import { type InternalPluginId, pluginIsInternal } from './internalPlugin.js';
import {
preventCsrf,
recommendedCsrfPreventionRequestHeaders,
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/errorNormalize.ts
Expand Up @@ -2,8 +2,8 @@

import {
GraphQLError,
GraphQLErrorExtensions,
GraphQLFormattedError,
type GraphQLErrorExtensions,
type GraphQLFormattedError,
} from 'graphql';
import { ApolloServerErrorCode } from './errors/index.js';
import type { HTTPGraphQLHead } from './externalTypes/http.js';
Expand Down
7 changes: 6 additions & 1 deletion packages/server/src/incrementalDeliveryPolyfill.ts
@@ -1,4 +1,9 @@
import { execute, ExecutionArgs, ExecutionResult, GraphQLError } from 'graphql';
import {
execute,
type ExecutionArgs,
type ExecutionResult,
type GraphQLError,
} from 'graphql';

// This file "polyfills" graphql@17's experimentalExecuteIncrementally (by
// returning a function that does not understand incremental directives if
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/internalErrorClasses.ts
@@ -1,4 +1,4 @@
import { GraphQLError, GraphQLErrorOptions } from 'graphql';
import { GraphQLError, type GraphQLErrorOptions } from 'graphql';
import { ApolloServerErrorCode } from './errors/index.js';
import { newHTTPGraphQLHead } from './runHttpQuery.js';
import { HeaderMap } from './utils/HeaderMap.js';
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/plugin/cacheControl/index.ts
@@ -1,9 +1,9 @@
import type { ApolloServerPlugin } from '../../externalTypes/index.js';
import {
DirectiveNode,
type DirectiveNode,
getNamedType,
GraphQLCompositeType,
GraphQLField,
type GraphQLCompositeType,
type GraphQLField,
isCompositeType,
isInterfaceType,
isObjectType,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/plugin/schemaIsSubgraph.ts
@@ -1,5 +1,5 @@
import {
GraphQLSchema,
type GraphQLSchema,
isObjectType,
isScalarType,
isNonNullType,
Expand Down
6 changes: 5 additions & 1 deletion packages/server/src/plugin/traceTreeBuilder.ts
@@ -1,6 +1,10 @@
// This class is a helper for ApolloServerPluginUsageReporting and
// ApolloServerPluginInlineTrace.
import { GraphQLError, GraphQLResolveInfo, ResponsePath } from 'graphql';
import {
GraphQLError,
type GraphQLResolveInfo,
type ResponsePath,
} from 'graphql';
import { Trace, google } from '@apollo/usage-reporting-protobuf';
import type { Logger } from '@apollo/utils.logger';
import type { SendErrorsOptions } from './usageReporting';
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/plugin/usageReporting/plugin.ts
Expand Up @@ -3,10 +3,10 @@ import type { Fetcher, FetcherResponse } from '@apollo/utils.fetcher';
import {
usageReportingSignature,
calculateReferencedFieldsByType,
ReferencedFieldsByType,
type ReferencedFieldsByType,
} from '@apollo/utils.usagereporting';
import retry from 'async-retry';
import { GraphQLSchema, printSchema } from 'graphql';
import { type GraphQLSchema, printSchema } from 'graphql';
import type LRUCache from 'lru-cache';
import { AbortController } from 'node-abort-controller';
import fetch from 'node-fetch';
Expand All @@ -26,7 +26,7 @@ import { dateToProtoTimestamp, TraceTreeBuilder } from '../traceTreeBuilder.js';
import { defaultSendOperationsAsTrace } from './defaultSendOperationsAsTrace.js';
import {
createOperationDerivedDataCache,
OperationDerivedData,
type OperationDerivedData,
operationDerivedDataCacheKey,
} from './operationDerivedDataCache.js';
import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/plugin/usageReporting/stats.ts
Expand Up @@ -14,7 +14,7 @@ import {
} from '@apollo/usage-reporting-protobuf';
import type { ReferencedFieldsByType } from '@apollo/utils.usagereporting';
import { DurationHistogram } from './durationHistogram.js';
import { iterateOverTrace, ResponseNamePath } from './iterateOverTrace.js';
import { iterateOverTrace, type ResponseNamePath } from './iterateOverTrace.js';

// protobuf.js exports both a class and an interface (starting with I) for each
// message type. The class is what it produces when it decodes the message; the
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/requestPipeline.ts
Expand Up @@ -6,7 +6,7 @@ import {
validate,
parse,
Kind,
ExecutionResult,
type ExecutionResult,
} from 'graphql';
import {
symbolExecutionDispatcherWillResolveField,
Expand Down Expand Up @@ -64,8 +64,8 @@ import type {
} from './externalTypes/requestPipeline.js';
import {
executeIncrementally,
GraphQLExperimentalInitialIncrementalExecutionResult,
GraphQLExperimentalSubsequentIncrementalExecutionResult,
type GraphQLExperimentalInitialIncrementalExecutionResult,
type GraphQLExperimentalSubsequentIncrementalExecutionResult,
} from './incrementalDeliveryPolyfill.js';
import { HeaderMap } from './utils/HeaderMap.js';

Expand Down
8 changes: 4 additions & 4 deletions packages/server/src/runHttpQuery.ts
Expand Up @@ -9,14 +9,14 @@ import type {
HTTPGraphQLResponse,
} from './externalTypes/index.js';
import {
ApolloServer,
ApolloServerInternals,
type ApolloServer,
type ApolloServerInternals,
chooseContentTypeForSingleResultResponse,
internalExecuteOperation,
MEDIA_TYPES,
SchemaDerivedData,
type SchemaDerivedData,
} from './ApolloServer.js';
import { FormattedExecutionResult, Kind } from 'graphql';
import { type FormattedExecutionResult, Kind } from 'graphql';
import { BadRequestError } from './internalErrorClasses.js';
import Negotiator from 'negotiator';
import { HeaderMap } from './utils/HeaderMap.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/standalone/index.ts
Expand Up @@ -2,7 +2,7 @@ import type { WithRequired } from '@apollo/utils.withrequired';
import bodyParser from 'body-parser'; // note that importing 'json' directly doesn't work in ESM
import cors from 'cors';
import express from 'express';
import http, { IncomingMessage, ServerResponse } from 'http';
import http, { type IncomingMessage, type ServerResponse } from 'http';
import type { ListenOptions } from 'net';
import type { ApolloServer } from '../ApolloServer.js';
import { expressMiddleware } from '../express4/index.js';
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/utils/schemaInstrumentation.ts
@@ -1,9 +1,9 @@
import {
GraphQLSchema,
GraphQLField,
type GraphQLSchema,
type GraphQLField,
getNamedType,
GraphQLObjectType,
GraphQLFieldResolver,
type GraphQLFieldResolver,
defaultFieldResolver,
} from 'graphql';
import type {
Expand Down
1 change: 0 additions & 1 deletion tsconfig.base.json
Expand Up @@ -17,7 +17,6 @@
"noUnusedParameters": true,
"noUnusedLocals": true,
"forceConsistentCasingInFileNames": true,
"importsNotUsedAsValues": "error",
"lib": ["es2020"],
"types": ["node"],
"baseUrl": ".",
Expand Down

0 comments on commit f6e3ae0

Please sign in to comment.