From 2cce72b2135817ca942a7fd053a1b03ff5b0d79f Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Fri, 12 Feb 2021 15:48:02 +0200 Subject: [PATCH] Deprecate 'getFieldDefFn' arg of 'TypeInfo' and move it last --- src/utilities/TypeInfo.d.ts | 7 +++---- src/utilities/TypeInfo.js | 9 ++++----- src/utilities/__tests__/TypeInfo-test.js | 4 ++-- src/validation/__tests__/validation-test.js | 11 +++++------ src/validation/validate.d.ts | 4 +++- src/validation/validate.js | 4 +++- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/utilities/TypeInfo.d.ts b/src/utilities/TypeInfo.d.ts index 499fb02978..9d26943d0d 100644 --- a/src/utilities/TypeInfo.d.ts +++ b/src/utilities/TypeInfo.d.ts @@ -22,13 +22,12 @@ import { export class TypeInfo { constructor( schema: GraphQLSchema, - // NOTE: this experimental optional second parameter is only needed in order - // to support non-spec-compliant code bases. You should never need to use it. - // It may disappear in the future. - getFieldDefFn?: getFieldDef, // Initial type may be provided in rare cases to facilitate traversals // beginning somewhere other than documents. initialType?: GraphQLType, + + // @deprecated will be removed in 17.0.0 + getFieldDefFn?: getFieldDef, ); getType(): Maybe; diff --git a/src/utilities/TypeInfo.js b/src/utilities/TypeInfo.js index c72684a742..805dd7df10 100644 --- a/src/utilities/TypeInfo.js +++ b/src/utilities/TypeInfo.js @@ -55,13 +55,12 @@ export class TypeInfo { constructor( schema: GraphQLSchema, - // NOTE: this experimental optional second parameter is only needed in order - // to support non-spec-compliant code bases. You should never need to use it. - // It may disappear in the future. - getFieldDefFn?: typeof getFieldDef, // Initial type may be provided in rare cases to facilitate traversals // beginning somewhere other than documents. - initialType?: GraphQLType, + initialType?: ?GraphQLType, + + // @deprecated will be removed in 17.0.0 + getFieldDefFn?: typeof getFieldDef, ) { this._schema = schema; this._typeStack = []; diff --git a/src/utilities/__tests__/TypeInfo-test.js b/src/utilities/__tests__/TypeInfo-test.js index 9f8349449b..7650032153 100644 --- a/src/utilities/__tests__/TypeInfo-test.js +++ b/src/utilities/__tests__/TypeInfo-test.js @@ -312,7 +312,7 @@ describe('visitWithTypeInfo', () => { const complexInputType = testSchema.getType('ComplexInput'); invariant(complexInputType != null); - const typeInfo = new TypeInfo(testSchema, undefined, complexInputType); + const typeInfo = new TypeInfo(testSchema, complexInputType); const visited = []; visit( @@ -357,7 +357,7 @@ describe('visitWithTypeInfo', () => { const humanType = testSchema.getType('Human'); invariant(humanType != null); - const typeInfo = new TypeInfo(testSchema, undefined, humanType); + const typeInfo = new TypeInfo(testSchema, humanType); const ast = parse('{ name, pets { name } }'); const operationNode = ast.definitions[0]; diff --git a/src/validation/__tests__/validation-test.js b/src/validation/__tests__/validation-test.js index b1113d2d01..1b2d7f8bcd 100644 --- a/src/validation/__tests__/validation-test.js +++ b/src/validation/__tests__/validation-test.js @@ -53,10 +53,9 @@ describe('Validate: Supports full validation', () => { ]); }); - // NOTE: experimental - it('validates using a custom TypeInfo', () => { + it('Deprecated: validates using a custom TypeInfo', () => { // This TypeInfo will never return a valid field. - const typeInfo = new TypeInfo(testSchema, () => null); + const typeInfo = new TypeInfo(testSchema, null, () => null); const doc = parse(` query { @@ -71,7 +70,7 @@ describe('Validate: Supports full validation', () => { } `); - const errors = validate(testSchema, doc, undefined, typeInfo); + const errors = validate(testSchema, doc, undefined, undefined, typeInfo); const errorMessages = errors.map((err) => err.message); expect(errorMessages).to.deep.equal([ @@ -130,7 +129,7 @@ describe('Validate: Limit maximum number of validation errors', () => { const doc = parse(query, { noLocation: true }); function validateDocument(options: {| maxErrors?: number |}) { - return validate(testSchema, doc, undefined, undefined, options); + return validate(testSchema, doc, undefined, options); } function invalidFieldError(fieldName: string) { @@ -170,7 +169,7 @@ describe('Validate: Limit maximum number of validation errors', () => { }; } expect(() => - validate(testSchema, doc, [customRule], undefined, { maxErrors: 1 }), + validate(testSchema, doc, [customRule], { maxErrors: 1 }), ).to.throw(/^Error from custom rule!$/); }); }); diff --git a/src/validation/validate.d.ts b/src/validation/validate.d.ts index 5e93a8cff0..e15fc0b2e3 100644 --- a/src/validation/validate.d.ts +++ b/src/validation/validate.d.ts @@ -30,8 +30,10 @@ export function validate( schema: GraphQLSchema, documentAST: DocumentNode, rules?: ReadonlyArray, - typeInfo?: TypeInfo, options?: { maxErrors?: number }, + + // @deprecate will be removed in 17.0.0 + typeInfo?: TypeInfo, ): ReadonlyArray; /** diff --git a/src/validation/validate.js b/src/validation/validate.js index 9245230ffd..8ba03bbfb4 100644 --- a/src/validation/validate.js +++ b/src/validation/validate.js @@ -34,8 +34,10 @@ export function validate( schema: GraphQLSchema, documentAST: DocumentNode, rules: $ReadOnlyArray = specifiedRules, - typeInfo: TypeInfo = new TypeInfo(schema), options: {| maxErrors?: number |} = { maxErrors: undefined }, + + // @deprecate will be removed in 17.0.0 + typeInfo: TypeInfo = new TypeInfo(schema), ): $ReadOnlyArray { devAssert(documentAST, 'Must provide document.'); // If the schema used for validation is invalid, throw an error.