Skip to content

Commit

Permalink
V3 (#1487)
Browse files Browse the repository at this point in the history
* feat: non-breaking GraphQL Engine

* feat: make envelop take in engine functions

* structural typings

* remove grapqhl as peer dep from types pkg

* make core more agnostic

* chore(dependencies): updated changesets for modified dependencies

* remove traced schema

* remove traced orchestrator

* make plugin agnostic

* drop EnvelopError

* remove more graphql import

* Drop useTiming

* make core completely free of graphql-js

* add eslint rule

* eslint disallow in types too

* more agnostic packages

* remove introspection util

* chore(dependencies): updated changesets for modified dependencies

* prettier

* TEMP: make bot calm down

* update all docs

* test matrix for core

* experimenting traced schema (#1501)

* experimenting traced schema

* Fix

* remove comment

* do optional chaining since we are not strongly typing

* document

* cleanup

Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>

* feat: drop node 12 (#1505)

* feat: remove `enableIf` utility (#1504)

* feat: remove enableIf utility

* make types happpy

* make types happy

* add changeset

* feat: remove async schema plugin and rename lazy loaded schema plugin (#1506)

* remove useAsyncSchema

* rename to useSchemaByContext

* add eslint rule (#1509)

* feat: `@envelop/on-resolve` plugin for hooking into schema resolvers (#1500)

* on resolve plugin

* changeset

* no more onResolverCalled

* unused import

* args is a record

* integrate and useOnResolve

* resolversHooksSymbol does not exist

* plugincontext for OnPluginInit

* on-resolve uses addPlugin

* onresolvercalled is no more

* refactor for new on-resolve

* fix open-telemetry tests

* fix newrelic

* opentelemetry graphql as peer dep

* tests

* addPlugin doesnt need to be used

* reorder

* respects onPluginInit context

* drop unused import

* fixes false positive eslint warnings

Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>

* docs: order of plugins matter (#1513)

* feat: remove handler for validation and parse errors (#1510)

* feat: remove hanlder for validation and parse errors

* tests

* make it work

* Add docs

* Fix serialization issue

* Go

* ..

* update docs

* update test

* make it work

* feat: add originalError in dev mode (#1514)

* remove Fn appendix

* name graphql error

* make ts happy

* make toJSON required

Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
Co-authored-by: Laurin Quast <laurinquast@googlemail.com>

* add changeset

* Update .changeset/nervous-seas-own.md

* Update .changeset/rude-cats-peel.md

* no-use-before-define (#1522)

* feat: trigger on context, validate and parse errors (#1511)

* feat: trigger on context, validate and parse errors

* trying

* make it work

* pass in phase

* add phase details

* feedback

* docs: migration guide (#1520)

* docs: migration guide

* remove slashes

* Update website/docs/guides/migrating-from-v2-to-v3.mdx

Co-authored-by: Denis Badurina <badurinadenis@gmail.com>

* feedback

* document removing of orchestrated tracer

* more feedback

* update docs

* update examples

* async schema example

Co-authored-by: Denis Badurina <badurinadenis@gmail.com>

* Add redirects

* remove deafult skip error from sentry plugin

* export masked error plugin

* sentry plugin default skip GraphQLError

* sentry: og error is not graphql error then send to sentry

* doc: drop introspection utils

* should fix ts issues on v15

* test: stack error we should not match the error name since it can be different across impl

* feat: use engine plugin (#1535)

* feat: use engine plugin

* remove assertion

* make useEngine plugin the only way to pass engine functions (#1536)

* make useEngine plugin the only way to pass engine fns

* update types

* update docs

* Update packages/plugins/apollo-datasources/README.md

Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>

* prettier:

Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>

Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>

* fix

* versioned docs with v3 default

* fix build

* fix

* feat this is cool

* docs reword schema tracing

* docs add graphql error example

* docs restructuring, fix typos

* chore remove autogenerated changeset

* cleanup changeset

* docs sycn patch

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
Co-authored-by: Denis Badurina <denis@domonda.com>
Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
Co-authored-by: Laurin Quast <laurinquast@googlemail.com>
Co-authored-by: Denis Badurina <badurinadenis@gmail.com>
  • Loading branch information
7 people committed Oct 12, 2022
1 parent 8b3c369 commit dc1e24b
Show file tree
Hide file tree
Showing 183 changed files with 6,797 additions and 1,607 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-fishes-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@envelop/core': major
---

## Remove `isIntrospectionQuery` utility
5 changes: 5 additions & 0 deletions .changeset/curvy-bottles-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@envelop/core': major
---

Remove async schema loading plugin. This was a mistake from beginning as we cannot asynchronously `validate` and `parse` since with GraphQL.js are synchronous in nature.
33 changes: 33 additions & 0 deletions .changeset/curvy-cheetahs-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
'@envelop/core': major
'@envelop/on-resolve': major
---

## Remove `onResolverCalled`

We decided to drop onResolverCalled hook and instead [provide a new plugin](https://github.com/n1ru4l/envelop/pull/1500) that will let you hook into this phase.

```diff
import { parse, validate, execute, subscribe } from 'graphql'
import { envelop, Plugin, useEngine } from '@envelop/core'
+ import { useOnResolve } from '@envelop/on-resolve'

import { onResolverCalled } from './my-resolver'

function useResolve(): Plugin {
return {
- onResolverCalled: onResolverCalled,
+ onPluginInit: ({ addPlugin }) => {
+ addPlugin(useOnResolve(onResolverCalled))
+ },
}
}

const getEnveloped = envelop({
plugins: [
useEngine({ parse, validate, execute, subscribe }),
// ... other plugins ...
useResolve(),
],
});
```
5 changes: 5 additions & 0 deletions .changeset/dirty-birds-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@envelop/sentry': major
---

Default skip reporting `GraphQLError`
7 changes: 7 additions & 0 deletions .changeset/dry-donuts-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@envelop/core': major
---

## Drop `useTiming` plugin

This plugin was dependent on tracing the schema. As we no longer support wrap the schema out of the box we decided to drop this plugin.
5 changes: 5 additions & 0 deletions .changeset/grumpy-windows-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@envelop/core': major
---

## Remove `isIntrospectionDocument` utility
7 changes: 7 additions & 0 deletions .changeset/late-students-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@envelop/core': major
---

## Drop Node v12 support

Node.js v12 is no longer supported by the Node.js team. https://github.com/nodejs/Release/#end-of-life-releases
7 changes: 7 additions & 0 deletions .changeset/light-bees-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@envelop/core': major
---

## Drop `EnvelopError` class

To keep the core agnostic from a specific implementation we no longer provide the `EnvelopError` class.
7 changes: 7 additions & 0 deletions .changeset/light-tomatoes-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@envelop/core': major
---

## Remove `useAsyncSchema` plugin

This was a mistake from beginning as we cannot asynchronously validate and parse since with [graphql](https://github.com/graphql/graphql-js) these functions are synchronous in nature.
19 changes: 19 additions & 0 deletions .changeset/lovely-clocks-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@envelop/core': major
---

## Remove `graphql` as a peer dependency

We have built the new `envelop` to be engine agnostic. `graphql-js` is no longer a peer dependency. Now you can use any spec compliant GraphQL engine with `envelop` and get the benefit of building a plugin system. We have introduced a new plugin that can be used to customize the GraphQL Engine.

```diff
- import { envelop } from '@envelop/core'
+ import { envelop, useEngine } from '@envelop/core'
+ import { parse, validate, execute, subscribe } from 'graphql';

- const getEnveloped = envelop([ ... ])
+ const getEnveloped = envelop({ plugins: [useEngine({ parse, validate, execute, subscribe })] })

```

Checkout the [migration guide](https://www.the-guild.dev/graphql/envelop/v3/guides/migrating-from-v2-to-v3) for more details.
5 changes: 5 additions & 0 deletions .changeset/nervous-seas-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@envelop/core': major
---

## Rename `useLazyLoadedSchema` to `useSchemaByContext` since the original name was vert misleading.
27 changes: 27 additions & 0 deletions .changeset/quiet-mice-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
'@envelop/core': major
---

Remove `enableIf` utility in favor of more type safe way to conditionally enable plugins. It wasn't a great experience to have a utility

We can easily replace usage like this:

```diff
- import { envelop, useMaskedErrors, enableIf } from '@envelop/core'
+ import { envelop, useMaskedErrors } from '@envelop/core'
import { parse, validate, execute, subscribe } from 'graphql'

const isProd = process.env.NODE_ENV === 'production'

const getEnveloped = envelop({
parse,
validate,
execute,
subscribe,
plugins: [
// This plugin is enabled only in production
- enableIf(isProd, useMaskedErrors())
+ isProd && useMaskedErrors()
]
})
```
10 changes: 10 additions & 0 deletions .changeset/rude-cats-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@envelop/core': major
---

Remove `handleValidationErrors` and `handleParseErrors` options from `useMaskedErrors`.

> ONLY masking validation errors OR ONLY disabling introspection errors does not make sense, as both can be abused for reverse-engineering the GraphQL schema (see https://github.com/nikitastupin/clairvoyance for reverse-engineering the schema based on validation error suggestions).
> https://github.com/n1ru4l/envelop/issues/1482#issue-1340015060
Rename `formatError` function option to `maskError`
5 changes: 5 additions & 0 deletions .changeset/silent-impalas-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@envelop/core': minor
---

respond to context, parse and validate errors in `useErrorHandler` plugin
7 changes: 7 additions & 0 deletions .changeset/warm-bulldogs-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@envelop/core': major
---

## Removed orchestrator tracing

`GraphQLSchema` was wrapped to provide resolvers/fields tracing from the schema. Issue with this approach was it was very specific to the underlying engine's implementation. With the new version we no longer want to depend to a specific implementation. Now users can wrap their schemas and add tracing themselves.
61 changes: 56 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
{
"parser": "@typescript-eslint/parser",
"extends": ["eslint:recommended", "standard", "prettier", "plugin:@typescript-eslint/recommended"],
"plugins": ["@typescript-eslint", "unicorn"],
"extends": [
"eslint:recommended",
"standard",
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:package-json/recommended"
],
"plugins": ["@typescript-eslint", "unicorn", "package-json"],
"rules": {
"unicorn/filename-case": "error",
"no-lonely-if": "error",
"unicorn/no-lonely-if": "error",
"no-empty": "off",
"no-console": "error",
"no-prototype-builtins": "off",
"prefer-arrow-callback": ["error", { "allowNamedFunctions": true }],
"prefer-arrow-callback": [
"error",
{
"allowNamedFunctions": true
}
],
"no-useless-constructor": "off",
"@typescript-eslint/no-unused-vars": ["warn", { "args": "none" }],
"no-use-before-define": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"args": "none"
}
],
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-empty-interface": "off",
Expand All @@ -26,7 +43,9 @@
"unicorn/no-useless-fallback-in-spread": "error",
"import/no-extraneous-dependencies": [
"error",
{ "devDependencies": ["**/*.test.ts", "**/*.spec.ts", "**/test/**/*.ts"] }
{
"devDependencies": ["**/*.test.ts", "**/*.spec.ts", "**/test/**/*.ts"]
}
]
},
"env": {
Expand All @@ -43,6 +62,38 @@
"@typescript-eslint/no-unused-vars": "off",
"import/no-extraneous-dependencies": "off"
}
},
// Disallow `graphql-js` specific things to get re-introduced in agnostic packages.
{
"files": [
"packages/core/**",
"packages/types/**",
"packages/plugins/apollo-datasources/**",
"packages/plugins/auth0/**",
"packages/plugins/dataloader/**",
"packages/plugins/preload-assets/**",
"packages/plugins/statsd/**"
],
"env": {
"jest": true
},
"rules": {
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "graphql",
"message": "You chose violence. Try to make it work without using GraphQL.js"
},
{
"name": "@graphql-tools/*",
"message": "You chose violence. Try to make it work without using `graphql-tools`"
}
]
}
]
}
}
],
"ignorePatterns": ["dist", "node_modules", "dev-test", "website"]
Expand Down
35 changes: 30 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,38 @@ jobs:
run: yarn ts:check

unit:
name: unit / ${{matrix.os}} / node v${{matrix.node-version}} / graphql v${{matrix.graphql_version}}
name: Unit Test
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-latest] # remove windows to speed up the tests
node-version: [12, 17]
graphql_version: [15, 16]
steps:
- name: Checkout Master
uses: actions/checkout@v2
- name: Setup env
uses: the-guild-org/shared-config/setup@main
with:
nodeVersion: 18
- name: Install Dependencies
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Cache Jest
uses: actions/cache@v2
with:
path: .cache/jest
key: ${{ runner.os }}-${{matrix.node-version}}-${{matrix.graphql_version}}-jest-${{ hashFiles('yarn.lock') }}-${{ hashFiles('patches/*.patch') }}
- name: Test
run: yarn test
env:
CI: true

core:
name: Core Test / ${{matrix.os}} / node v${{matrix.node-version}} / graphql v${{matrix.graphql_version}}
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-latest] # remove windows to speed up the tests
node-version: [14, 16, 17, 18]
graphql_version: [15, 16, 'npm:@graphql-tools/graphql@0.1.0-alpha-20220815193214-83898018']
steps:
- name: Checkout Master
uses: actions/checkout@v2
Expand All @@ -71,8 +96,8 @@ jobs:
with:
path: .cache/jest
key: ${{ runner.os }}-${{matrix.node-version}}-${{matrix.graphql_version}}-jest-${{ hashFiles('yarn.lock') }}-${{ hashFiles('patches/*.patch') }}
- name: Test
run: yarn test --ci
- name: Test Core
run: yarn test:core --ci
env:
CI: true

Expand Down
9 changes: 7 additions & 2 deletions examples/apollo-server/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-console */
import { ApolloServer } from 'apollo-server';
import { envelop, useSchema, useTiming } from '@envelop/core';
import { envelop, useSchema } from '@envelop/core';
import { parse, validate, subscribe, execute } from 'graphql';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core';

Expand All @@ -18,7 +19,11 @@ const schema = makeExecutableSchema({
});

const getEnveloped = envelop({
plugins: [useSchema(schema), useTiming()],
parse,
validate,
subscribe,
execute,
plugins: [useSchema(schema)],
});

const server = new ApolloServer({
Expand Down
3 changes: 2 additions & 1 deletion examples/apollo-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"@envelop/core": "*",
"apollo-server": "3.5.0",
"apollo-server-core": "3.5.0",
"@graphql-tools/schema": "8.5.0"
"@graphql-tools/schema": "8.5.0",
"graphql": "16.6.0"
},
"devDependencies": {
"@types/node": "15.6.1",
Expand Down
9 changes: 7 additions & 2 deletions examples/azure-functions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { envelop, useLogger, useSchema, useTiming } from '@envelop/core';
import { envelop, useLogger, useSchema } from '@envelop/core';
import { parse, validate, subscribe, execute } from 'graphql';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { AzureFunction, Context, HttpRequest } from '@azure/functions';
import { getGraphQLParameters, processRequest, Response } from 'graphql-helix';
Expand All @@ -17,7 +18,11 @@ const schema = makeExecutableSchema({
});

const getEnveloped = envelop({
plugins: [useSchema(schema), useLogger(), useTiming()],
parse,
validate,
execute,
subscribe,
plugins: [useSchema(schema), useLogger()],
});

export const index: AzureFunction = async (context: Context, req: HttpRequest): Promise<void> => {
Expand Down
3 changes: 2 additions & 1 deletion examples/azure-functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"dependencies": {
"graphql-helix": "1.8.3",
"@envelop/core": "*",
"@graphql-tools/schema": "8.5.0"
"@graphql-tools/schema": "8.5.0",
"graphql": "16.6.0"
},
"devDependencies": {
"@azure/functions": "1.2.3",
Expand Down
9 changes: 7 additions & 2 deletions examples/cloudflare-workers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { envelop, useLogger, useSchema, useTiming } from '@envelop/core';
import { envelop, useLogger, useSchema } from '@envelop/core';
import { parse, validate, execute, subscribe } from 'graphql';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { getGraphQLParameters, processRequest, Response } from 'graphql-helix';
import { Router } from 'worktop';
Expand All @@ -20,7 +21,11 @@ const schema = makeExecutableSchema({
});

const getEnveloped = envelop({
plugins: [useSchema(schema), useLogger(), useTiming()],
parse,
validate,
execute,
subscribe,
plugins: [useSchema(schema), useLogger()],
});

router.add('POST', '/graphql', async (req, res) => {
Expand Down

0 comments on commit dc1e24b

Please sign in to comment.