简体   繁体   中英

Type "TypeName" must define one or more fields graphql nest js

Im getting 3 similar errors from my graphql service

Type Location must define one or more fields.

Type Employee must define one or more fields.

Type Project must define one or more fields.

my location and project type extends from another service. but I couldn't figure out why this happens. the employee service is the one that throws these three errors. I will add my 3 types here. "@nestjs/graphql": "^10.0.13", "@apollo/gateway": "^2.0.3",

Employee

@ObjectType()
@Directive('@key(fields: "id")')
export class Employee {
  @Field(() => ID)
  id: string;

  @Field()
  firstName: string;

  @Field()
  lastName: string;

  @Field()
  designation: string;

  @Field({ nullable: true })
  city: string;

  @Field()
  projectId: string;

  @Field()
  locationId: string;

  @Field(() => Project)
  project: Project; //get data from another service via fedaration gateway

  @Field(() => Location)
  location: Location; //get data from another service via fedaration gateway
}

Location

@ObjectType()
@Directive('@extends')
@Directive('@key(fields: "id")')
export class Location {
  @Field(() => ID)
  @Directive('@external')
  id: string;

  @Field(() => [Employee])
  employees: Employee[];
}

Project

@ObjectType()
@Directive('@extends')
@Directive('@key(fields: "id")')
export class Project {
  @Field(() => ID)
  @Directive('@external')
  id: string;

  @Field(() => [Employee])
  employees: Employee[];
}

It appears that there are breaking changes in the latest patch version of @apollo/subgraph@2.0.3 . You may need to downgrade to 2.0.2 :

npm install @apollo/subgraph@2.0.2

Also recommend you pin this version, eg make sure the version is explicit, and not @apollo/subgraph@^2.0.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM