Skip to content

buildFederatedSchema bug - errors out on non-scalar directive arguments #423

@lgandecki

Description

@lgandecki

Apollo federation won't start if I try to use directives like so:

  directive @entity(
    embedded: Boolean
    additionalFields: [AdditionalEntityFields]
  ) on OBJECT

  input AdditionalEntityFields {
    path: String
    type: String
  }

Error: Schema must contain uniquely named types but contains multiple types named "AdditionalEntityFields".

This is a valid schema.

  • A short, but descriptive title. The title doesn't need "Apollo" in it.

  • The package name and version of Apollo showing the problem.
    "@apollo/federation": "0.19.1"

  • If applicable, the last version of Apollo where the problem did not occur.
    No idea.

  • The expected behavior.

It should accept a correct schema with non-scalar directive arguments.

  • The actual behavior.
/sandbox/node_modules/graphql/type/schema.js:262
      throw new Error("Schema must contain uniquely named types but contains multiple types named \"".concat(namedType.name, "\"."));
      ^

Error: Schema must contain uniquely named types but contains multiple types named "AdditionalEntityFields".
    at typeMapReducer (/sandbox/node_modules/graphql/type/schema.js:262:13)
    at /sandbox/node_modules/graphql/type/schema.js:307:12
    at Array.reduce (<anonymous>)
    at typeMapDirectiveReducer (/sandbox/node_modules/graphql/type/schema.js:306:25)
    at Array.reduce (<anonymous>)
    at new GraphQLSchema (/sandbox/node_modules/graphql/type/schema.js:147:32)
    at Object.transformSchema (/sandbox/node_modules/apollo-graphql/lib/schema/transformSchema.js:17:12)
    at buildFederatedSchema (/sandbox/node_modules/@apollo/federation/dist/service/buildFederatedSchema.js:58:31)
    at Object.<anonymous> (/sandbox/index.js:31:11)
    at Module._compile (internal/modules/cjs/loader.js:778:30)

if you switch true into false on line 28

if (true) {
// ->
if (false) {

you will see that the app starts just fine with the same typeDefs. This has been broken for months now and I hoped it was some easy oversight that would get fixed shortly, but for some reason, this is still broken. I tried to fix it myself but to be honest that piece of code is a rabbit hole of weird transformations. It's really hard to understand WHY all that stuff is happening - and one downside of what happens there is the duplication of some types, like that one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions