apollographql / federation

🌐  Build and scale a single data graph across multiple services with Apollo's federation gateway.
https://apollographql.com/docs/federation/
Other
661 stars 248 forks source link

Federation Feature Request: define custom scalars and scalar logic in gateway #389

Open jonahmolinski opened 4 years ago

jonahmolinski commented 4 years ago

It would be nice if there was a way to define a custom scalar in the gateway as well as provide the logic to resolve that scalar. It does not make sense to have to define the scalar logic in each microservice. Take DateTime for example, it is likely the most microservices in a project will use this, but each microservice now needs to implement the logic.

For a user standpoint, scalars should always behave the same. Having a developer implement the logic in each service could lead to inconsistent results and it leads to duplicated code.

To take this a step further, the gateway should be able to define "global" objects like a scalar definition and description.

I was unable to find a way to do this. If it exists, please point me in the right direction.

I hope you will see a use case for this.

Staceadam commented 3 years ago

Just ran into an issue where 2 services had defined a conflicting Date, one service defined it as a scalar and the other as a type. There needs to be a way to define scalars at the gateway level like you are suggesting, trying to match the same logic and definition between multiple services is the opposite of what we are trying to accomplish by introducing a federation.