微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何在解析器中使用 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 举报,一经查实,本站将立刻删除。