apollo-server: Apollo Federation - Duplicate scalar in multiple services

  • I run into an error when using a scalar like DateTime in two different microservices, and merging them together with Apollo Federation. Here is a snippet of the error being thrown UnhandledPromiseRejectionWarning: GraphQLSchemaValidationError: There can be only one type named "DateTime".

  • Apollo Federation

  • UnhandledPromiseRejectionWarning: GraphQLSchemaValidationError: There can be only one type named "DateTime"..

Microservice Foo

export const typeDefsFoo: DocumentNode = gql`
  scalar DateTime
  
  extend type Query {
    foo(id: ID!): Sensor!
  }

  type Foo {
    time: DateTime!
  }

Microservice Bar

export const typeDefsBar: DocumentNode = gql`
  scalar DateTime
  
  extend type Query {
    bar(id: ID!): Bar!
  }

  type Bar {
    time: DateTime!
  }
`;

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 17
  • Comments: 17 (5 by maintainers)

Most upvoted comments

@byrnedo This should be available now in @apollo/federation@0.6.4. @apollo/gateway@0.6.7 should be published in the next couple hours with this

@Pruxis I’m not aware of a workaround, but I hope to be wrapping up work on this today, so this should work soon. Sorry for the trouble. If anyone else here has a workaround, feel free to share!

I’m also having the same problem. We’ve structure our stuff a little differently, so wanted to add it for extra investigative input

Microservice Alpha

Schema/types.graphql

type AlphaData @key(fields: "id") {
  id: UuidV4!
  created: String
  updated: String
}

Schema/index.js

module.exports = gql`
  ${readFileSync(__dirname.concat('/inputs.graphql'), 'utf8')}
  ${readFileSync(__dirname.concat('/types.graphql'), 'utf8')}
  scalar DateISO
  scalar UuidV4
`;

Microservice Beta

module.exports = gql`
  extend type AlphaData @key(fields: "id") {
    id: UuidV4! @external
    beta_data: BetaData 
  };
`

UuidV4 is a valid scalar on both microservices, they run as expected on their own. When we join them with federation, we get the same duplicate error. If we change them both to String!, it runs fine. We also had the same problem with other custom scalars.