Skip to content

Commit 9fc23f7

Browse files
Fix imports for moduleResolution: nodenext TS users (v4) (#6731)
When installing @apollo/server v4 in a TS project using "moduleResolution": "nodenext", TS would throw errors about how Apollo Server's imports need to use extensions. Specifically, we omitted extensions from all type-only imports since they didn't seem to be needed, but it's not hurting anything to add them and some use cases require it. Add a new smoke test for this use case which will ensure extensions are used in all source code files, even for type-only imports. Fixes #6730
1 parent 686a30c commit 9fc23f7

File tree

32 files changed

+133
-42
lines changed

32 files changed

+133
-42
lines changed

.changeset/old-papayas-switch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/server": patch
3+
---
4+
5+
Use extensions for all imports to accommodate TS users using moduleResolution: "nodenext"

cspell-dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ mygraph
115115
myvariant
116116
namespacing
117117
nanos
118+
nodenext
118119
npmrc
119120
nsolid
120121
oneof

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"test:clean": "jest --clearCache",
1818
"test:watch": "jest --verbose --watchAll",
1919
"test:smoke": "npm run test:smoke:prepare && npm run test:smoke:run",
20-
"test:smoke:prepare": "npm run compile && smoke-test/prepare.sh",
20+
"test:smoke:prepare": "smoke-test/prepare.sh",
2121
"test:smoke:run": "smoke-test/smoke-test.sh",
2222
"testonly": "npm test",
2323
"test:ci": "npm test -- --ci --maxWorkers=2 --reporters=default --reporters=jest-junit",

packages/server/src/ApolloServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import type {
4343
HTTPGraphQLHead,
4444
ContextThunk,
4545
GraphQLRequestContext,
46-
} from './externalTypes';
46+
} from './externalTypes/index.js';
4747
import { runPotentiallyBatchedHttpQuery } from './httpBatching.js';
4848
import { InternalPluginId, pluginIsInternal } from './internalPlugin.js';
4949
import {
@@ -62,7 +62,7 @@ import { SchemaManager } from './utils/schemaManager.js';
6262
import { isDefined } from './utils/isDefined.js';
6363
import { UnreachableCaseError } from './utils/UnreachableCaseError.js';
6464
import type { WithRequired } from '@apollo/utils.withrequired';
65-
import type { ApolloServerOptionsWithStaticSchema } from './externalTypes/constructor';
65+
import type { ApolloServerOptionsWithStaticSchema } from './externalTypes/constructor.js';
6666
import type { GatewayExecutor } from '@apollo/server-gateway-interface';
6767

6868
const NoIntrospection = (context: ValidationContext) => ({

packages/server/src/determineApolloConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createHash } from '@apollo/utils.createhash';
2-
import type { ApolloConfig, ApolloConfigInput } from './externalTypes';
2+
import type { ApolloConfig, ApolloConfigInput } from './externalTypes/index.js';
33

44
// This function combines the `apollo` constructor argument and some environment
55
// variables to come up with a full ApolloConfig.

packages/server/src/express4/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { WithRequired } from '@apollo/utils.withrequired';
22
import type express from 'express';
3-
import type { ApolloServer } from '..';
3+
import type { ApolloServer } from '../index.js';
44
import type {
55
BaseContext,
66
ContextFunction,
77
HTTPGraphQLRequest,
8-
} from '../externalTypes';
8+
} from '../externalTypes/index.js';
99
import { parse as urlParse } from 'url';
1010

1111
export interface ExpressContextFunctionArgument {

packages/server/src/externalTypes/constructor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import type {
1010
} from 'graphql';
1111
import type { KeyValueCache } from '@apollo/utils.keyvaluecache';
1212
import type { GatewayInterface } from '@apollo/server-gateway-interface';
13-
import type { BaseContext } from '.';
14-
import type { ApolloServerPlugin } from './plugins';
13+
import type { ApolloServerPlugin } from './plugins.js';
14+
import type { BaseContext } from './index.js';
1515

1616
export type DocumentStore = KeyValueCache<DocumentNode>;
1717

packages/server/src/externalTypes/graphql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import type {
77
OperationDefinitionNode,
88
} from 'graphql';
99
import type { CachePolicy } from '@apollo/cache-control-types';
10-
import type { BaseContext } from './context';
11-
import type { HTTPGraphQLHead, HTTPGraphQLRequest } from './http';
10+
import type { BaseContext } from './context.js';
11+
import type { HTTPGraphQLHead, HTTPGraphQLRequest } from './http.js';
1212
import type { Logger } from '@apollo/utils.logger';
1313
import type { KeyValueCache } from '@apollo/utils.keyvaluecache';
1414

packages/server/src/externalTypes/plugins.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { KeyValueCache } from '@apollo/utils.keyvaluecache';
22
import type { Logger } from '@apollo/utils.logger';
33
import type { GraphQLResolveInfo, GraphQLSchema } from 'graphql';
4-
import type { ApolloConfig } from './constructor';
5-
import type { BaseContext } from './context';
6-
import type { GraphQLRequestContext, GraphQLResponse } from './graphql';
4+
import type { ApolloConfig } from './constructor.js';
5+
import type { BaseContext } from './context.js';
6+
import type { GraphQLRequestContext, GraphQLResponse } from './graphql.js';
77
import type {
88
GraphQLRequestContextDidEncounterErrors,
99
GraphQLRequestContextDidResolveOperation,
@@ -13,7 +13,7 @@ import type {
1313
GraphQLRequestContextResponseForOperation,
1414
GraphQLRequestContextValidationDidStart,
1515
GraphQLRequestContextWillSendResponse,
16-
} from './requestPipeline';
16+
} from './requestPipeline.js';
1717

1818
export interface GraphQLServerContext {
1919
readonly logger: Logger;

packages/server/src/externalTypes/requestPipeline.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { WithRequired } from '@apollo/utils.withrequired';
2-
import type { BaseContext } from './context';
3-
import type { GraphQLRequestContext } from './graphql';
2+
import type { BaseContext } from './context.js';
3+
import type { GraphQLRequestContext } from './graphql.js';
44

55
export type GraphQLRequestContextDidResolveSource<
66
TContext extends BaseContext,

0 commit comments

Comments
 (0)