'unable to resolve types of another federated Apollo Graphql schema

I have two federated services in apollo graphql like the following

Service A

type User @key(fields:"id"){
    id:ID!
    name:String!
}

Service B:

extend type mutation{
   editUser(userId:ID!,name:String!):User
}

extend type User @key(fields:"id"){
   id:ID! @external
}

in the Service B resolver:

const resolvers={
   Mutation:{
      editUser:async(parent,args)=>{
         //logic of editing user here 
         //console.log(user) >> {id:123,name:"xyz"}
         return user;
      } 
   }
}

now when I do the mutation:

mutation{
   editUser(userId:"123",name:"xyz"){
      id,
      name
   }
}

The result is :

{
   "data": {
     "editUser": {
        id:"123",
        name:null
     }
   }
 }

I tried even resolving the user in service B but the the name is always null:

const resolvers={
   User:async(parent,args)=>{
      return await getUser(123); 
   },
   Mutation:{
      editUser:async(parent,args)=>{
         //logic of editing user here 
         //console.log(user) >> {id:123,name:"xyz"}
         return user;
      } 
   }
}

The only thing that worked is when I completly define the user object in service B Schema , but this is not what I want to do.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source