Skip to content

Commit

Permalink
Deprecate 'getFieldDefFn' arg of 'TypeInfo' and move it last (graphql…
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Feb 20, 2021
1 parent 6054799 commit 01859b0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/utilities/TypeInfo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GraphQLOutputType>;
Expand Down
9 changes: 4 additions & 5 deletions src/utilities/TypeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/__tests__/TypeInfo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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];
Expand Down
11 changes: 5 additions & 6 deletions src/validation/__tests__/validation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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([
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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!$/);
});
});
4 changes: 3 additions & 1 deletion src/validation/validate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export function validate(
schema: GraphQLSchema,
documentAST: DocumentNode,
rules?: ReadonlyArray<ValidationRule>,
typeInfo?: TypeInfo,
options?: { maxErrors?: number },

// @deprecate will be removed in 17.0.0
typeInfo?: TypeInfo,
): ReadonlyArray<GraphQLError>;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/validation/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export function validate(
schema: GraphQLSchema,
documentAST: DocumentNode,
rules: $ReadOnlyArray<ValidationRule> = 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<GraphQLError> {
devAssert(documentAST, 'Must provide document.');
// If the schema used for validation is invalid, throw an error.
Expand Down

0 comments on commit 01859b0

Please sign in to comment.