简体   繁体   English

如何使用代码优先方法在 graphql 中创建更复杂的类型

[英]How to create more complex types in graphql using code first approach

Hello I'm trying to create field for mutation which is array of objects.您好,我正在尝试为突变创建field ,该字段是对象数组。 Code looks like this:代码如下所示:

import { Field, InputType } from '@nestjs/graphql';

type ChainToAddress = {
  chain: string;
  address: string;
};

@InputType()
export class CreateONSInput {
  @Field()
  ons: string;

  @Field(type => [ChainToAddress])
  chainAddressess: ChainToAddress;
}

Currently is throwing following error:目前正在抛出以下错误:

'ChainToAddress' only refers to a type, but is being used as a value here.

Any idea how to make it work, tried with interfaces / type but somehow not able to manage it知道如何使其工作,尝试使用接口/类型,但不知何故无法管理它

You need to create an InputType / ObjectType out of your nested interface to make it work.您需要在嵌套接口之外创建一个InputType / ObjectType才能使其工作。

@InputType()
class ChainToAddress {
  @Field()
  chain: string;
  @Field()
  address: string;
};

@InputType()
export class CreateONSInput {
  @Field()
  ons: string;

  @Field(type => [ChainToAddress])
  chainAddressess: ChainToAddress[];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 复杂类型的 HotChocolate (GraphQL) 模式第一种方法 - HotChocolate (GraphQL) schema first approach on complex type 使用代码优先方法在 NestJS 中使用 GraphQL 模型出错 - Getting error with GraphQL model in NestJS, using code-first approach zend 3,graphQL - 如何使用Types类中的工厂创建模型实例 - zend 3, graphQL - how to create model instance using factory in Types class GraphQL 架构未使用 NestJS 更新(代码优先方法) - GraphQL Schema not updated with NestJS (code-first approach) 在 NestJS 中实现 GraphQL 全局 Object 识别(代码优先方法) - Implementing GraphQL Global Object Identification in NestJS (code-first approach) 使用解析器在GraphQL和Ruby中获取更复杂的查询 - Using resolvers to get more complex queries in GraphQL and Ruby 定义不止一种类型的查询 GraphQL Schema - 在查询上定义不同类型的最佳方法 object - Define more than one type of query GraphQL Schema - Best approach to define different types on query one one object 使用自定义字段在nestjs graphql 代码优先方法中定义实体导致错误 - Defining entities in nestjs graphql code first approach with custom field results in error 在多种类型上使用 GraphQL Fragment - Using GraphQL Fragment on multiple types 在GraphQL typedDefs中使用联合类型 - using Union types in GraphQL typedDefs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM