Skip to content

Commit 825ebd3

Browse files
Deprecate 'getFieldDefFn' arg of 'TypeInfo' and move it last (#2921)
1 parent 920b45a commit 825ebd3

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

src/utilities/TypeInfo.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ import {
2222
export class TypeInfo {
2323
constructor(
2424
schema: GraphQLSchema,
25-
// NOTE: this experimental optional second parameter is only needed in order
26-
// to support non-spec-compliant code bases. You should never need to use it.
27-
// It may disappear in the future.
28-
getFieldDefFn?: getFieldDef,
2925
// Initial type may be provided in rare cases to facilitate traversals
3026
// beginning somewhere other than documents.
3127
initialType?: GraphQLType,
28+
29+
// @deprecated will be removed in 17.0.0
30+
getFieldDefFn?: getFieldDef,
3231
);
3332

3433
getType(): Maybe<GraphQLOutputType>;

src/utilities/TypeInfo.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ export class TypeInfo {
5555

5656
constructor(
5757
schema: GraphQLSchema,
58-
// NOTE: this experimental optional second parameter is only needed in order
59-
// to support non-spec-compliant code bases. You should never need to use it.
60-
// It may disappear in the future.
61-
getFieldDefFn?: typeof getFieldDef,
6258
// Initial type may be provided in rare cases to facilitate traversals
6359
// beginning somewhere other than documents.
64-
initialType?: GraphQLType,
60+
initialType?: ?GraphQLType,
61+
62+
// @deprecated will be removed in 17.0.0
63+
getFieldDefFn?: typeof getFieldDef,
6564
) {
6665
this._schema = schema;
6766
this._typeStack = [];

src/utilities/__tests__/TypeInfo-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ describe('visitWithTypeInfo', () => {
312312
const complexInputType = testSchema.getType('ComplexInput');
313313
invariant(complexInputType != null);
314314

315-
const typeInfo = new TypeInfo(testSchema, undefined, complexInputType);
315+
const typeInfo = new TypeInfo(testSchema, complexInputType);
316316

317317
const visited = [];
318318
visit(
@@ -357,7 +357,7 @@ describe('visitWithTypeInfo', () => {
357357
const humanType = testSchema.getType('Human');
358358
invariant(humanType != null);
359359

360-
const typeInfo = new TypeInfo(testSchema, undefined, humanType);
360+
const typeInfo = new TypeInfo(testSchema, humanType);
361361

362362
const ast = parse('{ name, pets { name } }');
363363
const operationNode = ast.definitions[0];

src/validation/__tests__/validation-test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ describe('Validate: Supports full validation', () => {
5353
]);
5454
});
5555

56-
// NOTE: experimental
57-
it('validates using a custom TypeInfo', () => {
56+
it('Deprecated: validates using a custom TypeInfo', () => {
5857
// This TypeInfo will never return a valid field.
59-
const typeInfo = new TypeInfo(testSchema, () => null);
58+
const typeInfo = new TypeInfo(testSchema, null, () => null);
6059

6160
const doc = parse(`
6261
query {
@@ -71,7 +70,7 @@ describe('Validate: Supports full validation', () => {
7170
}
7271
`);
7372

74-
const errors = validate(testSchema, doc, undefined, typeInfo);
73+
const errors = validate(testSchema, doc, undefined, undefined, typeInfo);
7574
const errorMessages = errors.map((err) => err.message);
7675

7776
expect(errorMessages).to.deep.equal([
@@ -130,7 +129,7 @@ describe('Validate: Limit maximum number of validation errors', () => {
130129
const doc = parse(query, { noLocation: true });
131130

132131
function validateDocument(options: {| maxErrors?: number |}) {
133-
return validate(testSchema, doc, undefined, undefined, options);
132+
return validate(testSchema, doc, undefined, options);
134133
}
135134

136135
function invalidFieldError(fieldName: string) {
@@ -170,7 +169,7 @@ describe('Validate: Limit maximum number of validation errors', () => {
170169
};
171170
}
172171
expect(() =>
173-
validate(testSchema, doc, [customRule], undefined, { maxErrors: 1 }),
172+
validate(testSchema, doc, [customRule], { maxErrors: 1 }),
174173
).to.throw(/^Error from custom rule!$/);
175174
});
176175
});

src/validation/validate.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ export function validate(
3030
schema: GraphQLSchema,
3131
documentAST: DocumentNode,
3232
rules?: ReadonlyArray<ValidationRule>,
33-
typeInfo?: TypeInfo,
3433
options?: { maxErrors?: number },
34+
35+
// @deprecate will be removed in 17.0.0
36+
typeInfo?: TypeInfo,
3537
): ReadonlyArray<GraphQLError>;
3638

3739
/**

src/validation/validate.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ export function validate(
3434
schema: GraphQLSchema,
3535
documentAST: DocumentNode,
3636
rules: $ReadOnlyArray<ValidationRule> = specifiedRules,
37-
typeInfo: TypeInfo = new TypeInfo(schema),
3837
options: {| maxErrors?: number |} = { maxErrors: undefined },
38+
39+
// @deprecate will be removed in 17.0.0
40+
typeInfo: TypeInfo = new TypeInfo(schema),
3941
): $ReadOnlyArray<GraphQLError> {
4042
devAssert(documentAST, 'Must provide document.');
4143
// If the schema used for validation is invalid, throw an error.

0 commit comments

Comments
 (0)