Skip to content

Commit

Permalink
Simplify extendType()
Browse files Browse the repository at this point in the history
  • Loading branch information
leebyron authored Feb 9, 2018
1 parent ca2cdc7 commit a8b9539
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/utilities/extendSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,23 @@ export function extendSchema(
return (extendTypeCache[type.name]: any);
}

// Should be called only once per type so only getExtendedType should call it.
// To be called at most once per type. Only getExtendedType should call this.
function extendType<T: GraphQLNamedType>(type: T): T {
let extendedType = type;
if (!isIntrospectionType(type)) {
if (isObjectType(type)) {
extendedType = extendObjectType(type);
} else if (isInterfaceType(type)) {
extendedType = extendInterfaceType(type);
} else if (isUnionType(type)) {
extendedType = extendUnionType(type);
}
if (isIntrospectionType(type)) {
// Introspection types are not extended.
return type;
}
if (isObjectType(type)) {
return extendObjectType(type);
}
if (isInterfaceType(type)) {
return extendInterfaceType(type);
}
if (isUnionType(type)) {
return extendUnionType(type);
}
// Workaround: Flow should figure out correct type, but it doesn't.
return (extendedType: any);
// This type is not yet extendable.
return type;
}

function extendObjectType(type: GraphQLObjectType): GraphQLObjectType {
Expand Down

0 comments on commit a8b9539

Please sign in to comment.