Skip to content

Commit 7fa08fc

Browse files
committed
Avoid using globalThis
1 parent 595c687 commit 7fa08fc

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

.changeset/mighty-clouds-taste.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-tools/delegate': patch
3+
'@graphql-tools/utils': patch
4+
---
5+
6+
enhance: avoid using globalThis

packages/batch-delegate/src/getLoader.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ const getLoadersMap = memoize3(function getLoadersMap<K, V, C>(
6161
return new Map<string, DataLoader<K, V, C>>();
6262
});
6363

64+
const GLOBAL_CONTEXT = {};
65+
6466
export function getLoader<K = any, V = any, C = K>(options: BatchDelegateOptions<any>): DataLoader<K, V, C> {
6567
const { schema, fieldName, context, info, dataLoaderOptions } = options;
6668
const targetFieldName = fieldName ?? info.fieldName;
67-
const loaders = getLoadersMap<K, V, C>(context ?? globalThis ?? window ?? global, info.fieldNodes, schema);
69+
const loaders = getLoadersMap<K, V, C>(context ?? GLOBAL_CONTEXT, info.fieldNodes, schema);
6870

6971
let loader = loaders.get(targetFieldName);
7072

packages/delegate/src/delegateToSchema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ function validateRequest(delegationContext: DelegationContext<any>, document: Do
186186
}
187187
}
188188

189+
const GLOBAL_CONTEXT = {};
190+
189191
function getExecutor<TContext>(delegationContext: DelegationContext<TContext>): Executor<TContext> {
190192
const { subschemaConfig, targetSchema, context } = delegationContext;
191193

@@ -194,7 +196,7 @@ function getExecutor<TContext>(delegationContext: DelegationContext<TContext>):
194196
if (subschemaConfig?.batch) {
195197
const batchingOptions = subschemaConfig?.batchingOptions;
196198
executor = getBatchingExecutor(
197-
context ?? globalThis ?? window ?? global,
199+
context ?? GLOBAL_CONTEXT,
198200
executor,
199201
batchingOptions?.dataLoaderOptions,
200202
batchingOptions?.extensionsReducer

packages/utils/src/AggregateError.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ interface AggregateErrorConstructor {
99
readonly prototype: AggregateError;
1010
}
1111

12-
let AggregateErrorImpl: AggregateErrorConstructor = globalThis.AggregateError;
12+
let AggregateErrorImpl: AggregateErrorConstructor;
1313

14-
if (typeof AggregateErrorImpl === 'undefined') {
14+
if (typeof AggregateError === 'undefined') {
1515
class AggregateErrorClass extends Error implements AggregateError {
1616
constructor(public errors: any[], message = '') {
1717
super(message);
@@ -22,6 +22,8 @@ if (typeof AggregateErrorImpl === 'undefined') {
2222
AggregateErrorImpl = function (errors: any[], message?: string) {
2323
return new AggregateErrorClass(errors, message);
2424
} as AggregateErrorConstructor;
25+
} else {
26+
AggregateErrorImpl = AggregateError;
2527
}
2628

2729
export { AggregateErrorImpl as AggregateError };

0 commit comments

Comments
 (0)