【发布时间】:2019-12-28 16:39:23
【问题描述】:
我有一个使用 Apollo Server 返回 GraphQL 响应的模拟服务器。其中一个查询是获取teams,它有一个metrics 数组(参见下面的架构):
const mocks = {
Query: () => ({
teams: (/*parent, args, context, info*/) => teamsFixture,
}),
};
const graphServer = new ApolloServer({ typeDefs: schema, mocks });
graphServer.applyMiddleware({ app });
我的查询曾经是(已编辑字段):
teams {
bpxId
metrics {
timestamp
}
}
真正的 (java) 服务器已对此进行了更改,以允许我仅查询(Relay 样式)指标数组中的第一项,因为它性能不佳:
teams {
bpxId
metrics(first: 1) {
edges {
node {
timestamp
}
}
}
}
这种形状的响应:
metrics: {
edges: [
{
node: [Team]
__typename: "TeamMetricsConnectionEdge"
}
]
__typename: "TeamMetricsConnection"
}
我想将此功能添加到我的 Apollo Server 模拟中,但不确定如何?
新架构(相关位):
type TeamMetrics {
timestamp: Int
# etc
}
type TeamMetricsConnection {
edges: [TeamMetricsConnectionEdge]
pageInfo: PageInfo
}
type PageInfo {
hasPreviousPage: Boolean!
hasNextPage: Boolean!
startCursor: String
endCursor: String
}
type Query {
teams(bpxId: Int): [Team]
}
type Team {
bpxId: Int!
metrics(first: Int! = 5, after: String): TeamMetricsConnection
}
如何调整我的模拟响应以处理中继分页?谢谢
【问题讨论】:
标签: javascript graphql apollo apollo-server