0

Looking for an option to join graphQL API response using Apollo federation where Graphql APIs are built on top of POST services.

To explain my usecase, I have created below dummy example.

Two POST Services are

  1. User Service and
  2. Post Service

Request for UserService

{
userid : "13242"
}

Response from UserService

    {
       userName,
       email,
       dateOfBirth,
       postIds []
    }

Request for PostService

  {
    postId: "13242",  // this is from UserService Response
    memberInfo: {     // this will come from client
       memberid : "34343",
       memberGroup : "mg-8798",
       memberLocation : "LOc-87"
    },
    groupInfo: {     // this will come from client
       GroupId :  "87980"
       GroupInfo : "some group Info"
    }
  }

Post Service needs PostIds from UserService Response and memberInfo and GroupInfo from Gateway Input (Input from Client).

In my current resolver I don't have any information other than postId,

{
  user: {
    posts(user) {
      return user.posts.map(postId => ({ __typename: "Post", postId }));
    }
  }
}

How do I write resolver where two responses need to get connected using postId but need extra info from client Input?

or In other words - How to access data from Input Request across federated services through resolver


Added to answer to one of the Questions in comments

---------------------------- User Schema ---------------------------

 type User @key(fields: "id"){
    id: ID!
    name: String!
    username: String!
    userposts: [Post]
    email: String!
    phone: String!
    website: String!
  }

// Here Id (postId) should be primary key, but service needs other inputs too which contains MemberInfo and GroupInfo. I am not sure how to do this and this is where I need help as well as on resolver

 extend type Post @key(fields: "postInput") {
      id: ID! @external
      postInput : PostInput
  }

-----------------------------Post Schema -------------------------

 type PostResult @key(fields: "postInput"){
    postInput: PostInput!
    userid: Int!
    title: String!
    comments : [Comments]
  }  

input PostInput {
   postId : String!
   memberInfo: MemberInfo 
   groupInfo: GroupInfo
}

input MemberInfo { 
   memberNumber: "String"
   enrolmentId: "String" 
}

input GroupInfo {
    groupIds: "String"
    groupName: "String" 
}
    
user837593
  • 337
  • 1
  • 5
  • 25
  • I'm not sure what your'e asking for. Are you asking for GraphQL arguments, or are you asking for information about the user's session? – Dan Crews Jul 06 '20 at 23:26
  • @DanCrews - I have modified my question and explained scenario with some dummy example. I hope my question is clear now, please provide pointers on how can I achieve it. Thanks in advance for your inputs – user837593 Jul 07 '20 at 14:26
  • Could you please share your federated schema for Post and User? – Glenn Sonna Jul 14 '20 at 09:50
  • @GlennSonna - I have added handwritten dummy schemas to my original question to explain use case. Please ignore any syntax error. – user837593 Jul 15 '20 at 22:28

0 Answers0