Support for inheritResolversFromInterfaces/allowUndefinedInResolve in federation?

I’m migrating an existing Apollo graphql server to a federated subgraph. Previously I would build the schema like so:

const schema = makeExecutableSchema({
    typeDefs,
    resolvers,
    allowUndefinedInResolve: true,
    schemaDirectives,
    inheritResolversFromInterfaces: true
  });

Now I’m calling buildSubgraphSchema instead, but it doesn’t seem to be expecting either of the allowUndefinedInResolve or inheritResolversFromInterfaces options. Consequently my existing “interface resolvers” don’t seem to be firing.

Is this an known limitation of buildSubgraphSchema, and if so will it be addressed in future versions? Or is there some other way to ensure my interface resolvers can be called?

Hi! Im currently having the same issue. Im trying to migrate to Apollo Federation but inheritResolversFromInterfaces doesnt seem to be usable. I tried using mergeSchemas from @graphql-tools/schema but it seems like references stop being resolved.

Hi, you can use addResolveFunctionsToSchema from graphql-tools (or addResolversToSchema from @graphql-tools/schema but I’m not sure if it works) like this:

  const federatedSchema = buildSubgraphSchema(typeDefs);
  const schema = addResolveFunctionsToSchema({
    // super important, otherwise we need to implement every resolver
    inheritResolversFromInterfaces: true,
    resolverValidationOptions: {
      requireResolversForArgs: true,
      requireResolversForNonScalar: true,
      requireResolversForResolveType: false,
    },
    resolvers,
    schema: federatedSchema,
  });

Edit: the resolverValidationOptions do not work on my side

Thanks @Nicoowr - I will give that a try and let you know how it goes!

I avoided graphql-tools on the grounds that I thought that was essentially deprecated but the following appears to work using @graphql-tools/schema:

const schema = addResolversToSchema({
    // super important, otherwise we need to implement every resolver
    inheritResolversFromInterfaces: true,
    resolvers,
    schema: buildSubgraphSchema([{ typeDefs }])
  });

2 Likes

Thanks @Alan_Boshier , just stumbled upon this and it’s exactly what I need… it seems you’re still helping me with GQL, even though we don’t work together anymore :slight_smile:
Hope life is treating you well?!

1 Like