首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nest JS GraphQL“不能为非空返回null”。

Nest JS GraphQL“不能为非空返回null”。
EN

Stack Overflow用户
提问于 2019-09-27 20:16:23
回答 1查看 10.8K关注 0票数 6

我试图解决学习代码中的一个错误,但失败了。然后我就试着启动这段代码。

https://github.com/nestjs/nest/tree/master/sample/23-type-graphql

同样的情况..。

错误看上去

代码语言:javascript
复制
{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Recipe.id.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "recipe",
        "id"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Cannot return null for non-nullable field Recipe.id.",
            "    at completeValue (/home/innistry/Downloads/nest-master/sample/23-type-graphql/node_modules/graphql/execution/execute.js:560:13)",
            "    at /home/innistry/Downloads/nest-master/sample/23-type-graphql/node_modules/graphql/execution/execute.js:492:16",
            "    at process._tickCallback (internal/process/next_tick.js:68:7)"
          ]
        }
      }
    }
  ],
  "data": null
}

有人有主意吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-30 06:01:01

这是最快的修正,刚刚启动。

代码语言:javascript
复制
import { Field, ID, ObjectType } from 'type-graphql';

@ObjectType()
export class Recipe {
  @Field(type => ID, { nullable: true })
  id?: string;

  @Field({ nullable: true })
  title?: string;

  @Field({ nullable: true })
  description?: string;

  @Field({ nullable: true })
  creationDate?: Date;

  @Field(type => [String], { nullable: true })
  ingredients?: string[];
}
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58140891

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档