typescript - 如何在解析器中使用 Apollo-Server Graphql 的枚举?
问题描述
环境
- 阿波罗服务器
- 表示
- 打字稿
- 打字机
类型定义 (typeDefs.ts)
import { gql } from 'apollo-server-express';
const typeDefs = gql`
enum Part {
Hand, Arm, Waist, Bottom
}
type PartInfo {
team: Int,
tag: String,
part: Part
}
...
type Query {
...
hand(team: Int): PartInfo,
...
}
`;
export default typeDefs;
解析器 (resolvers.ts)
const resolvers = {
Query: {
...
hand: async (parent, args, context, info) => {
const { team } = args;
...
return {
team,
tag: "handTag",
part: Part.hand
}
}
...
},
};
export default resolvers;
问题
我想使用 enum 的typeDefs.ts
一部分resolvers.ts
我试过了
return {
team,
tag: "handTag",
part: "Hand"
}
也,但剂量工作。
如何使用typeDefs.ts
at中定义的枚举类型resolvers.ts
?
请检查!
解决方案
除了 Schema (typeDef.ts),您还应该在解析器中定义您的枚举。
const resolvers = {
Query: {
...
hand: async (parent, args, context, info) => {
const { team } = args;
...
return {
team,
tag: "handTag",
part: Part.hand
}
}
...
},
Part: {
Hand: Part.hand
}
};
export default resolvers;
推荐阅读
- python-3.x - 有没有办法附加相同的日志文件而不是在 python 3.x 中创建新文件?
- oracle - 如何写这个匿名块?
- android - 在某些设备上对本机应用程序崩溃做出反应而不会出错
- javascript - 如何使用 javascript 创建 ec2
- azure - 是否有用于操作 Azure ARM 模板的工具
- g++ - 对`__cxa_throw_bad_array_new_length的未定义引用
- git - 在 Azure Devops 中,有没有一种方法可以从多个存储库中获取单个构建定义的源?
- html - 抗锯齿在倾斜导航中造成奇怪的差距
- python - 将带有键和值列表的字典转换为矩阵
- python - 对大量数据帧进行操作