Skip to content

Commit 5e5a0fc

Browse files
committed
test: run test against both graphql-js 16 and 17
1 parent f6a7096 commit 5e5a0fc

8 files changed

Lines changed: 53 additions & 10 deletions

File tree

.github/workflows/ci-todo-example.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@ jobs:
88
ci:
99
name: CI
1010
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
graphql_version:
14+
- "16"
15+
- "17.0.0-alpha.1"
1116
steps:
1217
- name: Checkout Repo
1318
uses: actions/checkout@master
1419
with:
1520
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
1621
fetch-depth: 0
1722

18-
- name: Setup Node.js 14.x
23+
- name: Setup Node.js 16.x
1924
uses: actions/setup-node@master
2025
with:
21-
node-version: 14.x
26+
node-version: 16.x
27+
28+
- name: Use GraphQL v${{matrix.graphql_version}}
29+
run: node ./scripts/match-graphql.js ${{matrix.graphql_version}}
2230

2331
- name: Install Dependencies
2432
run: yarn

.github/workflows/ci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@ jobs:
88
ci:
99
name: CI
1010
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
graphql_version:
14+
- "16"
15+
- "17.0.0-alpha.1"
1116
steps:
1217
- name: Checkout Repo
1318
uses: actions/checkout@master
1419
with:
1520
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
1621
fetch-depth: 0
1722

18-
- name: Setup Node.js 14.x
23+
- name: Setup Node.js 16.x
1924
uses: actions/setup-node@master
2025
with:
21-
node-version: 14.x
26+
node-version: 16.x
27+
28+
- name: Use GraphQL v${{matrix.graphql_version}}
29+
run: node ./scripts/match-graphql.js ${{matrix.graphql_version}}
2230

2331
- name: Install Dependencies
2432
run: yarn

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
1717
fetch-depth: 0
1818

19-
- name: Setup Node.js 14.x
19+
- name: Setup Node.js 16.x
2020
uses: actions/setup-node@master
2121
with:
22-
node-version: 14.x
22+
node-version: 16.x
2323

2424
- name: Install Dependencies
2525
run: yarn

jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const tsconfig = require(TSCONFIG);
88

99
module.exports = {
1010
transform: { "^.+\\.[jt]sx?$": "babel-jest" },
11-
transformIgnorePatterns: ["node_modules/(?!graphql)"],
1211
testEnvironment: "node",
1312
rootDir: ROOT_DIR,
1413
restoreMocks: true,

jest.end2end.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const tsconfig = require(TSCONFIG);
99
module.exports = {
1010
testEnvironment: "node",
1111
transform: { "^.+\\.[jt]sx?$": "babel-jest" },
12-
transformIgnorePatterns: ["node_modules/(?!graphql)"],
1312
rootDir: ROOT_DIR,
1413
restoreMocks: true,
1514
reporters: ["default"],

jest.project.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module.exports = ({ dirname, projectMode = true }) => {
1414
? {}
1515
: { displayName: pkg.name.replace("@graphql-codegen/", "") }),
1616
transform: { "^.+\\.[jt]sx?$": "babel-jest" },
17-
transformIgnorePatterns: ["node_modules/(?!graphql)"],
1817
testEnvironment: "node",
1918
rootDir: dirname,
2019
globals: {

scripts/cjsify-graphql.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@ const fileExists = (path) => {
2121

2222
console.log("Need some graphql commonjs?");
2323

24+
const pkgJSON = JSON.parse(fs.readFileSync(pkgJSONPath, "utf-8"));
25+
26+
const [major] = pkgJSON.version.split(".").map((value) => Number(value));
27+
if (major < 17) {
28+
console.log("this graphql version supports commonjs. all good.");
29+
process.exit(0);
30+
}
31+
2432
if (fileExists(oldPkgJSONPath)) {
2533
console.log("already applied everything. all good.");
2634
process.exit(0);
2735
}
2836

29-
const pkgJSON = JSON.parse(fs.readFileSync(pkgJSONPath, "utf-8"));
3037
fs.copyFileSync(pkgJSONPath, oldPkgJSONPath);
3138

3239
for (const [exportName, exportPathName] of Object.entries(pkgJSON.exports)) {

scripts/match-graphql.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
3+
const { writeFileSync } = require("fs");
4+
const { resolve } = require("path");
5+
const { argv } = require("process");
6+
7+
const pkgPath = resolve(__dirname, "..", "package.json");
8+
9+
const pkg = require(pkgPath);
10+
11+
const version = argv[2];
12+
13+
pkg.resolutions = pkg.resolutions || {};
14+
if (pkg.resolutions.graphql.startsWith(version)) {
15+
console.info(`GraphQL v${version} is match! Skipping.`);
16+
process.exit(0);
17+
}
18+
19+
const npmVersion = version.includes("-") ? version : `^${version}`;
20+
pkg.resolutions.graphql = npmVersion;
21+
pkg.devDependencies.graphql = npmVersion;
22+
23+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), "utf8");

0 commit comments

Comments
 (0)