Apollo-server: Apollo Federation/Gateway doesn't support Custom scalars

Created on 21 Dec 2019  Â·  2Comments  Â·  Source: apollographql/apollo-server

It doesn't look like "@apollo/federation": "^0.11.2" and "@apollo/gateway": "^0.11.5" support custom scalars。

Expected

The gateway can identify custom type fields defined by child services。

Actual

GraphQLSchemaValidationError: [micro-test2] User.id -> Type undefined does not match the type of the original field in micro-test (UserId)

Code Example:

#### micro-test

type User @key(fields: "id"){
  id: UserId!
  username:String
}

new GraphQLScalarType({
    name: 'UserId',
    description: 'Global id of User Schema',
    serialize(value) {
      // value sent to the client
      return toGlobalId('User', value)
    },
    parseValue(value) {
      // value from the client
      if (typeof value === 'string') {
        const { type, id } = fromGlobalId(value)
        if (type === typeName) {
          return id
        }
        throw new Error('Incorrect globalId type: ' + type)
      } else {
        throw new Error('Incorrect globalId format: ')
      }
    },
    parseLiteral(ast) {
       // more
    }
})

#### micro-test2

extend type User @key(fields: "id"){
  id: UserId! @external
  realName: String
}

When I start the gateway , it unable to start normally and throw error(It seems that you don't know what userId is in service micro-test2. Even if I try to define the same userId).If I use ID to replace custom ID, the entire service can work.How can I solve this problem?Thanks.

All 2 comments

Sorry, it's my fault.

What was the solution?

Was this page helpful?
0 / 5 - 0 ratings