typescript graphql.v2.user.schema.ts

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript graphql.v2.user.schema.ts相关的知识,希望对你有一定的参考价值。

export const userTypeDefs = `

  type User {
    id: ID!
    email: String!
    password: String!
    firstName: String!
    lastName: String

    # We have 2 new fields, "workspaceId" and "workspace"
    # The workspaceId will be the id of the item and workspace 
    # will be the actual populated workspace object

    workspaceId: String
    workspace: Workspace
  }

  // code...

`;

export const userResolvers = {
  Query: {
    // Query resolvers...
  },
  Mutation: {
    // Mutation resolvers...
  },
  User: {
    async workspace(user: { workspaceId: string }) {
      if (user.workspaceId) {
        const workspace: any = await Workspace.findById(user.workspaceId);
        return workspace.toGraph();
      }
      return null;
    },
  },
};

以上是关于typescript graphql.v2.user.schema.ts的主要内容,如果未能解决你的问题,请参考以下文章

TypeScript入门五:TypeScript的接口

TypeScript系列教程--初探TypeScript

TypeScript入门三:TypeScript函数类型

typescript使用 TypeScript 开发 Vue 组件

认识 TypeScript

Learining TypeScript TypeScript 简介