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

Apollo Federation - Duplicate scalar in multiple services #2767

Closed
juicycleff opened this issue Jun 3, 2019 · 17 comments · Fixed by #2829
Closed

Apollo Federation - Duplicate scalar in multiple services #2767

juicycleff opened this issue Jun 3, 2019 · 17 comments · Fixed by #2829
Assignees

Comments

@juicycleff
Copy link

juicycleff commented Jun 3, 2019

  • 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!
  }
`;
@MFogleman
Copy link

MFogleman commented Jun 3, 2019

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.

@juicycleff
Copy link
Author

I believe there should be internal deduplication for the scaler type in the Apollo Gateway library

@ausov
Copy link

ausov commented Jun 4, 2019

Could you please suggest a workaround? Is it possible to transform individual service definitions or a composed schema on the gateway?

@Ked57
Copy link

Ked57 commented Jun 6, 2019

A more stable aproach would be to be able to declare each service as a module/namespace so the gateway calls every field of the service using service.field

@jbaxleyiii
Copy link
Contributor

Hello all! This is being fixed in the next release, currently worked on by @JakeDawkins!

@ausov
Copy link

ausov commented Jun 7, 2019

Thank you for taking care of this. I would anyway suggest adding a possibility for some extensions, e.g. by invoking a function if present in gateway options for service schema pre/post processing on (like it was possible with stiching). What do you think?

@ivome
Copy link

ivome commented Jun 10, 2019

I think the option of schema pre/post processing would be great with an option to rename types.
If the types are just merged, you might end up with a scalar that has different behavior in different parts of the schema.

@Pruxis
Copy link
Contributor

Pruxis commented Jun 12, 2019

Is there any hack around this for the time being @JakeDawkins ?

I'm currently JSON stringifying/parsing my JSON scalars instead but it's such a pain.

@JakeDawkins
Copy link
Contributor

@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!

@Pruxis
Copy link
Contributor

Pruxis commented Jun 12, 2019

@JakeDawkins thanks for the effort.

@byrnedo
Copy link

byrnedo commented Jun 18, 2019

@JakeDawkins Should this be available in @apollo/gateway version 0.6.7?

@JakeDawkins
Copy link
Contributor

JakeDawkins commented Jun 18, 2019

@byrnedo This should be available now in @apollo/[email protected]. @apollo/[email protected] should be published in the next couple hours with this

@CaroseKYS
Copy link

@JakeDawkins When dose @apollo/[email protected] will be published? We are stopped by this problem.

@byrnedo
Copy link

byrnedo commented Jun 19, 2019

@CaroseKYS workaround is to update have @apollo/[email protected] in your package json and then remove the federation package in the gateway's node_modules dir:
rm -rf ./node_modules/@apollo/gateway/node_modules/@apollo/federation
Then it will use 0.6.4 instead of 0.6.3

@CaroseKYS
Copy link

@byrnedo Thanks, I just have solved problem in my local env. But in scenes like CI deployment and team work, it is troublesome.

@byrnedo
Copy link

byrnedo commented Jun 20, 2019

@CaroseKYS you can add a postinstall script in package.json to solve it for ci

@CaroseKYS
Copy link

@byrnedo @apollo/[email protected] has been pulished. Do you have any ideas about this issue :https://github.com/apollographql/apollo-server/issues/2884? Thanks.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants