Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .changeset/two-kiwis-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'@envelop/core': minor
'@envelop/apollo-tracing': minor
'@envelop/auth0': minor
'@envelop/dataloader': minor
'@envelop/depth-limit': minor
'@envelop/disable-introspection': minor
'@envelop/extended-validation': minor
'@envelop/filter-operation-type': minor
'@envelop/generic-auth': minor
'@envelop/graphql-jit': minor
'@envelop/graphql-middleware': minor
'@envelop/graphql-modules': minor
'@envelop/opentelemetry': minor
'@envelop/parser-cache': minor
'@envelop/persisted-operations': minor
'@envelop/preload-assets': minor
'@envelop/rate-limiter': minor
'@envelop/sentry': minor
'@envelop/validation-cache': minor
'@envelop/testing': minor
'@envelop/types': minor
---

ESM Support for all plugins and envelop core
2 changes: 1 addition & 1 deletion benchmark/k6.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const options = {
thresholds: {
no_errors: ['rate=1.0'],
expected_result: ['rate=1.0'],
http_req_duration: ['p(95)<=12'],
http_req_duration: ['p(95)<=15'],
graphql_execute: ['p(95)<=1'],
graphql_context: ['p(95)<=1'],
graphql_validate: ['p(95)<=1'],
Expand Down
14 changes: 14 additions & 0 deletions examples/with-esm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Envelop with ESM

If you are using ESM in your project, you can consume Envelop's core and plugins using ESM.

All bundles produced from this repo has `mjs` in addition to CommonJS.

### Running this example

To run this example:

1. Make sure to install deps on the root of the repo.
2. Run `yarn build`.
3. Run `yarn dev` in this directory.

19 changes: 19 additions & 0 deletions examples/with-esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@envelop-examples/with-esm",
"version": "0.0.1",
"scripts": {
"dev": "tsup-node src/index.ts --format esm --watch src --onSuccess \"node dist/index.mjs\"",
"start": "tsup-node src/index.ts --format esm --onSuccess \"node dist/index.mjs\""
},
"dependencies": {
"@envelop/core": "*",
"@graphql-tools/schema": "7.1.5",
"fastify": "3.14.0",
"graphql-helix": "1.6.1"
},
"devDependencies": {
"@types/node": "15.12.2",
"tsup": "4.11.2",
"typescript": "4.3.2"
}
}
68 changes: 68 additions & 0 deletions examples/with-esm/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-disable no-console */
import fastify from 'fastify';
import { getGraphQLParameters, processRequest, renderGraphiQL, shouldRenderGraphiQL } from 'graphql-helix';
import { envelop, useLogger, useSchema, useTiming } from '@envelop/core';
import { makeExecutableSchema } from '@graphql-tools/schema';

const schema = makeExecutableSchema({
typeDefs: /* GraphQL */ `
type Query {
hello: String!
}
`,
resolvers: {
Query: {
hello: () => 'World',
},
},
});

const getEnveloped = envelop({
plugins: [useSchema(schema), useLogger(), useTiming()],
});
const app = fastify();

app.route({
method: ['GET', 'POST'],
url: '/graphql',
async handler(req, res) {
const { parse, validate, contextFactory, execute, schema } = getEnveloped({ req });
const request = {
body: req.body,
headers: req.headers,
method: req.method,
query: req.query,
};

if (shouldRenderGraphiQL(request)) {
res.type('text/html');
res.send(renderGraphiQL({}));
} else {
const { operationName, query, variables } = getGraphQLParameters(request);
const result = await processRequest({
operationName,
query,
variables,
request,
schema,
parse,
validate,
execute,
contextFactory,
});

if (result.type === 'RESPONSE') {
res.status(result.status);
res.send(result.payload);
} else {
// You can find a complete example with GraphQL Subscriptions and stream/defer here:
// https://github.com/contrawork/graphql-helix/blob/master/examples/fastify/server.ts
res.send({ errors: [{ message: 'Not Supported in this demo' }] });
}
}
},
});

app.listen(3000, () => {
console.log(`GraphQL server is running in http://127.0.0.1:3000/graphql.`);
});
19 changes: 19 additions & 0 deletions examples/with-esm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es2019",
"module": "esnext",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noEmit": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
"./examples/lambda-aws",
"./examples/azure-functions",
"./examples/google-cloud-functions",
"./examples/cloudflare-workers"
"./examples/cloudflare-workers",
"./examples/with-esm"
],
"scripts": {
"prepare": "husky install",
"benchmark": "NODE_ENV=production ts-node --project tsconfig.benchmark.json benchmark/execute.case.ts",
"postinstall": "patch-package",
"lint": "eslint --config .eslintrc.json --ext .ts .",
"prebuild": "rimraf packages/*/dist",
"prebuild": "rimraf packages/*/dist packages/plugins/*/dist",
"build": "tsc --project tsconfig.json && bob build",
"test": "jest",
"test:ci": "jest --coverage",
Expand Down Expand Up @@ -48,7 +49,7 @@
"husky": "6.0.0",
"lint-staged": "11.0.0",
"@types/node": "15.6.1",
"bob-the-bundler": "1.2.1",
"bob-the-bundler": "1.4.1",
"eslint-config-standard": "16.0.3",
"eslint-plugin-import": "2.23.4",
"eslint-plugin-node": "11.1.0",
Expand Down
16 changes: 13 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@
"nodejs",
"typescript"
],
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand All @@ -34,7 +44,7 @@
"devDependencies": {
"@graphql-tools/utils": "7.10.0",
"@graphql-tools/schema": "7.1.5",
"bob-the-bundler": "1.2.1",
"bob-the-bundler": "1.4.1",
"graphql": "15.5.0",
"typescript": "4.3.2"
},
Expand Down
16 changes: 13 additions & 3 deletions packages/plugins/apollo-tracing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
"directory": "packages/plugins/apollo-tracing"
},
"sideEffects": false,
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand All @@ -24,7 +34,7 @@
},
"devDependencies": {
"@graphql-tools/schema": "7.1.5",
"bob-the-bundler": "1.2.1",
"bob-the-bundler": "1.4.1",
"graphql": "15.5.0",
"typescript": "4.3.2"
},
Expand Down
16 changes: 13 additions & 3 deletions packages/plugins/auth0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
"url": "https://github.com/dotansimha/envelop.git",
"directory": "packages/plugins/auth0"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand All @@ -25,7 +35,7 @@
},
"devDependencies": {
"@types/jsonwebtoken": "8.5.1",
"bob-the-bundler": "1.2.1",
"bob-the-bundler": "1.4.1",
"graphql": "15.5.0",
"typescript": "4.3.2"
},
Expand Down
16 changes: 13 additions & 3 deletions packages/plugins/dataloader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
"url": "https://github.com/dotansimha/envelop.git",
"directory": "packages/plugins/dataloader"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand All @@ -23,7 +33,7 @@
"devDependencies": {
"dataloader": "2.0.0",
"reflect-metadata": "0.1.13",
"bob-the-bundler": "1.2.1",
"bob-the-bundler": "1.4.1",
"graphql": "15.5.0",
"typescript": "4.3.2"
},
Expand Down
16 changes: 13 additions & 3 deletions packages/plugins/depth-limit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
"url": "https://github.com/dotansimha/envelop.git",
"directory": "packages/plugins/depth-limit"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand All @@ -24,7 +34,7 @@
},
"devDependencies": {
"@types/graphql-depth-limit": "1.1.2",
"bob-the-bundler": "1.2.1",
"bob-the-bundler": "1.4.1",
"graphql": "15.5.0",
"typescript": "4.3.2"
},
Expand Down
16 changes: 13 additions & 3 deletions packages/plugins/disable-introspection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
"url": "https://github.com/dotansimha/envelop.git",
"directory": "packages/plugins/disable-introspection"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand All @@ -21,7 +31,7 @@
},
"dependencies": {},
"devDependencies": {
"bob-the-bundler": "1.2.1",
"bob-the-bundler": "1.4.1",
"graphql": "15.5.0",
"typescript": "4.3.2"
},
Expand Down
16 changes: 13 additions & 3 deletions packages/plugins/extended-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
"url": "https://github.com/dotansimha/envelop.git",
"directory": "packages/plugins/extended-validation"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
Expand All @@ -21,7 +31,7 @@
},
"dependencies": {},
"devDependencies": {
"bob-the-bundler": "1.2.1",
"bob-the-bundler": "1.4.1",
"graphql": "15.5.0",
"typescript": "4.3.2"
},
Expand Down
Loading