【发布时间】:2020-06-04 20:39:56
【问题描述】:
我想做什么?
在 Apollo Graphl 服务器中,我想在架构中将实体 Person 更改为 Human,但我不想破坏我的客户端(正在查询 graphql 的前端)。因此,如果客户正在查询Person,我想将其映射到Human。
示例:
客户查询
query {
Person {
ID
firstName
}
}
重写到
query {
Human {
ID
name
}
}
重写回复
{
data: {
Person: {
Id: 123,
name:"abc"
}
}
}
我尝试过的事情
graphql-rewriter 提供了类似于我正在寻找的东西。我浏览了它的文档,但它没有重写字段名称的选项。
在 apollo graphql 文档 Apollow graphql directives 中,他们提到了重命名指令,但我没有找到 rename-directive-package 节点模块。
apollo-directives-package我也试过这个,但它没有重命名缩放字段的选项,例如
import { makeExecutableSchema } from "graphql-tools";
import { RenameDirective } from "rename-directive-package";
const typeDefs = `
type Person @rename(to: "Human") {
name: String!
currentDateMinusDateOfBirth: Int @rename(to: "age")
}`;
const schema = makeExecutableSchema({
typeDefs,
schemaDirectives: {
rename: RenameDirective
}
});
任何建议/帮助将不胜感激。
【问题讨论】:
标签: graphql apollo apollo-server express-graphql