Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dependency issue when using @rollup/plugin-commonjs #5797

Merged
merged 3 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
210 changes: 210 additions & 0 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions packages/apollo-server-core/src/__tests__/rollupCommonJs.test.ts
Original file line number Diff line number Diff line change
@@ -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'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth noting that I believe this works because our npm pretest script builds the package ahead of time.

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');
});
});
8 changes: 8 additions & 0 deletions packages/apollo-server-core/src/gql.ts
Original file line number Diff line number Diff line change
@@ -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;