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
- User Service and
- 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"
}