Skip to content

Commit 04120de

Browse files
n1ru4lardatan
andauthored
graphql-js 16 support (#625)
* graphql-js 16 support * Bump v16 version * Fix parser types Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
1 parent 7a941f7 commit 04120de

File tree

58 files changed

+336
-229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+336
-229
lines changed

.changeset/ten-ads-visit.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
'@envelop/core': minor
3+
'@envelop/apollo-server-errors': minor
4+
'@envelop/apollo-tracing': minor
5+
'@envelop/auth0': minor
6+
'@envelop/dataloader': minor
7+
'@envelop/depth-limit': minor
8+
'@envelop/disable-introspection': minor
9+
'@envelop/execute-subscription-event': minor
10+
'@envelop/extended-validation': minor
11+
'@envelop/filter-operation-type': minor
12+
'@envelop/fragment-arguments': minor
13+
'@envelop/generic-auth': minor
14+
'@envelop/graphql-jit': minor
15+
'@envelop/graphql-middleware': minor
16+
'@envelop/graphql-modules': minor
17+
'@envelop/live-query': minor
18+
'@envelop/newrelic': minor
19+
'@envelop/opentelemetry': minor
20+
'@envelop/operation-field-permissions': minor
21+
'@envelop/parser-cache': minor
22+
'@envelop/persisted-operations': minor
23+
'@envelop/preload-assets': minor
24+
'@envelop/prometheus': minor
25+
'@envelop/rate-limiter': minor
26+
'@envelop/resource-limitations': minor
27+
'@envelop/response-cache': minor
28+
'@envelop/sentry': minor
29+
'@envelop/statsd': minor
30+
'@envelop/validation-cache': minor
31+
'@envelop/testing': minor
32+
'@envelop/types': minor
33+
---
34+
35+
add support for GraphQL.js 16

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
graphql_version:
3737
# - 14
3838
- 15
39-
# - 16.0.0-rc.1
39+
- 16.0.0-rc.7
4040
steps:
4141
- name: Checkout Master
4242
uses: actions/checkout@v2
@@ -67,7 +67,7 @@ jobs:
6767
graphql_version:
6868
# - 14
6969
- 15
70-
# - 16.0.0-rc.1
70+
- 16.0.0-rc.7
7171
steps:
7272
- name: Checkout Master
7373
uses: actions/checkout@v2

.vscode/settings.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"typescript.tsdk": "node_modules/typescript/lib",
33
"editor.defaultFormatter": "esbenp.prettier-vscode",
4-
"editor.formatOnSave": true
4+
"editor.formatOnSave": true,
5+
"files.exclude": {
6+
"**/.git": true,
7+
"**/.DS_Store": true,
8+
"**/node_modules": true,
9+
"test-lib": true,
10+
"lib": true,
11+
"coverage": true,
12+
"npm": true,
13+
"**/dist": true
14+
}
515
}

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"typescript": "4.4.4"
5050
},
5151
"peerDependencies": {
52-
"graphql": "^14.0.0 || ^15.0.0"
52+
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
5353
},
5454
"buildOptions": {
5555
"input": "./src/index.ts"

packages/core/src/orchestrator.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
OnContextErrorHandler,
2828
SubscribeErrorHook,
2929
DefaultContext,
30+
Maybe,
3031
} from '@envelop/types';
3132
import {
3233
DocumentNode,
@@ -40,7 +41,6 @@ import {
4041
validate,
4142
ValidationRule,
4243
} from 'graphql';
43-
import { Maybe } from 'graphql/jsutils/Maybe';
4444
import { prepareTracedSchema, resolversHooksSymbol } from './traced-schema';
4545
import { errorAsyncIterator, finalAsyncIterator, makeExecute, makeSubscribe, mapAsyncIterator } from './utils';
4646

@@ -307,7 +307,7 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>
307307
const afterCalls: SubscribeResultHook<PluginsContext>[] = [];
308308
const subscribeErrorHandlers: SubscribeErrorHook[] = [];
309309

310-
let context = args.contextValue || {};
310+
let context = (args.contextValue as {}) || {};
311311

312312
for (const onSubscribe of beforeCallbacks.subscribe) {
313313
const after = await onSubscribe({
@@ -338,9 +338,11 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>
338338
context[resolversHooksSymbol] = onResolversHandlers;
339339
}
340340

341-
let result = await subscribeFn({
341+
let result: AsyncIterableIteratorOrValue<ExecutionResult> = await subscribeFn({
342342
...args,
343343
contextValue: context,
344+
// Casted for GraphQL.js 15 compatibility
345+
// Can be removed once we drop support for GraphQL.js 15
344346
});
345347

346348
const onNextHandler: OnSubscribeResultResultOnNextHook<PluginsContext>[] = [];
@@ -399,7 +401,7 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>
399401
});
400402
}
401403

402-
return result;
404+
return result as AsyncIterableIterator<ExecutionResult>;
403405
});
404406

405407
const customExecute = beforeCallbacks.execute.length
@@ -409,7 +411,7 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>
409411
let result: AsyncIterableIteratorOrValue<ExecutionResult>;
410412

411413
const afterCalls: OnExecuteDoneHook<PluginsContext>[] = [];
412-
let context = args.contextValue || {};
414+
let context = (args.contextValue as {}) || {};
413415

414416
for (const onExecute of beforeCallbacks.execute) {
415417
let stopCalled = false;

packages/core/src/traced-orchestrator.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { DocumentNode, ExecutionArgs, GraphQLFieldResolver, GraphQLSchema, GraphQLTypeResolver, SubscriptionArgs } from 'graphql';
2-
import { Maybe } from 'graphql/jsutils/Maybe';
3-
import { ArbitraryObject, isAsyncIterable } from '@envelop/types';
2+
import { ArbitraryObject, isAsyncIterable, Maybe } from '@envelop/types';
43
import { EnvelopOrchestrator } from './orchestrator';
54

65
const HR_TO_NS = 1e9;
@@ -88,7 +87,8 @@ export function traceOrchestrator<TInitialContext extends ArbitraryObject, TPlug
8887
typeResolver,
8988
}
9089
: argsOrSchema;
91-
90+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
91+
// @ts-ignore GraphQL.js types contextValue as unknown
9292
const done = createTracer('execute', args.contextValue || {});
9393

9494
try {
@@ -97,6 +97,8 @@ export function traceOrchestrator<TInitialContext extends ArbitraryObject, TPlug
9797

9898
if (!isAsyncIterable(result)) {
9999
result.extensions = result.extensions || {};
100+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
101+
// @ts-ignore GraphQL.js types contextValue as unknown
100102
result.extensions.envelopTracing = args.contextValue._envelopTracing;
101103
} else {
102104
// eslint-disable-next-line no-console
@@ -135,6 +137,8 @@ export function traceOrchestrator<TInitialContext extends ArbitraryObject, TPlug
135137
subscribeFieldResolver,
136138
}
137139
: argsOrSchema;
140+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
141+
// @ts-ignore GraphQL.js types contextValue as unknown
138142
const done = createTracer('subscribe', args.contextValue || {});
139143

140144
try {

packages/core/src/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
PolymorphicExecuteArguments,
1717
PolymorphicSubscribeArguments,
1818
SubscribeFunction,
19+
PromiseOrValue,
1920
} from '@envelop/types';
20-
import { PromiseOrValue } from 'graphql/jsutils/PromiseOrValue';
2121

2222
export const envelopIsIntrospectionSymbol = Symbol('ENVELOP_IS_INTROSPECTION');
2323

@@ -73,13 +73,13 @@ function getSubscribeArgs(args: PolymorphicSubscribeArguments): SubscriptionArgs
7373
* Utility function for making a subscribe function that handles polymorphic arguments.
7474
*/
7575
export const makeSubscribe = (
76-
subscribeFn: (args: SubscriptionArgs) => PromiseOrValue<AsyncIterableIterator<ExecutionResult> | ExecutionResult>
76+
subscribeFn: (args: SubscriptionArgs) => PromiseOrValue<AsyncIterableIterator<ExecutionResult>>
7777
): SubscribeFunction =>
78-
((...polyArgs: PolymorphicSubscribeArguments): PromiseOrValue<AsyncIterableIterator<ExecutionResult> | ExecutionResult> =>
78+
((...polyArgs: PolymorphicSubscribeArguments): PromiseOrValue<AsyncIterableIterator<ExecutionResult>> =>
7979
subscribeFn(getSubscribeArgs(polyArgs))) as SubscribeFunction;
8080

8181
export async function* mapAsyncIterator<TInput, TOutput = TInput>(
82-
asyncIterable: AsyncIterableIterator<TInput>,
82+
asyncIterable: AsyncIterable<TInput>,
8383
map: (input: TInput) => Promise<TOutput> | TOutput
8484
): AsyncIterableIterator<TOutput> {
8585
for await (const value of asyncIterable) {
@@ -109,10 +109,10 @@ export const makeExecute = (
109109
executeFn: (args: ExecutionArgs) => PromiseOrValue<AsyncIterableIteratorOrValue<ExecutionResult>>
110110
): ExecuteFunction =>
111111
((...polyArgs: PolymorphicExecuteArguments): PromiseOrValue<AsyncIterableIteratorOrValue<ExecutionResult>> =>
112-
executeFn(getExecuteArgs(polyArgs))) as ExecuteFunction;
112+
executeFn(getExecuteArgs(polyArgs))) as unknown as ExecuteFunction;
113113

114114
export async function* finalAsyncIterator<TInput>(
115-
asyncIterable: AsyncIterableIterator<TInput>,
115+
asyncIterable: AsyncIterable<TInput>,
116116
onFinal: () => void
117117
): AsyncIterableIterator<TInput> {
118118
try {
@@ -123,7 +123,7 @@ export async function* finalAsyncIterator<TInput>(
123123
}
124124

125125
export async function* errorAsyncIterator<TInput>(
126-
asyncIterable: AsyncIterableIterator<TInput>,
126+
asyncIterable: AsyncIterable<TInput>,
127127
onError: (err: unknown) => void
128128
): AsyncIterableIterator<TInput> {
129129
try {

packages/plugins/apollo-federation/test/federation.spec.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { ApolloGateway, LocalGraphQLDataSource } from '@apollo/gateway';
21
import { assertSingleExecutionValue, createTestkit } from '@envelop/testing';
3-
import { execute } from 'graphql';
2+
import { execute, versionInfo } from 'graphql';
43
import { useApolloFederation } from '../src';
5-
import * as accounts from './fixtures/accounts';
6-
import * as products from './fixtures/products';
7-
import * as reviews from './fixtures/reviews';
84

95
describe('useApolloFederation', () => {
6+
if (versionInfo.major > 15) {
7+
it('dummy', () => {});
8+
return;
9+
}
1010
const query = /* GraphQL */ `
1111
# A query that the gateway resolves by calling all three services
1212
query GetCurrentUserReviews {
@@ -23,6 +23,11 @@ describe('useApolloFederation', () => {
2323
}
2424
`;
2525

26+
const { ApolloGateway, LocalGraphQLDataSource }: typeof import('@apollo/gateway') = require('@apollo/gateway');
27+
const accounts: typeof import('./fixtures/accounts') = require('./fixtures/accounts');
28+
const products: typeof import('./fixtures/products') = require('./fixtures/products');
29+
const reviews: typeof import('./fixtures/reviews') = require('./fixtures/reviews');
30+
2631
const gateway = new ApolloGateway({
2732
localServiceList: [
2833
{ name: 'accounts', typeDefs: accounts.typeDefs },

packages/plugins/apollo-server-errors/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"typescript": "4.4.4"
4040
},
4141
"peerDependencies": {
42-
"graphql": "^14.0.0 || ^15.0.0"
42+
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
4343
},
4444
"buildOptions": {
4545
"input": "./src/index.ts"

packages/plugins/apollo-server-errors/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const makeHandleResult =
88
if (result.errors && result.errors.length > 0) {
99
setResult({
1010
...result,
11+
// Upstream issue in apollo with GraphQL.js 16
12+
// Type 'ApolloError[]' is not assignable to type 'readonly GraphQLError[]'. Property '[Symbol.toStringTag]' is missing in type 'ApolloError' but required in type 'GraphQLError'.
13+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
14+
// @ts-ignore
1115
errors: formatApolloErrors(result.errors, {
1216
debug: options.debug,
1317
formatter: options.formatter,

0 commit comments

Comments
 (0)