I’m using version 0.1.4 of @apollo/subgraph.
My schema includes an interface, and I’m getting the following error when calling buildSubgraphSchema:
TypeError: type.getInterfaces is not a function
at printImplementedInterfaces node_modules\@apollo\subgraph\src\printSubgraphSchema.ts:174:27)
at printInterface node_modules\@apollo\subgraph\src\printSubgraphSchema.ts:219:5)
at printType node_modules\@apollo\subgraph\src\printSubgraphSchema.ts:149:12)
at node_modules\@apollo\subgraph\src\printSubgraphSchema.ts:78:30
at Array.map (<anonymous>)
at printFilteredSchema node_modules\@apollo\subgraph\src\printSubgraphSchema.ts:78:16)
at printSubgraphSchema node_modules\@apollo\subgraph\src\printSubgraphSchema.ts:41:10)
at buildSubgraphSchema node_modules\@apollo\subgraph\src\buildSubgraphSchema.ts:81:34)
Looking at the apollo/subsgraph source (printSubgraph.ts), the following method looks odd - why would printing an interface include printing which interfaces that interface supports? I didn’t think GraphQL allowed interface A implements B
.
function printInterface(type: GraphQLInterfaceType): string {
// Apollo change: print `extend` keyword on type extensions.
// See printObject for assumptions made.
//
// XXX revist extension checking
const isExtension =
type.extensionASTNodes && type.astNode && !type.astNode.fields;
return (
printDescription(type) +
// Apollo change: print `extend` keyword on interface extensions
(isExtension ? 'extend ' : '') +
`interface ${type.name}` +
printImplementedInterfaces(type) + // <-- why this?
printFederationDirectives(type) +
printKnownDirectiveUsagesOnTypeOrField(type) +
printFields(type)
);
}
The error occurs then in the printImplementedInterfaces method because a GraphQLInterfaceType does not have a method getInterfaces()
:
function printImplementedInterfaces(
type: GraphQLObjectType | GraphQLInterfaceType,
): string {
const interfaces = type.getInterfaces(); // <-- This blows up
return interfaces.length
? ' implements ' + interfaces.map((i) => i.name).join(' & ')
: '';
}
I can’t believe I’m the first person to build a subgraph schema with an interface in it, so is there something I might have done wrong here?