Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
GraphQL - "Field \"updateOwner\" of type \"Owner!\" must have a selection of subfields. Did you mean \"updateOwner { ... }\"?"

I'm trying to get Mutation Update query in GraphQL Playground. I'm basic level in GraphQL and in learning phase. I don't know how to create udpate Mutation for the below Owner code. Any idea what I'm missing in my code / query?

---Resolver---

>   @Mutation(() => Owner)   updateOwner(
>     @Args('id', { type: () => Int }) id: number,
>     @Args('updateOwnerInput') updateOwnerInput: UpdateOwnerInput) {
>     return this.ownersService.update(id, updateOwnerInput);   }

---Service---

  update(id: number, updateOwnerInput: UpdateOwnerInput) {
    return this.ownersRepository.update(id, updateOwnerInput);
  }

---dto---

@InputType()
export class UpdateOwnerInput extends PartialType(CreateOwnerInput) {
  @Column()
  @Field(() => Int)
  id: number;
}

---entity---

@Entity()
@ObjectType()
export class Owner {
  @PrimaryGeneratedColumn()
  @Field(type => Int)
  id: number;

  @Column()
  @Field()
  name: string;

  @OneToMany(() => Pet, pet => pet.owner)
  @Field(type => [Pet], { nullable: true })
  pets?: Pet[];

}

---schema---

type Pet {
  id: Int!
  name: String!
  type: String
  ownerId: Int!
  owner: Owner!
}

type Owner {
  id: Int!
  name: String!
  pets: [Pet!]
}

type Query {
  getPet(id: Int!): Pet!
  pets: [Pet!]!
  owners: [Owner!]!
  owner(id: Int!): Owner!
}

type Mutation {
  createPet(createPetInput: CreatePetInput!): Pet!
  createOwner(createOwnerInput: CreateOwnerInput!): Owner!
  updateOwner(id: Int!, updateOwnerInput: UpdateOwnerInput!): Owner!
}

input CreatePetInput {
  name: String!
  type: String
  ownerId: Int!
}

input CreateOwnerInput {
  name: String!
}

input UpdateOwnerInput {
  name: String
  id: Int!
}

---GraphQL Query (I don't know whether it is correct or wrong)

mutation {
  updateOwner (updateOwnerInput:{
    id:6,
    name: "josh",    
  })
}

---error---

"message": "Field \"updateOwner\" of type \"Owner!\" must have a selection of subfields. Did you mean \"updateOwner { ... }\"?",
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to make a selection of subfields to return (even if you're not interested in any):

mutation {
  updateOwner (updateOwnerInput:{
    id:6,
    name: "josh",    
  })
  {
    id
    name
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda