Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(federation): override federated resolveType for interfaces #1444

Merged
merged 4 commits into from
Mar 22, 2021

Conversation

thomas-advantitge
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Interfaces example (https://docs.nestjs.com/graphql/interfaces) with resolveType doesn't work when changing GraphQLModule to GraphQLFederationModule.

{
  "errors": [
    {
      "message": "Abstract type \"Party\" must resolve to an Object type at runtime for field \"Query.parties\". Either the \"Party\" type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
...

Issue Number: N/A

What is the new behavior?

Resolve type function is executed when using GraphQLFederationModule.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

// lib/federation/graphql-federation.factory.ts

// autoGeneratedSchema is including types with resolveType function
const autoGeneratedSchema: GraphQLSchema = await this.gqlSchemaBuilder.buildFederatedSchema(
  options.autoSchemaFile,
  options,
  this.resolversExplorerService.getAllCtors(),
);
// executableSchema "erases" this field
let executableSchema: GraphQLSchema = buildFederatedSchema({
  typeDefs: gql(printSchema(autoGeneratedSchema)),
  resolvers: this.getResolvers(options.resolvers),
});

Interfaces example (https://docs.nestjs.com/graphql/interfaces) with `resolveType` didn't work when changing `GraphQLModule` to `GraphQLFederationModule`.
@kamilmysliwiec
Copy link
Member

Would you be able to add an e2e test for this issue (or update one of the existing tests) so we can make sure we never break this behavior in the future?

@thomas-advantitge
Copy link
Contributor Author

@kamilmysliwiec as we encountered a related problem concerning the absence of field directives on interfaces, added the fix in this PR as well, extending the new e2e test.

@kamilmysliwiec kamilmysliwiec merged commit c9bde25 into nestjs:master Mar 22, 2021
@kamilmysliwiec
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants