Skip to content

Commit

Permalink
feat: support TypeScript esm + esm and cjs import tests on CI (#4539)
Browse files Browse the repository at this point in the history
* feat: support TypeScript esm + esm and cjs import tests on CI

* chore: workaround broken apollo-client import mess

* chore: adjust webpack path

* chore: add changeset

* chore: upgrade bob

* chore: upgrade bob version

* chore: change wording
  • Loading branch information
n1ru4l committed Jun 27, 2022
1 parent f6dfa93 commit d76a299
Show file tree
Hide file tree
Showing 305 changed files with 1,932 additions and 1,202 deletions.
36 changes: 36 additions & 0 deletions .changeset/nine-carrots-serve.md
@@ -0,0 +1,36 @@
---
'@graphql-tools/batch-delegate': minor
'@graphql-tools/batch-execute': minor
'@graphql-tools/delegate': minor
'@graphql-tools/graphql-tag-pluck': minor
'graphql-tools': minor
'@graphql-tools/import': minor
'@graphql-tools/jest-transform': minor
'@graphql-tools/links': minor
'@graphql-tools/load': minor
'@graphql-tools/load-files': minor
'@graphql-tools/apollo-engine-loader': minor
'@graphql-tools/code-file-loader': minor
'@graphql-tools/git-loader': minor
'@graphql-tools/github-loader': minor
'@graphql-tools/graphql-file-loader': minor
'@graphql-tools/json-file-loader': minor
'@graphql-tools/module-loader': minor
'@graphql-tools/prisma-loader': minor
'@graphql-tools/url-loader': minor
'@graphql-tools/merge': minor
'@graphql-tools/mock': minor
'@graphql-tools/node-require': minor
'@graphql-tools/optimize': minor
'@graphql-tools/relay-operation-optimizer': minor
'@graphql-tools/resolvers-composition': minor
'@graphql-tools/schema': minor
'@graphql-tools/stitch': minor
'@graphql-tools/stitching-directives': minor
'@graphql-tools/utils': minor
'@graphql-tools/webpack-loader': minor
'@graphql-tools/webpack-loader-runtime': minor
'@graphql-tools/wrap': minor
---

Support TypeScript module resolution.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Expand Up @@ -185,8 +185,8 @@ jobs:
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Build Packages
run: yarn build
- name: Test ESM
run: node scripts/test-esm.mjs
- name: Test ESM and CJS integrity
run: yarn bob check
test_browser:
name: Browser Test
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Expand Up @@ -21,6 +21,7 @@ packages/loaders/git/tests/test-files/type-defs-invalid.graphql
packages/loaders/json-file/tests/test-files/failing/malformed.json
website/.next
website/out
.bob
CHANGELOG.md

# temporarly ignore follow files because prettier-ignore comments don't work in mdx2
Expand Down
3 changes: 2 additions & 1 deletion jest.config.js
Expand Up @@ -11,9 +11,10 @@ module.exports = {
rootDir: ROOT_DIR,
restoreMocks: true,
reporters: ['default'],
modulePathIgnorePatterns: ['dist', 'test-assets', 'test-files', 'fixtures'],
modulePathIgnorePatterns: ['dist', 'test-assets', 'test-files', 'fixtures', '.bob'],
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { prefix: `${ROOT_DIR}/` }),
collectCoverage: false,
cacheDirectory: resolve(ROOT_DIR, `${CI ? '' : 'node_modules/'}.cache/jest`),
transformIgnorePatterns: ['node_modules/(?!graphql)'],
resolver: 'bob-the-bundler/jest-resolver.js',
};
21 changes: 9 additions & 12 deletions package.json
Expand Up @@ -7,9 +7,8 @@
"predeploy:website": "yarn build:api-docs",
"deploy:website": "cd website && yarn deploy",
"ts:check": "tsc --noEmit",
"ts:transpile": "tsc --project tsconfig.build.json",
"clean-dist": "rimraf \"packages/**/dist\" && rimraf \".bob\"",
"build": "yarn ts:transpile && bob build",
"build": "bob build",
"build:api-docs": "ts-node --compiler-options='{\"module\":\"commonjs\"}' scripts/build-api-docs",
"lint": "eslint --ext .ts .",
"prettier": "prettier --ignore-path .prettierignore --write --list-different .",
Expand Down Expand Up @@ -50,7 +49,7 @@
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"babel-jest": "28.1.1",
"bob-the-bundler": "1.7.3",
"bob-the-bundler": "2.0.0",
"chalk": "4.1.2",
"concurrently": "7.2.2",
"eslint": "8.18.0",
Expand Down Expand Up @@ -79,18 +78,16 @@
"packages/**/src/**/*.{ts,tsx}": [
"eslint --fix"
],
"**/*.{ts,tsx,graphql,yml,md,mdx}": [
"**/*.{ts,tsx,graphql,yml,md,mdx,json}": [
"prettier --write"
]
},
"workspaces": {
"packages": [
"./packages/*",
"./packages/loaders/*",
"./website",
"./benchmark/*"
]
},
"workspaces": [
"./packages/*",
"./packages/loaders/*",
"./website",
"./benchmark/*"
],
"resolutions": {
"graphql": "16.5.0",
"esbuild": "^0.14.0",
Expand Down
46 changes: 34 additions & 12 deletions packages/batch-delegate/package.json
Expand Up @@ -9,21 +9,42 @@
},
"license": "MIT",
"sideEffects": false,
"main": "dist/index.js",
"module": "dist/index.mjs",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
"require": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/cjs/index.js"
},
"import": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
},
"default": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
"require": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/cjs/*.js"
},
"import": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
},
"default": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
}
},
"./package.json": "./package.json"
},
"typings": "dist/index.d.ts",
"typings": "dist/typings/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
"definition": "dist/typings/index.d.ts"
},
"peerDependencies": {
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
Expand All @@ -42,7 +63,8 @@
"@graphql-tools/stitch": "8.6.14"
},
"publishConfig": {
"access": "public",
"directory": "dist"
}
"directory": "dist",
"access": "public"
},
"type": "module"
}
4 changes: 2 additions & 2 deletions packages/batch-delegate/src/batchDelegateToSchema.ts
@@ -1,6 +1,6 @@
import { BatchDelegateOptions } from './types';
import { BatchDelegateOptions } from './types.js';

import { getLoader } from './getLoader';
import { getLoader } from './getLoader.js';

export function batchDelegateToSchema<TContext = any>(options: BatchDelegateOptions<TContext>): any {
const key = options.key;
Expand Down
4 changes: 2 additions & 2 deletions packages/batch-delegate/src/createBatchDelegateFn.ts
@@ -1,8 +1,8 @@
import DataLoader from 'dataloader';

import { CreateBatchDelegateFnOptions, BatchDelegateOptionsFn, BatchDelegateFn } from './types';
import { CreateBatchDelegateFnOptions, BatchDelegateOptionsFn, BatchDelegateFn } from './types.js';

import { getLoader } from './getLoader';
import { getLoader } from './getLoader.js';

export function createBatchDelegateFn<K = any, V = any, C = K>(
optionsOrArgsFromKeys: CreateBatchDelegateFnOptions | ((keys: ReadonlyArray<K>) => Record<string, any>),
Expand Down
2 changes: 1 addition & 1 deletion packages/batch-delegate/src/getLoader.ts
Expand Up @@ -5,7 +5,7 @@ import DataLoader from 'dataloader';
import { delegateToSchema, SubschemaConfig } from '@graphql-tools/delegate';
import { memoize3, relocatedError } from '@graphql-tools/utils';

import { BatchDelegateOptions } from './types';
import { BatchDelegateOptions } from './types.js';

function createBatchFn<K = any>(options: BatchDelegateOptions) {
const argsFromKeys = options.argsFromKeys ?? ((keys: ReadonlyArray<K>) => ({ ids: keys }));
Expand Down
6 changes: 3 additions & 3 deletions packages/batch-delegate/src/index.ts
@@ -1,4 +1,4 @@
export * from './batchDelegateToSchema';
export * from './createBatchDelegateFn';
export * from './batchDelegateToSchema.js';
export * from './createBatchDelegateFn.js';

export * from './types';
export * from './types.js';
46 changes: 34 additions & 12 deletions packages/batch-execute/package.json
Expand Up @@ -9,21 +9,42 @@
},
"license": "MIT",
"sideEffects": false,
"main": "dist/index.js",
"module": "dist/index.mjs",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
"require": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/cjs/index.js"
},
"import": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
},
"default": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
"require": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/cjs/*.js"
},
"import": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
},
"default": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
}
},
"./package.json": "./package.json"
},
"typings": "dist/index.d.ts",
"typings": "dist/typings/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
"definition": "dist/typings/index.d.ts"
},
"peerDependencies": {
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
Expand All @@ -38,7 +59,8 @@
"value-or-promise": "1.0.11"
},
"publishConfig": {
"access": "public",
"directory": "dist"
}
"directory": "dist",
"access": "public"
},
"type": "module"
}
4 changes: 2 additions & 2 deletions packages/batch-execute/src/createBatchingExecutor.ts
Expand Up @@ -2,8 +2,8 @@ import DataLoader from 'dataloader';

import { Executor, ExecutionRequest, ExecutionResult, getOperationASTFromRequest } from '@graphql-tools/utils';

import { mergeRequests } from './mergeRequests';
import { splitResult } from './splitResult';
import { mergeRequests } from './mergeRequests.js';
import { splitResult } from './splitResult.js';

export function createBatchingExecutor(
executor: Executor,
Expand Down
2 changes: 1 addition & 1 deletion packages/batch-execute/src/getBatchingExecutor.ts
@@ -1,7 +1,7 @@
import DataLoader from 'dataloader';

import { ExecutionRequest, Executor, memoize2of4 } from '@graphql-tools/utils';
import { createBatchingExecutor } from './createBatchingExecutor';
import { createBatchingExecutor } from './createBatchingExecutor.js';

export const getBatchingExecutor = memoize2of4(function getBatchingExecutor(
_context: Record<string, any>,
Expand Down
4 changes: 2 additions & 2 deletions packages/batch-execute/src/index.ts
@@ -1,2 +1,2 @@
export * from './createBatchingExecutor';
export * from './getBatchingExecutor';
export * from './createBatchingExecutor.js';
export * from './getBatchingExecutor.js';
2 changes: 1 addition & 1 deletion packages/batch-execute/src/mergeRequests.ts
Expand Up @@ -17,7 +17,7 @@ import {

import { ExecutionRequest, getOperationASTFromRequest } from '@graphql-tools/utils';

import { createPrefix } from './prefix';
import { createPrefix } from './prefix.js';

/**
* Merge multiple queries into a single query in such a way that query results
Expand Down
2 changes: 1 addition & 1 deletion packages/batch-execute/src/splitResult.ts
Expand Up @@ -4,7 +4,7 @@ import { ExecutionResult, GraphQLError } from 'graphql';

import { relocatedError } from '@graphql-tools/utils';

import { parseKey } from './prefix';
import { parseKey } from './prefix.js';

/**
* Split and transform result of the query produced by the `merge` function
Expand Down
46 changes: 34 additions & 12 deletions packages/delegate/package.json
Expand Up @@ -9,21 +9,42 @@
},
"license": "MIT",
"sideEffects": false,
"main": "dist/index.js",
"module": "dist/index.mjs",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
"require": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/cjs/index.js"
},
"import": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
},
"default": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
"require": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/cjs/*.js"
},
"import": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
},
"default": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
}
},
"./package.json": "./package.json"
},
"typings": "dist/index.d.ts",
"typings": "dist/typings/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
"definition": "dist/typings/index.d.ts"
},
"peerDependencies": {
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
Expand All @@ -40,7 +61,8 @@
"value-or-promise": "1.0.11"
},
"publishConfig": {
"access": "public",
"directory": "dist"
}
"directory": "dist",
"access": "public"
},
"type": "module"
}
4 changes: 2 additions & 2 deletions packages/delegate/src/Subschema.ts
@@ -1,8 +1,8 @@
import { GraphQLSchema } from 'graphql';

import { SubschemaConfig, Transform, MergedTypeConfig, CreateProxyingResolverFn, BatchingOptions } from './types';
import { SubschemaConfig, Transform, MergedTypeConfig, CreateProxyingResolverFn, BatchingOptions } from './types.js';

import { applySchemaTransforms } from './applySchemaTransforms';
import { applySchemaTransforms } from './applySchemaTransforms.js';
import { Executor } from '@graphql-tools/utils';

export function isSubschema(value: any): value is Subschema {
Expand Down

0 comments on commit d76a299

Please sign in to comment.