如何在解析器中使用 Apollo-Server Graphql 的枚举?

问题描述

环境

  1. 阿波罗服务器
  2. 快递
  3. 打字稿
  4. 打字

类型定义(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;

问题

我想在 typeDefs.ts 使用 enum Part of resolvers.ts

我试过了

return {
    team,part: "Hand"
}

也是,但工作量不大。

如何使用 typeDefs.ts at resolvers.ts 中定义的枚举类型?

请检查!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)