1

i create mutation like following

 @Mutation(returns => TagTranslation)
 updateTagTranslationName(@Arg('id') id: number, @Arg('name') name: string): Promise<TagTranslation>{
    return this.tagTranslationService.findById(id);

and in the playgrond, i send like following

mutation {
    updateTagTranslationName(id:1, name:"123") {
      code
    }
}

but it returns error "message": "Cannot return null for non-nullable field Mutation.updateTagTranslationName.", "locations": [ { "line": 2, "column": 3 } ], "path": [ "updateTagTranslationName" ],

following is my tagtranslation entity

@Table({
tableName: 'tag_translation',
indexes: [
]
})
@ObjectType()
export class TagTranslation extends Model<TagTranslation>{
    @PrimaryKey
    @AutoIncrement
    @Column
    @Field(type => Int)
    id: number;

    @ForeignKey(()=> Tag)
    @Field()
    @Column
    tag_id: number;

    @Column
    @Field({ nullable: true })
    name: string;

    @Column
    @Field({ nullable: true })
    language: string;
}

and following is error message

{
"errors": [
{
  "message": "Cannot return null for non-nullable field Mutation.updateTagTranslationName.",
  "locations": [
    {
      "line": 2,
      "column": 3
    }
  ],
  "path": [
    "updateTagTranslationName"
  ],
  "extensions": {
    "code": "INTERNAL_SERVER_ERROR",
    "exception": {
      "stacktrace": [
        "Error: Cannot return null for non-nullable field Mutation.updateTagTranslationName.",
        "    at completeValue 

I don't know why it returns error. please help me....

fuzes
  • 1,777
  • 4
  • 20
  • 40
  • 1
    Fields that are marked as non-null in the schema cannot return null. `updateTagTranslationName` is a non-null field and it is resolving to null, so an error is thrown. Either make the field nullable, or fix whatever is causing it to be null (like the row not actually being in the database). – Daniel Rearden Oct 04 '19 at 10:26
  • @DanielRearden row is exists in database, query is working well. i change field to nullable, i will add entity info – fuzes Oct 07 '19 at 02:26

0 Answers0