Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
24
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ script:
# run coverage and file size checks
- npm run coverage:upload || true #ignore failures

# make sure files don't get too large
# make sure files don't get too large (bundlesize disabled, because it wouldn't install - see https://github.com/siddharthkp/bundlesize/pull/370)
- npm run filesize

# make sure there are no type errors
# make sure there are no type errors
- npm run check-types

# Allow Travis tests to run in containers.
Expand Down
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
10 changes: 0 additions & 10 deletions codecov.yml

This file was deleted.

5 changes: 2 additions & 3 deletions docs/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ Here is one way you might customize `RestLink`:

```js
import fetch from 'node-fetch';
import * as camelCase from 'camelcase';
import * as snake_case from 'snake-case';
import { camelCase, snakeCase } from 'change-case';

const link = new RestLink({
endpoints: { github: 'github.com' },
Expand All @@ -416,7 +415,7 @@ Here is one way you might customize `RestLink`:
},
credentials: "same-origin",
fieldNameNormalizer: (key: string) => camelCase(key),
fieldNameDenormalizer: (key: string) => snake_case(key),
fieldNameDenormalizer: (key: string) => snakeCase(key),
typePatcher: {
Post: ()=> {
bodySnippet...
Expand Down
47 changes: 30 additions & 17 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
module.exports = {
export default {
roots: ['<rootDir>/src'],
globals: {
'ts-jest': {
babelConfig: false,
mapCoverage: true,
compilerOptions: {
allowJs: true, // Necessary for jest.js
},
diagnostics: {
ignoreCodes: [
151001 // Suppress esModuleInterop suggestion that breaks __tests__/restLink.ts
]
}
},
},
preset: 'ts-jest/presets/default-esm',
extensionsToTreatAsEsm: ['.ts', '.tsx'],
transform: {
'.(ts|tsx)': 'ts-jest',
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
tsconfig: {
allowJs: true,
esModuleInterop: true,
},
diagnostics: {
ignoreCodes: [
151001, // Suppress esModuleInterop suggestion that breaks __tests__/restLink.ts
],
},
},
],
'^.+\\.jsx?$': [
'ts-jest',
{
useESM: true,
},
],
},
transformIgnorePatterns: ['node_modules/(?!(change-case|@fetch-mock)/)'],
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
setupFiles: ['./scripts/jest.js'],
setupFiles: ['./scripts/jest-setup.cjs'],
testEnvironment: 'jsdom',
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
};
77 changes: 37 additions & 40 deletions package.json
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I may, I would suggest adding support for the exports field in this release if you can as some bundlers treat the presence of that property as a breaking change. We waited to introduce it until 4.0 for this reason. Since v4 supports it, it should be safe to add exports as well in this package 🙂.

Copy link
Copy Markdown
Collaborator Author

@fbartho fbartho Nov 14, 2025

Choose a reason for hiding this comment

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

I'm not an expert at CJS/ESM nonsense 😉, what should my exports config look like?

These are the files in our built directory:

bundle.umd.js
bundle.umd.js.map
index.d.ts
index.js
index.js.map
LICENSE
package.json
README.md
restLink.d.ts
restLink.js
restLink.js.map
schema.graphql
utils

Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
{
"name": "apollo-link-rest",
"version": "0.9.0",
"version": "0.10.0-rc.2",
"description": "Query existing REST services with GraphQL",
"license": "MIT",
"main": "./lib/bundle.umd.js",
"module": "./lib/index.js",
"jsnext:main": "./lib/index.js",
"typings": "./lib/index.d.ts",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/apollographql/apollo-link-rest.git"
},
"bugs": {
"url": "https://github.com/apollographql/apollo-link-rest/issues"
},
"sideEffects": false,
"homepage": "https://github.com/apollographql/apollo-link-rest#readme",
"scripts": {
"build:browser": "browserify ./lib/bundle.umd.js -o=./lib/bundle.js --i @apollo/client/core --i @apollo/client/utilities --i graphql --i react && npm run minify:browser",
"build": "tsc -p .",
"bundle": "rollup -c",
"clean": "rimraf lib/* coverage/* npm/*",
"clean:modules": "rm -rf node_modules/",
"coverage:upload": "codecov",
"danger": "danger run --verbose",
"deploy": "./scripts/deploy.sh",
"docs:check": "./scripts/docs_check.sh",
"docs:pull": "./scripts/docs_pull.sh",
"docs:push": "./scripts/docs_push.sh",
"filesize": "npm run build && npm run build:browser && bundlesize",
"filesize": "npm run build && npm run build:browser && du lib",
"lint": "prettier --write 'src/**/*.{j,t}s*'",
"lint-staged": "lint-staged",
"minify:browser": "uglifyjs -c -m -o ./lib/bundle.min.js -- ./lib/bundle.js",
Expand All @@ -44,46 +45,44 @@
"check-types": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.tests.json"
},
"peerDependencies": {
"@apollo/client": ">=3",
"@apollo/client": ">=4",
"graphql": ">=0.11",
"qs": ">=6"
},
"devDependencies": {
"@apollo/client": "^3.0.0-beta.29",
"@apollo/link-error": "^2.0.0-beta.3",
"@apollo/client": "4.0.9",
"@babel/core": "7.x",
"@types/graphql": "14.x",
"@types/jest": "23.x",
"@types/node": "10.x",
"@types/qs": "6.5.x",
"browserify": "16.2.x",
"bundlesize": "0.17.x",
"camelcase": "5.0.x",
"codecov": "3.x",
"danger": "6.x",
"fetch-mock": "7.x",
"graphql": "14.x",
"isomorphic-fetch": "2.2.x",
"jest": "23.x",
"jest-fetch-mock": "2.x",
"lerna": "3.6.x",
"lint-staged": "8.1.x",
"@fetch-mock/jest": "^0.2.20",
"@jest/globals": "^30.2.0",
"@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@types/jest": "30.x",
"@types/node": "24.x",
"@types/qs": "6.14.x",
"browserify": "17.x",
"change-case": "5.x",
"danger": "13.x",
"fetch-mock": "12.6.x",
"graphql": "16.x",
"isomorphic-fetch": "3.x",
"jest": "30.x",
"jest-environment-jsdom": "^30.2.0",
"jest-fetch-mock": "3.x",
"lint-staged": "16.2.x",
"lodash": "4.17.x",
"pre-commit": "1.2.x",
"prettier": "1.15.x",
"qs": "6.6.x",
"rimraf": "2.6.x",
"rollup": "0.67.x",
"rollup-plugin-local-resolve": "1.0.x",
"rollup-plugin-sourcemaps": "0.4.x",
"snake-case": "2.1.x",
"ts-jest": "23.10.x",
"typescript": "3.x",
"uglify-js": "3.4.x"
"rimraf": "6.1.x",
"rollup": "^4.53.2",
"rxjs": "^7.8.2",
"ts-jest": "29.4.5",
"typescript": "5.x",
"uglify-js": "3.19.x",
"web-streams-polyfill": "^4.2.0"
},
"resolutions": {
"babel-core": "7.0.0-bridge.0",
"babel-jest": "23.6.0"
"disabledDependencies": {
"bundlesize": "0.18.x"
},
"bundlesize": [
{
Expand All @@ -94,17 +93,15 @@
],
"lint-staged": {
"*.ts*": [
"prettier --write",
"git add"
"prettier --write"
],
"*.js*": [
"prettier --write",
"git add"
"prettier --write"
],
"*.json*": [
"prettier --write",
"git add"
"prettier --write"
]
},
"pre-commit": "lint-staged"
"pre-commit": "lint-staged",
"packageManager": "yarn@4.6.0"
}
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import resolve from 'rollup-plugin-local-resolve';
import sourcemaps from 'rollup-plugin-sourcemaps';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

const globals = {
'@apollo/client/core': 'apolloClient.core',
Expand All @@ -20,7 +20,7 @@ export default {
},
external: Object.keys(globals),
onwarn,
plugins: [resolve(), sourcemaps()],
plugins: [resolve(), commonjs()],
};

function onwarn(message) {
Expand Down
35 changes: 35 additions & 0 deletions scripts/jest-setup.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Setup fetch for JSDOM environment using CommonJS
// This runs before test files are loaded

// Polyfill ReadableStream for JSDOM (required by fetch-mock v12)
if (typeof global.ReadableStream === 'undefined') {
const streams = require('web-streams-polyfill');
global.ReadableStream = streams.ReadableStream;
global.WritableStream = streams.WritableStream;
global.TransformStream = streams.TransformStream;
}

// Provide a basic fetch for initialization
require('isomorphic-fetch');

// Create a placeholder that will be replaced by fetchMock
// Store original for tests that might need it
const originalFetch = global.fetch;

// Create a mutable reference that fetchMock can update
let currentFetch = originalFetch;

// Replace global.fetch with a function that calls whatever currentFetch points to
// This allows fetchMock to update the reference and have all code see the change
global.fetch = function(...args) {
return currentFetch.apply(this, args);
};

// Make the currentFetch reference available so fetchMock setup can update it
global.__setMockFetch = function(fn) {
currentFetch = fn;
};

// Also set up globalThis
globalThis.fetch = global.fetch;
globalThis.__setMockFetch = global.__setMockFetch;
8 changes: 8 additions & 0 deletions scripts/jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Polyfill fetch for JSDOM environment first
import 'isomorphic-fetch';

// Import and set up fetch-mock globally for all tests
import fetchMock from '@fetch-mock/jest';

// Patch global fetch for all tests
fetchMock.mockGlobal();
4 changes: 0 additions & 4 deletions scripts/jest.js

This file was deleted.

Loading