如何定义多态(参数化)GraphQL类型?

时间:2017-04-18 16:16:56

标签: graphql

我希望我的所有Mutation方法都能返回实现MutationResult类型的结果:

interface MutationResult {
  errors: [UserError]!
}

示例:

type AuthenticateMutationResult implements MutationResult {
  errors: [UserError]!
  user: User
}

type Mutation {
  authenticate (
    email: String!
    password: String!
  ): AuthenticateMutationResult!
}

为每个变异创建...MutationResult会产生许多样板代码。

有没有办法定义可配置类型,例如

type MutatationResult<fieldName, fieldType> = {
  [fieldName: fieldName]: fieldType
};

这将允许我内联变异结果类型:

type Mutation {
  authenticate (
    email: String!
    password: String!
  ): MutatationResult<'user', User>!
}

中是否存在多态类型的语法?

0 个答案:

没有答案
相关问题