Skip to content

Commit

Permalink
Inline @josephg/resolvable dependency (#7900)
Browse files Browse the repository at this point in the history
Issue #7895
reports that AS4 fails to build for ESM due to the resolvable
dependency.

I'm actually unsure _why_ this is happening though, since the shipped JS
appears to be ESM compatible:
https://unpkg.com/@josephg/resolvable@1.0.1/index.js

@macrozone would you mind testing the builds from this PR (see
Codesandbox CI comment) and letting me know if this resolves the issue
in your project?
  • Loading branch information
trevor-scheer authored Jul 22, 2024
1 parent 79dacd0 commit 86d7111
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .changeset/ninety-clouds-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@apollo/server-integration-testsuite": patch
"@apollo/server": patch
---

Inline a small dependency that was causing build issues for ESM projects
1 change: 0 additions & 1 deletion cspell-dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ instanceof
iosapp
isnodelike
iteratees
josephg
jsdelivr
keyv
keyvadapter
Expand Down
9 changes: 3 additions & 6 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"@graphql-codegen/typescript-operations": "3.0.4",
"@graphql-tools/mock": "8.7.20",
"@graphql-tools/schema": "9.0.19",
"@josephg/resolvable": "1.0.1",
"@rollup/plugin-commonjs": "25.0.7",
"@types/async-retry": "1.4.8",
"@types/compression": "1.7.5",
Expand Down
1 change: 0 additions & 1 deletion packages/integration-testsuite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"@apollo/usage-reporting-protobuf": "^4.1.1",
"@apollo/utils.createhash": "^2.0.0",
"@apollo/utils.keyvaluecache": "^2.1.0",
"@josephg/resolvable": "^1.0.1",
"express": "^4.18.1",
"graphql-http": "1.22.0",
"graphql-tag": "^2.12.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-testsuite/src/apolloServerTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
} from '@apollo/server';
import fetch, { type Headers } from 'node-fetch';

import resolvable, { type Resolvable } from '@josephg/resolvable';
import resolvable, { type Resolvable } from './resolvable.js';
import type { AddressInfo } from 'net';
import request, { type Response } from 'supertest';
import { InMemoryLRUCache } from '@apollo/utils.keyvaluecache';
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-testsuite/src/httpServerTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// function. Newer tests have generally been added to the apolloServerTests.ts
// file.
import { createHash } from '@apollo/utils.createhash';
import resolvable, { type Resolvable } from '@josephg/resolvable';
import resolvable, { type Resolvable } from './resolvable.js';
import {
BREAK,
type DocumentNode,
Expand Down
30 changes: 30 additions & 0 deletions packages/integration-testsuite/src/resolvable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2019 Joseph Gentle

// Permission to use, copy, modify, and / or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.

// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS.IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

export type Resolvable<T> = Promise<T> & {
resolve: (t: T) => void;
reject: (e: any) => void;
};

export default <T = void>(): Resolvable<T> => {
let resolve: (val: T) => void;
let reject: (err: any) => void;
const promise = new Promise<T>((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
}) as Resolvable<T>;
promise.resolve = resolve!;
promise.reject = reject!;
return promise;
};
1 change: 0 additions & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
"@apollo/utils.usagereporting": "^2.1.0",
"@apollo/utils.withrequired": "^2.0.0",
"@graphql-tools/schema": "^9.0.0",
"@josephg/resolvable": "^1.0.0",
"@types/express": "^4.17.13",
"@types/express-serve-static-core": "^4.17.30",
"@types/node-fetch": "^2.6.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import type { Logger } from '@apollo/utils.logger';
import type { WithRequired } from '@apollo/utils.withrequired';
import { makeExecutableSchema } from '@graphql-tools/schema';
import resolvable, { type Resolvable } from '@josephg/resolvable';
import resolvable, { type Resolvable } from './utils/resolvable.js';
import {
GraphQLError,
assertValidSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import compression, { filter as defaultFilter } from 'compression';
import { ApolloServer, BaseContext } from '../../index.js';
import { expressMiddleware } from '../../express4/index.js';
import { it, expect } from '@jest/globals';
import resolvable from '@josephg/resolvable';
import resolvable from '../../utils/resolvable.js';
import cors from 'cors';

it('gives helpful error if json middleware is not installed', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import path from 'path';
import type { AddressInfo } from 'net';
import { describe, it, expect, afterEach, beforeEach } from '@jest/globals';
import { AbortController } from 'node-abort-controller';
import resolvable, { Resolvable } from '@josephg/resolvable';
import resolvable, { Resolvable } from '../../../utils/resolvable.js';

function port(s: http.Server) {
return (s.address() as AddressInfo).port;
Expand Down
30 changes: 30 additions & 0 deletions packages/server/src/utils/resolvable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2019 Joseph Gentle

// Permission to use, copy, modify, and / or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.

// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS.IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

export type Resolvable<T> = Promise<T> & {
resolve: (t: T) => void;
reject: (e: any) => void;
};

export default <T = void>(): Resolvable<T> => {
let resolve: (val: T) => void;
let reject: (err: any) => void;
const promise = new Promise<T>((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
}) as Resolvable<T>;
promise.resolve = resolve!;
promise.reject = reject!;
return promise;
};

0 comments on commit 86d7111

Please sign in to comment.