-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preparations for [email protected]. (#1743)
This PR makes the minimal number of changes necessary for the apollo-tooling's repository's tests to pass for the planned [email protected] release. Notable changes to implementations are as follows: an adjustment to account for the new onError callback introduced by graphql/graphql-js#2074, which deprecated the previously used ValidationContext.prototype.getErrors method. utilize the GraphQLEnumValueConfig type instead of GraphQLEnumValue (which lead to the removal of the name field, which isn't actually needed when building the values for the GraphQLEnumType constructor. Ref: graphql/graphql-js#2303 Co-authored-by: Trevor Scheer <[email protected]>
- Loading branch information
1 parent
cbf732f
commit 56c37d8
Showing
16 changed files
with
65 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,18 @@ export function getValidationErrors( | |
rules: ValidationRule[] = defaultValidationRules | ||
) { | ||
const typeInfo = new TypeInfo(schema); | ||
const context = new ValidationContext(schema, document, typeInfo); | ||
|
||
// The 4th argument to `ValidationContext` is an `onError` callback. This was | ||
// introduced by https://github.com/graphql/graphql-js/pull/2074 and first | ||
// published in [email protected]. It is meant to replace the `getErrors` method | ||
// which was previously used. Since we support versions of graphql older than | ||
// that, it's possible that this callback will not be invoked and we'll need | ||
// to resort to using `getErrors`. Therefore, although we'll collect errors | ||
// via this callback, if `getErrors` is present on the context we create, | ||
// we'll go ahead and use that instead. | ||
const errors: GraphQLError[] = []; | ||
const onError = (err: GraphQLError) => errors.push(err); | ||
const context = new ValidationContext(schema, document, typeInfo, onError); | ||
|
||
if (fragments) { | ||
(context as any)._fragments = fragments; | ||
|
@@ -60,7 +71,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))); | ||
return context.getErrors(); | ||
|
||
// @ts-ignore | ||
// `getErrors` is gone in `graphql@15`, but we still support older versions. | ||
if (typeof context.getErrors === "function") return context.getErrors(); | ||
|
||
// If `getErrors` doesn't exist, we must be on a `graphql@15` or higher, | ||
// so we'll use the errors we collected via the `onError` callback. | ||
return errors; | ||
} | ||
|
||
export function validateQueryDocument( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters