Closed
Description
Extracted from #1127 see #1127 (comment)
We shoud add diffSchemas
function. That returns something like this:
type SchemaDifference = {|
added: {|
queryType?: GraphQLObjectType,
// ...
types: Array<GraphQLTypes>,
directives: Array<GraphQLDirectives>
|},
changed: {|
queryType?: ValueDifference<GraphQLType>,
// ...
types: Array<TypeDifference>,
directives: Array<DirectivesDifference>
|}
// ...
|};
type ValueDifference<T> = { old: T, new: T };
type TypeDifference = ScalarTypeDifference | ObjectTypeDifference; /* ... */
type ObjectTypeDifference = {|
name: string,
added: {|
description: string,
fields: Array<GraphQLField>
// ...
|},
changed: {|
description: ValueDifference<string>,
fields: Array<FieldDifference>
// ...
|}
// ...
|};
It will allow to implement your particular check as:
const diff = diffSchema(oldSchema, newSchema);
for (const newType of diff.added.types) {
if (newType.description) {
console.log("Description of a new type ...");
}
newType.getFields().forEach(reportNewField);
}
for (const typeDiff of diff.changed.types) {
if (typeDiff.added.description) {
console.log("Added type description ...");
}
typeDiff.added.fields.forEach(reportNewField);
if (typeDiff.changed.description) {
console.log("Changed type description ...");
}
for (const fieldDiff of typeDiff.changed.field) {
if (fieldDiff.added.description) {
console.log("Added field description ...");
// ...
}
}
}
function reportNewField(field) {
if (field.description) {
// ...
}
}