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

159
Visualizações
Graphql querying many to many relationship

I have two entities Events and Profiles which have a many to many relationship. Im attempting to query an event with its associated profiles like so.

{
  event(id: 7){
    id
    username
    startDate
    endDate
    privacy
    timezone
    updatedAt
    createdAt
    creator{
      id
      username
    }
    profiles{
      Profile {
        id
        username
      }
    }
  }
}

But am getting ""message": "Cannot query field \"Profile\" on type \"Profile\"."," whenever i try to do so.

Event entity:

@ObjectType()
@Entity()
export class Event extends BaseEntity {
  @Field(() => Int)
  @PrimaryGeneratedColumn()
  id!: number

  @Field()
  @Column({ unique: true })
  username!: string

  @Field()
  @Column()
  title!: string

  @Field()
  @Column()
  description!: string

  @Field()
  @Column()
  privacy!: string

  @Field({ nullable: true, defaultValue: new Date() })
  @Column()
  startDate?: Date

  @Field({ nullable: true, defaultValue: new Date() })
  @Column()
  endDate?: Date

  @Field()
  @Column()
  timezone: string

  @Field()
  @Column()
  creatorId: number

  @Field(() => User)
  @ManyToOne(() => User, (user) => user.events)
  creator: User

  @Field(() => Profile)
  @ManyToMany(() => Profile, (profile) => profile.events)
  @JoinTable()
  profiles: Profile[]

  @Field(() => String)
  @UpdateDateColumn()
  updatedAt: Date

  @Field(() => String)
  @CreateDateColumn()
  createdAt: Date
}

Profile entity:

@ObjectType()
@Entity()
export class Profile extends BaseEntity {
  @Field(() => Int)
  @PrimaryGeneratedColumn()
  id!: number

  @Field()
  @Column({ unique: true })
  username!: string

  @OneToMany(() => Post, (post) => post.creator)
  posts: Post[]

  @OneToMany(() => Updoot, (updoot) => updoot.user)
  updoots: Updoot[]

  @ManyToMany(() => Event, (event) => event.profiles)
  events: Event[]

  @Field()
  @Column()
  userId: number

  @OneToOne(() => User, (user) => user.profile)
  user: User

  @Field(() => String)
  @UpdateDateColumn()
  updatedAt: Date

  @Field(() => String)
  @CreateDateColumn()
  createdAt: Date
}
about 4 years ago · Juan Pablo Isaza
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