寻找一种使用Apollo联合加入graphQL API响应的选项,其中Graphql API建立在POST服务之上。
为了解释我的用例,我创建了下面的虚拟示例。
两个POST服务是
请求UserService
{
userid : "13242"
}
来自UserService的响应
{
userName,
email,
dateOfBirth,
postIds []
}
请求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需要UserService Response中的PostIds和Gateway Input(来自客户端的输入)中的memberInfo和GroupInfo。
在当前的解析器中,除postId之外,我没有任何其他信息,
{
user: {
posts(user) {
return user.posts.map(postId => ({ __typename: "Post", postId }));
}
}
}
如何在需要使用postId连接两个响应但需要来自客户端输入的额外信息的地方编写解析器?
或换句话说-如何通过解析器跨联合服务访问输入请求中的数据
--------------------------------用户架构----------------- ----------
type User @key(fields: "id"){
id: ID!
name: String!
username: String!
userposts: [Post]
email: String!
phone: String!
website: String!
}
//这里的id(postId)应该是主键,但是服务也需要其他输入,其中包含MemberInfo和GroupInfo。我不确定如何执行此操作,这是我需要帮助以及解析程序的地方
extend type Post @key(fields: "postInput") {
id: ID! @external
postInput : PostInput
}
-----------------发布架构---------------- ---------
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"
}