From b3b985c0579afbf02ac7b793077c59a87eb3f9de Mon Sep 17 00:00:00 2001 From: Sergiu Danalachi Date: Fri, 8 Oct 2021 19:38:53 +0300 Subject: [PATCH 1/3] Fix circular dependency (issue when using @rollup/plugin-commonjs) --- .../src/plugin/schemaReporting/schemaReporter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/apollo-server-core/src/plugin/schemaReporting/schemaReporter.ts b/packages/apollo-server-core/src/plugin/schemaReporting/schemaReporter.ts index 510bd5671e1..894f6311111 100644 --- a/packages/apollo-server-core/src/plugin/schemaReporting/schemaReporter.ts +++ b/packages/apollo-server-core/src/plugin/schemaReporting/schemaReporter.ts @@ -1,4 +1,4 @@ -import { gql } from '../..'; +import gqlTag from 'graphql-tag'; import { fetch, Headers, Request } from 'apollo-server-env'; import type { GraphQLRequest, Logger } from 'apollo-server-types'; import { print } from 'graphql'; @@ -9,7 +9,7 @@ import type { ReportSchemaResponse, } from './operations'; -export const schemaReportGql = print(gql` +export const schemaReportGql = print(gqlTag` mutation SchemaReport($report: SchemaReport!, $coreSchema: String) { reportSchema(report: $report, coreSchema: $coreSchema) { __typename From b2fc35e22633c4823a896b3d0ef4df0e38363ff6 Mon Sep 17 00:00:00 2001 From: Sergiu Danalachi Date: Sat, 9 Oct 2021 10:05:30 +0300 Subject: [PATCH 2/3] Move gql def to separate module --- packages/apollo-server-core/src/gql.ts | 8 ++++++++ packages/apollo-server-core/src/index.ts | 10 +--------- .../src/plugin/schemaReporting/schemaReporter.ts | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 packages/apollo-server-core/src/gql.ts diff --git a/packages/apollo-server-core/src/gql.ts b/packages/apollo-server-core/src/gql.ts new file mode 100644 index 00000000000..f1ddaf62299 --- /dev/null +++ b/packages/apollo-server-core/src/gql.ts @@ -0,0 +1,8 @@ +// This currently provides the ability to have syntax highlighting as well as +// consistency between client and server gql tags +import type { DocumentNode } from 'graphql'; +import gqlTag from 'graphql-tag'; +export const gql: ( + template: TemplateStringsArray | string, + ...substitutions: any[] +) => DocumentNode = gqlTag; diff --git a/packages/apollo-server-core/src/index.ts b/packages/apollo-server-core/src/index.ts index 46bcdedce74..720fd3f9ef8 100644 --- a/packages/apollo-server-core/src/index.ts +++ b/packages/apollo-server-core/src/index.ts @@ -39,13 +39,5 @@ export { GraphQLExecutionResult, } from 'apollo-server-types'; -// This currently provides the ability to have syntax highlighting as well as -// consistency between client and server gql tags -import type { DocumentNode } from 'graphql'; -import gqlTag from 'graphql-tag'; -export const gql: ( - template: TemplateStringsArray | string, - ...substitutions: any[] -) => DocumentNode = gqlTag; - +export * from './gql'; export * from './plugin'; diff --git a/packages/apollo-server-core/src/plugin/schemaReporting/schemaReporter.ts b/packages/apollo-server-core/src/plugin/schemaReporting/schemaReporter.ts index 894f6311111..f45c5b3bbc0 100644 --- a/packages/apollo-server-core/src/plugin/schemaReporting/schemaReporter.ts +++ b/packages/apollo-server-core/src/plugin/schemaReporting/schemaReporter.ts @@ -1,4 +1,4 @@ -import gqlTag from 'graphql-tag'; +import { gql } from '../../gql'; import { fetch, Headers, Request } from 'apollo-server-env'; import type { GraphQLRequest, Logger } from 'apollo-server-types'; import { print } from 'graphql'; @@ -9,7 +9,7 @@ import type { ReportSchemaResponse, } from './operations'; -export const schemaReportGql = print(gqlTag` +export const schemaReportGql = print(gql` mutation SchemaReport($report: SchemaReport!, $coreSchema: String) { reportSchema(report: $report, coreSchema: $coreSchema) { __typename From fd284d95268d154705a825a4ecd11ac2496ac125 Mon Sep 17 00:00:00 2001 From: Sergiu Danalachi Date: Sat, 9 Oct 2021 10:12:34 +0300 Subject: [PATCH 3/3] Add rollup test --- package-lock.json | 210 ++++++++++++++++++ package.json | 3 + .../src/__tests__/rollupCommonJs.test.ts | 27 +++ 3 files changed, 240 insertions(+) create mode 100644 packages/apollo-server-core/src/__tests__/rollupCommonJs.test.ts diff --git a/package-lock.json b/package-lock.json index e549dea9153..4f79627faa0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,6 +43,8 @@ "@graphql-tools/utils": "8.2.5", "@hapi/hapi": "20.2.0", "@josephg/resolvable": "1.0.1", + "@rollup/plugin-commonjs": "21.0.0", + "@rollup/plugin-json": "4.1.0", "@sinonjs/fake-timers": "8.0.1", "@types/async-retry": "1.4.3", "@types/aws-lambda": "8.10.83", @@ -103,6 +105,7 @@ "qs-middleware": "1.0.3", "request-promise": "4.2.6", "requisition": "1.7.0", + "rollup": "2.58.0", "supertest": "6.1.6", "test-listen": "1.1.0", "ts-jest": "27.0.5", @@ -5757,6 +5760,62 @@ "version": "1.1.0", "license": "BSD-3-Clause" }, + "node_modules/@rollup/plugin-commonjs": { + "version": "21.0.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-21.0.0.tgz", + "integrity": "sha512-XDQimjHl0kNotAV5lLo34XoygaI0teqiKGJ100B3iCU8+15YscJPeqk2KqkqD3NIe1H8ZTUo5lYjUFZyEgASTw==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^3.1.0", + "commondir": "^1.0.1", + "estree-walker": "^2.0.1", + "glob": "^7.1.6", + "is-reference": "^1.2.1", + "magic-string": "^0.25.7", + "resolve": "^1.17.0" + }, + "engines": { + "node": ">= 8.0.0" + }, + "peerDependencies": { + "rollup": "^2.38.3" + } + }, + "node_modules/@rollup/plugin-json": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-4.1.0.tgz", + "integrity": "sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^3.0.8" + }, + "peerDependencies": { + "rollup": "^1.20.0 || ^2.0.0" + } + }, + "node_modules/@rollup/pluginutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", + "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", + "dev": true, + "dependencies": { + "@types/estree": "0.0.39", + "estree-walker": "^1.0.1", + "picomatch": "^2.2.2" + }, + "engines": { + "node": ">= 8.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0" + } + }, + "node_modules/@rollup/pluginutils/node_modules/estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", + "dev": true + }, "node_modules/@samverschueren/stream-to-observable": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.1.tgz", @@ -5977,6 +6036,12 @@ "@types/node": "*" } }, + "node_modules/@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, "node_modules/@types/express": { "version": "4.17.13", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.13.tgz", @@ -8069,6 +8134,12 @@ "node": ">=4.0.0" } }, + "node_modules/commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=", + "dev": true + }, "node_modules/compare-func": { "version": "2.0.0", "dev": true, @@ -9204,6 +9275,12 @@ "node": ">=4.0" } }, + "node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true + }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -11320,6 +11397,15 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "dev": true }, + "node_modules/is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "dev": true, + "dependencies": { + "@types/estree": "*" + } + }, "node_modules/is-regex": { "version": "1.1.2", "dev": true, @@ -14752,6 +14838,15 @@ "node": ">=10" } }, + "node_modules/magic-string": { + "version": "0.25.7", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", + "integrity": "sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==", + "dev": true, + "dependencies": { + "sourcemap-codec": "^1.4.4" + } + }, "node_modules/make-dir": { "version": "3.1.0", "dev": true, @@ -17551,6 +17646,21 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/rollup": { + "version": "2.58.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.58.0.tgz", + "integrity": "sha512-NOXpusKnaRpbS7ZVSzcEXqxcLDOagN6iFS8p45RkoiMqPHDLwJm758UF05KlMoCRbLBTZsPOIa887gZJ1AiXvw==", + "dev": true, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=10.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, "node_modules/run-async": { "version": "2.4.1", "dev": true, @@ -18021,6 +18131,12 @@ "source-map": "^0.6.0" } }, + "node_modules/sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", + "dev": true + }, "node_modules/spdx-correct": { "version": "3.1.0", "dev": true, @@ -24597,6 +24713,49 @@ "@protobufjs/utf8": { "version": "1.1.0" }, + "@rollup/plugin-commonjs": { + "version": "21.0.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-21.0.0.tgz", + "integrity": "sha512-XDQimjHl0kNotAV5lLo34XoygaI0teqiKGJ100B3iCU8+15YscJPeqk2KqkqD3NIe1H8ZTUo5lYjUFZyEgASTw==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.1.0", + "commondir": "^1.0.1", + "estree-walker": "^2.0.1", + "glob": "^7.1.6", + "is-reference": "^1.2.1", + "magic-string": "^0.25.7", + "resolve": "^1.17.0" + } + }, + "@rollup/plugin-json": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-4.1.0.tgz", + "integrity": "sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.0.8" + } + }, + "@rollup/pluginutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", + "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", + "dev": true, + "requires": { + "@types/estree": "0.0.39", + "estree-walker": "^1.0.1", + "picomatch": "^2.2.2" + }, + "dependencies": { + "estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", + "dev": true + } + } + }, "@samverschueren/stream-to-observable": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.1.tgz", @@ -24786,6 +24945,12 @@ "@types/node": "*" } }, + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, "@types/express": { "version": "4.17.13", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.13.tgz", @@ -26582,6 +26747,12 @@ "integrity": "sha512-6P6g0uetGpW/sdyUy/iQQCbFF0kWVMSIVSyYz7Zgjcgh8mgw8PQzDNZeyZ5DQ2gM7LBoZPHmnjz8rUthkBG5tw==", "dev": true }, + "commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=", + "dev": true + }, "compare-func": { "version": "2.0.0", "dev": true, @@ -27387,6 +27558,12 @@ "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==", "dev": true }, + "estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true + }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -28847,6 +29024,15 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "dev": true }, + "is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "dev": true, + "requires": { + "@types/estree": "*" + } + }, "is-regex": { "version": "1.1.2", "dev": true, @@ -31440,6 +31626,15 @@ "yallist": "^4.0.0" } }, + "magic-string": { + "version": "0.25.7", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", + "integrity": "sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==", + "dev": true, + "requires": { + "sourcemap-codec": "^1.4.4" + } + }, "make-dir": { "version": "3.1.0", "dev": true, @@ -33421,6 +33616,15 @@ "glob": "^7.1.3" } }, + "rollup": { + "version": "2.58.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.58.0.tgz", + "integrity": "sha512-NOXpusKnaRpbS7ZVSzcEXqxcLDOagN6iFS8p45RkoiMqPHDLwJm758UF05KlMoCRbLBTZsPOIa887gZJ1AiXvw==", + "dev": true, + "requires": { + "fsevents": "~2.3.2" + } + }, "run-async": { "version": "2.4.1", "dev": true @@ -33758,6 +33962,12 @@ "source-map": "^0.6.0" } }, + "sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", + "dev": true + }, "spdx-correct": { "version": "3.1.0", "dev": true, diff --git a/package.json b/package.json index dbaab95695a..5a675e0cbf1 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,8 @@ "@graphql-tools/utils": "8.2.5", "@hapi/hapi": "20.2.0", "@josephg/resolvable": "1.0.1", + "@rollup/plugin-commonjs": "21.0.0", + "@rollup/plugin-json": "4.1.0", "@sinonjs/fake-timers": "8.0.1", "@types/async-retry": "1.4.3", "@types/aws-lambda": "8.10.83", @@ -123,6 +125,7 @@ "qs-middleware": "1.0.3", "request-promise": "4.2.6", "requisition": "1.7.0", + "rollup": "2.58.0", "supertest": "6.1.6", "test-listen": "1.1.0", "ts-jest": "27.0.5", diff --git a/packages/apollo-server-core/src/__tests__/rollupCommonJs.test.ts b/packages/apollo-server-core/src/__tests__/rollupCommonJs.test.ts new file mode 100644 index 00000000000..9cc304405bc --- /dev/null +++ b/packages/apollo-server-core/src/__tests__/rollupCommonJs.test.ts @@ -0,0 +1,27 @@ +const rollup = require('rollup'); +import json from '@rollup/plugin-json'; +import commonjs from '@rollup/plugin-commonjs'; +import path from 'path'; + +describe('@rollup/plugin-commonjs', () => { + it('bundles into es6 without circular dependencies issues', async () => { + const outputOptions = { + exports: 'named', + name: 'apollo', + format: 'umd', + sourcemapExcludeSources: false, + }; + const bundle = await rollup.rollup({ + input: path.resolve(__dirname, '..', '..', 'dist', 'index.js'), + plugins: [json(), commonjs()], + onwarn: () => { + /* suppress warnings */ + }, + }); + const { output } = await bundle.generate(outputOptions); + const indexBundle = output[0].code; + var varDefinedAfterBundle; + eval(`${indexBundle}; varDefinedAfterBundle = 'foo';`); + expect(varDefinedAfterBundle).toEqual('foo'); + }); +});