From 8e745d9fce193522856271a6f8a24081dd6834d2 Mon Sep 17 00:00:00 2001 From: Ben Salili-James Date: Mon, 20 Apr 2020 15:54:12 +0100 Subject: [PATCH 1/4] Replace deprecated use of `getErrors` with `onError` --- packages/apollo-language-server/src/errors/validation.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/apollo-language-server/src/errors/validation.ts b/packages/apollo-language-server/src/errors/validation.ts index c9fa38cb4d..87f3097eec 100644 --- a/packages/apollo-language-server/src/errors/validation.ts +++ b/packages/apollo-language-server/src/errors/validation.ts @@ -51,7 +51,12 @@ export function getValidationErrors( rules: ValidationRule[] = defaultValidationRules ) { const typeInfo = new TypeInfo(schema); - const context = new ValidationContext(schema, document, typeInfo); + + const errors: GraphQLError[] = []; + + const context = new ValidationContext(schema, document, typeInfo, error => + errors.push(error) + ); if (fragments) { (context as any)._fragments = fragments; @@ -60,7 +65,7 @@ export function getValidationErrors( const visitors = rules.map(rule => rule(context)); // Visit the whole document with each instance of all provided rules. visit(document, visitWithTypeInfo(typeInfo, visitInParallel(visitors))); - return context.getErrors(); + return errors; } export function validateQueryDocument( From d334cac90d095793991dbb361a0f6d3ea76f075c Mon Sep 17 00:00:00 2001 From: Ben Salili-James Date: Mon, 20 Apr 2020 15:59:34 +0100 Subject: [PATCH 2/4] Add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffec0cb148..ea486c9c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - - `apollo-language-server` - Fix definition navigation for vscode using localSchemaFile [#1996](https://github.com/apollographql/apollo-tooling/pull/1996) + - Replace deprecated use of `getErrors` with `onError` [#1908](https://github.com/apollographql/apollo-tooling/pull/1908) - `apollo-tools` - - `vscode-apollo` From 3677ac40ca9108fa06fd928dd68f7b3c3af3b748 Mon Sep 17 00:00:00 2001 From: Ben Salili-James Date: Thu, 25 Jun 2020 19:50:21 +0100 Subject: [PATCH 3/4] Add back in support for pre-14.5.0 graphql installs --- .../apollo-language-server/src/errors/validation.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/apollo-language-server/src/errors/validation.ts b/packages/apollo-language-server/src/errors/validation.ts index 87f3097eec..8a8feaef8e 100644 --- a/packages/apollo-language-server/src/errors/validation.ts +++ b/packages/apollo-language-server/src/errors/validation.ts @@ -54,6 +54,9 @@ export function getValidationErrors( const errors: GraphQLError[] = []; + // The fourth `onError` parameter in the constructor of `ValidationContext` + // was introduced in `graphql@14.5.0`. It is safe to use this in pre-14.5.0 + // versions too, as there was no fourth parameter in any earlier version. const context = new ValidationContext(schema, document, typeInfo, error => errors.push(error) ); @@ -65,6 +68,14 @@ export function getValidationErrors( const visitors = rules.map(rule => rule(context)); // Visit the whole document with each instance of all provided rules. visit(document, visitWithTypeInfo(typeInfo, visitInParallel(visitors))); + + // In `graphql@15.0.0`, `context.getErrors` was removed. + // If this function is available, then we prefer to use it, as the user + // may be on a version of `graphql` that is pre-14.5.0 (and therefore `errors`) + // will be empty as it's never called above. + if (typeof context.getErrors === "function") { + return context.getErrors(); + } return errors; } From 8b3eec2304abd13c42f454e69402a438acfd5a54 Mon Sep 17 00:00:00 2001 From: Ben Salili-James Date: Thu, 25 Jun 2020 19:57:37 +0100 Subject: [PATCH 4/4] Fix typo and add additional clarification on major release --- packages/apollo-language-server/src/errors/validation.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/apollo-language-server/src/errors/validation.ts b/packages/apollo-language-server/src/errors/validation.ts index 8a8feaef8e..d960ad59b1 100644 --- a/packages/apollo-language-server/src/errors/validation.ts +++ b/packages/apollo-language-server/src/errors/validation.ts @@ -71,8 +71,9 @@ export function getValidationErrors( // In `graphql@15.0.0`, `context.getErrors` was removed. // If this function is available, then we prefer to use it, as the user - // may be on a version of `graphql` that is pre-14.5.0 (and therefore `errors`) + // may be on a version of `graphql` that is pre-14.5.0, and therefore `errors` // will be empty as it's never called above. + // This can be removed in a major release if pre-14.5.0 support is dropped. if (typeof context.getErrors === "function") { return context.getErrors(); }