Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 #1487

Merged
merged 61 commits into from
Oct 12, 2022
Merged

V3 #1487

Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
726519d
feat: non-breaking GraphQL Engine
saihaj Aug 17, 2022
a84ea46
feat: make envelop take in engine functions
saihaj Aug 22, 2022
5320ae5
structural typings
saihaj Aug 22, 2022
871208e
remove grapqhl as peer dep from types pkg
saihaj Aug 22, 2022
732ec5e
make core more agnostic
saihaj Aug 22, 2022
4d09e1d
chore(dependencies): updated changesets for modified dependencies
github-actions[bot] Aug 22, 2022
4f6fe63
remove traced schema
saihaj Aug 23, 2022
dd616a1
remove traced orchestrator
saihaj Aug 23, 2022
1244549
make plugin agnostic
saihaj Aug 23, 2022
28bfd92
drop EnvelopError
saihaj Aug 23, 2022
6ba3999
remove more graphql import
saihaj Aug 23, 2022
ae21a6e
Drop useTiming
saihaj Aug 23, 2022
da7c81c
make core completely free of graphql-js
saihaj Aug 23, 2022
5010b96
add eslint rule
saihaj Aug 23, 2022
2f8c24b
eslint disallow in types too
saihaj Aug 23, 2022
d55b626
more agnostic packages
saihaj Aug 23, 2022
184db16
remove introspection util
saihaj Aug 24, 2022
06687c4
Merge branch 'main' into saihaj/engine-agnostic-non-breaking
saihaj Aug 24, 2022
6964702
chore(dependencies): updated changesets for modified dependencies
github-actions[bot] Aug 24, 2022
6ec5792
prettier
saihaj Aug 24, 2022
680dbda
TEMP: make bot calm down
saihaj Aug 24, 2022
f0373e1
update all docs
saihaj Aug 24, 2022
d8be662
test matrix for core
saihaj Aug 24, 2022
c1274cd
experimenting traced schema (#1501)
saihaj Aug 31, 2022
2647f7f
feat: drop node 12 (#1505)
saihaj Sep 1, 2022
3442989
Merge branch 'main' into saihaj/engine-agnostic-non-breaking
saihaj Sep 1, 2022
5ab6cc6
feat: remove `enableIf` utility (#1504)
saihaj Sep 2, 2022
6e27fdd
feat: remove async schema plugin and rename lazy loaded schema plugin…
saihaj Sep 5, 2022
59d8a78
add eslint rule (#1509)
saihaj Sep 7, 2022
49cf420
feat: `@envelop/on-resolve` plugin for hooking into schema resolvers …
enisdenjo Sep 7, 2022
050d317
docs: order of plugins matter (#1513)
saihaj Sep 7, 2022
b1bf2e9
feat: remove handler for validation and parse errors (#1510)
saihaj Sep 8, 2022
7b7b530
add changeset
saihaj Sep 12, 2022
593b119
Merge branch 'main' into saihaj/engine-agnostic-non-breaking
saihaj Sep 12, 2022
cdbfbb2
Update .changeset/nervous-seas-own.md
saihaj Sep 12, 2022
ebf9e1a
Update .changeset/rude-cats-peel.md
saihaj Sep 12, 2022
7bc6412
no-use-before-define (#1522)
enisdenjo Sep 13, 2022
1770063
feat: trigger on context, validate and parse errors (#1511)
saihaj Sep 13, 2022
9399a33
docs: migration guide (#1520)
saihaj Sep 15, 2022
1720176
Add redirects
saihaj Sep 15, 2022
049f13d
remove deafult skip error from sentry plugin
saihaj Sep 15, 2022
43adce7
export masked error plugin
saihaj Sep 15, 2022
1b063e9
sentry plugin default skip GraphQLError
saihaj Sep 15, 2022
6cbf555
sentry: og error is not graphql error then send to sentry
saihaj Sep 16, 2022
36b3d28
doc: drop introspection utils
saihaj Sep 20, 2022
af08536
should fix ts issues on v15
saihaj Sep 20, 2022
fbef7dd
test: stack error we should not match the error name since it can be …
saihaj Sep 21, 2022
b32fda2
feat: use engine plugin (#1535)
saihaj Sep 28, 2022
5805d5a
Merge branch 'main' into saihaj/engine-agnostic-non-breaking
saihaj Sep 28, 2022
af295b0
Merge branch 'main' into saihaj/engine-agnostic-non-breaking
saihaj Oct 10, 2022
ce3728a
fix
saihaj Oct 10, 2022
32d6c10
versioned docs with v3 default
saihaj Oct 10, 2022
a7819c6
fix build
saihaj Oct 10, 2022
f2afa3b
fix
saihaj Oct 10, 2022
748132d
feat this is cool
saihaj Oct 11, 2022
a0bbe32
docs reword schema tracing
saihaj Oct 11, 2022
27375db
docs add graphql error example
saihaj Oct 11, 2022
4851db7
docs restructuring, fix typos
saihaj Oct 11, 2022
5bdc22a
chore remove autogenerated changeset
saihaj Oct 11, 2022
5eba9aa
cleanup changeset
saihaj Oct 11, 2022
78febf3
docs sycn patch
saihaj Oct 11, 2022
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
7 changes: 7 additions & 0 deletions .changeset/@envelop_types-1487-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@envelop/types": patch
---

dependencies updates:

- Removed dependency [`graphql@^14.0.0 || ^15.0.0 || ^16.0.0` ↗︎](https://www.npmjs.com/package/graphql/v/null) (from `peerDependencies`)
33 changes: 33 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{ "devDependencies": ["**/*.test.ts", "**/*.spec.ts", "**/test/**/*.ts"] }
]
},

"env": {
"es6": true,
"node": true
Expand All @@ -43,6 +44,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"
dotansimha marked this conversation as resolved.
Show resolved Hide resolved
},
{
"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
3 changes: 0 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@
"graphql": "16.3.0",
"typescript": "4.7.4"
},
"peerDependencies": {
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
},
"buildOptions": {
"input": "./src/index.ts"
},
Expand Down
28 changes: 21 additions & 7 deletions packages/core/src/create.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import { GetEnvelopedFn, ComposeContext, Plugin, ArbitraryObject } from '@envelop/types';
import {
GetEnvelopedFn,
ComposeContext,
Plugin,
ArbitraryObject,
ExecuteFunction,
SubscribeFunction,
ParseFunction,
ValidateFunction,
} from '@envelop/types';
import { isPluginEnabled, PluginOrDisabledPlugin } from './enable-if.js';
import { createEnvelopOrchestrator, EnvelopOrchestrator } from './orchestrator.js';
import { traceOrchestrator } from './traced-orchestrator.js';

export function envelop<PluginsType extends Plugin<any>[]>(options: {
plugins: Array<PluginOrDisabledPlugin>;
enableInternalTracing?: boolean;
parse: ParseFunction;
execute: ExecuteFunction;
validate: ValidateFunction;
subscribe: SubscribeFunction;
}): GetEnvelopedFn<ComposeContext<PluginsType>> {
const plugins = options.plugins.filter(isPluginEnabled);
let orchestrator = createEnvelopOrchestrator<ComposeContext<PluginsType>>(plugins);

if (options.enableInternalTracing) {
orchestrator = traceOrchestrator(orchestrator);
}
const orchestrator = createEnvelopOrchestrator<ComposeContext<PluginsType>>({
plugins,
parse: options.parse,
execute: options.execute,
validate: options.validate,
subscribe: options.subscribe,
});

const getEnveloped = <TInitialContext extends ArbitraryObject>(
initialContext: TInitialContext = {} as TInitialContext
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ export * from './create.js';
export * from './utils.js';
export * from './plugins/use-envelop.js';
export * from './plugins/use-logger.js';
export * from './plugins/use-timing.js';
export * from './plugins/use-schema.js';
export * from './plugins/use-error-handler.js';
export * from './plugins/use-extend-context.js';
export * from './plugins/use-payload-formatter.js';
export * from './plugins/use-masked-errors.js';
export * from './plugins/use-immediate-introspection.js';
export * from './enable-if.js';
export { resolversHooksSymbol } from './orchestrator.js';
61 changes: 37 additions & 24 deletions packages/core/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,10 @@ import {
SubscribeErrorHook,
DefaultContext,
Maybe,
} from '@envelop/types';
import {
DocumentNode,
execute,
ParseFunction,
ValidateFunction,
ExecutionResult,
GraphQLError,
GraphQLSchema,
parse,
specifiedRules,
subscribe,
validate,
ValidationRule,
} from 'graphql';
import { prepareTracedSchema, resolversHooksSymbol } from './traced-schema.js';
} from '@envelop/types';
import {
errorAsyncIterator,
finalAsyncIterator,
Expand All @@ -61,13 +51,26 @@ export type EnvelopOrchestrator<
execute: ReturnType<GetEnvelopedFn<PluginsContext>>['execute'];
subscribe: ReturnType<GetEnvelopedFn<PluginsContext>>['subscribe'];
contextFactory: EnvelopContextFnWrapper<ReturnType<GetEnvelopedFn<PluginsContext>>['contextFactory'], PluginsContext>;
getCurrentSchema: () => Maybe<GraphQLSchema>;
getCurrentSchema: () => Maybe<any>;
};

type EnvelopOrchestratorOptions = {
plugins: Plugin[];
parse: ParseFunction;
execute: ExecuteFunction;
subscribe: SubscribeFunction;
validate: ValidateFunction;
};
export const resolversHooksSymbol = Symbol('RESOLVERS_HOOKS');

export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>(
plugins: Plugin[]
): EnvelopOrchestrator<any, PluginsContext> {
let schema: GraphQLSchema | undefined | null = null;
export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>({
plugins,
parse,
execute,
subscribe,
validate,
}: EnvelopOrchestratorOptions): EnvelopOrchestrator<any, PluginsContext> {
let schema: any | undefined | null = null;
let initDone = false;
const onResolversHandlers: OnResolverCalledHook[] = [];
for (const plugin of plugins) {
Expand All @@ -79,9 +82,9 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>
// Define the initial method for replacing the GraphQL schema, this is needed in order
// to allow setting the schema from the onPluginInit callback. We also need to make sure
// here not to call the same plugin that initiated the schema switch.
const replaceSchema = (newSchema: GraphQLSchema, ignorePluginIndex = -1) => {
const replaceSchema = (newSchema: any, ignorePluginIndex = -1) => {
if (onResolversHandlers.length) {
prepareTracedSchema(newSchema);
// prepareTracedSchema(newSchema);
}
schema = newSchema;

Expand Down Expand Up @@ -152,7 +155,7 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>

const customParse: EnvelopContextFnWrapper<typeof parse, any> = beforeCallbacks.parse.length
? initialContext => (source, parseOptions) => {
let result: DocumentNode | Error | null = null;
let result: any | Error | null = null;
let parseFn: typeof parse = parse;
const context = initialContext;
const afterCalls: AfterParseHook<any>[] = [];
Expand Down Expand Up @@ -211,9 +214,9 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>

const customValidate: EnvelopContextFnWrapper<typeof validate, any> = beforeCallbacks.validate.length
? initialContext => (schema, documentAST, rules, typeInfo, validationOptions) => {
let actualRules: undefined | ValidationRule[] = rules ? [...rules] : undefined;
let actualRules: undefined | any[] = rules ? [...rules] : undefined;
let validateFn = validate;
let result: null | readonly GraphQLError[] = null;
let result: null | readonly any[] = null;
const context = initialContext;

const afterCalls: AfterValidateHook<any>[] = [];
Expand All @@ -234,7 +237,10 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>
validateFn,
addValidationRule: rule => {
if (!actualRules) {
actualRules = [...specifiedRules];
// Ideally we should provide default validation rules here.
// eslint-disable-next-line no-console
console.warn('No default validation rules provided.');
actualRules = [];
}

actualRules.push(rule);
Expand All @@ -254,6 +260,10 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>
result = validateFn(schema, documentAST, actualRules, typeInfo, validationOptions);
}

if (!result) {
return;
}

const valid = result.length === 0;

for (const afterCb of afterCalls) {
Expand Down Expand Up @@ -384,6 +394,9 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>
// Can be removed once we drop support for GraphQL.js 15
});
}
if (!result) {
return;
}

const onNextHandler: OnSubscribeResultResultOnNextHook<PluginsContext>[] = [];
const onEndHandler: OnSubscribeResultResultOnEndHook[] = [];
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/plugins/use-error-handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Plugin, DefaultContext, TypedExecutionArgs } from '@envelop/types';
import { ExecutionResult, GraphQLError } from 'graphql';
import { Plugin, DefaultContext, TypedExecutionArgs, ExecutionResult } from '@envelop/types';
import { handleStreamOrSingleExecutionResult } from '../utils.js';

export type ErrorHandler = (errors: readonly GraphQLError[], context: Readonly<DefaultContext>) => void;
export type ErrorHandler = (errors: readonly Error[] | any[], context: Readonly<DefaultContext>) => void;

type ErrorHandlerCallback<ContextType> = {
result: ExecutionResult;
Expand Down
138 changes: 0 additions & 138 deletions packages/core/src/plugins/use-masked-errors.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/core/src/plugins/use-payload-formatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Plugin, TypedExecutionArgs } from '@envelop/types';
import { Plugin, TypedExecutionArgs, ExecutionResult } from '@envelop/types';
import { handleStreamOrSingleExecutionResult } from '../utils.js';
import { ExecutionResult } from 'graphql';

export type FormatterFunction = (
result: ExecutionResult<any, any>,
Expand Down
Loading