nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.73k stars 7.63k forks source link

owned types are marked as extension #13635

Closed developer239 closed 5 months ago

developer239 commented 5 months ago

Is there an existing issue for this?

Current behavior

I am trying to run MOST MINIMALISTIC gateway but I am running into false positive error when one of the dependencies is thinking that Use Objet type is "extension" type.

Error: A valid schema couldn't be composed. The following composition errors were found:
        [auth] Type "User" is an extension type, but there is no type definition for "User" in any subgraph.

Auth Module:

@ObjectType()
@Directive('@key(fields: "id")') // this line breaks the gateway
export class User {
  @Field((type) => ID)
  id: number

  @Field()
  name: string

  @Field()
  email: string
}

@Resolver(() => User)
export class UserResolver {
  constructor(private userService: UserService) {}

  @Query((returns) => [User])
  users() {
    return this.userService.findAll()
  }
}

@Module({
  imports: [
    WrappedConfigModule,
    HomeModule,
    GraphQLModule.forRoot<ApolloFederationDriverConfig>({
      driver: ApolloFederationDriver,
      playground: true,
      autoSchemaFile: true,
      introspection: true,
      plugins: [ApolloServerPluginInlineTrace()],
    }),
    UserModule,
  ],
})
export class AppModule {}

Events Module:

@ObjectType()
export class Event {
  @Field((type) => ID)
  id: number

  @Field()
  name: string

  @Field()
  description: string

  @Field(() => [Number])
  attendees: number[]
}

@Resolver(() => Event)
export class EventResolver {
  constructor(private eventService: EventService) {}

  @Query((returns) => [Event])
  events() {
    return this.eventService.findAll()
  }
}

@Module({
  imports: [
    WrappedConfigModule,
    HomeModule,
    GraphQLModule.forRoot<ApolloFederationDriverConfig>({
      driver: ApolloFederationDriver,
      playground: true,
      autoSchemaFile: true,
      introspection: true,
      plugins: [ApolloServerPluginInlineTrace()],
    }),
    EventModule,
  ],
})
export class AppModule {}

Gateway Module:

@Module({
  imports: [
    WrappedConfigModule,
    HomeModule,
    GraphQLModule.forRoot<ApolloGatewayDriverConfig>({
      driver: ApolloGatewayDriver,
      gateway: {
        supergraphSdl: new IntrospectAndCompose({
          subgraphs: [
            { name: 'auth', url: 'http://localhost:8080/graphql' },
            { name: 'events', url: 'http://localhost:8081/graphql' },
          ],
        }),
      },
    }),
  ],
})
export class AppModule {}

Minimum reproduction code

https://github.com/developer239/nest-microservices-example/tree/v2

Steps to reproduce

  1. yarn install
  2. yarn dev (or run each service manually)

Expected behavior

Package

Other package

@apollo/gateway

NestJS version

10.3.2

Packages versions

{
  "name": "be-gateway-service",
  "version": "0.0.1",
  "license": "MIT",
  "scripts": {
    "build": "nest build",
    "start": "node dist/main",
    "dev": "NODE_ENV=development nest start --watch"
  },
  "dependencies": {
    "@apollo/federation": "^0.38.1",
    "@apollo/gateway": "^2.8.0",
    "@apollo/server": "^4.10.4",
    "@nestjs/apollo": "^12.1.0",
    "@nestjs/common": "10.3.8",
    "@nestjs/config": "3.2.2",
    "@nestjs/core": "10.3.8",
    "@nestjs/graphql": "^12.1.1",
    "@nestjs/microservices": "10.3.8",
    "@nestjs/platform-express": "10.3.8",
    "apollo-server-express": "^3.13.0",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.1",
    "graphql": "^16.8.1",
    "graphql-subscriptions": "^2.0.0",
    "graphql-tools": "^9.0.1",
    "joi": "17.13.1",
    "reflect-metadata": "0.2.2",
    "rxjs": "7.8.1"
  },
  "devDependencies": {
    "@nestjs/cli": "10.3.2",
    "@types/express": "4.17.21",
    "@types/node": "20.13.0",
    "source-map-support": "0.5.21",
    "tsconfig-paths": "4.2.0"
  }
}

Node.js version

18.20.3

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 5 months ago

Thank you for taking the time to submit your report! From the looks of it, this could be better discussed on our Discord. If you haven't already, please join here and send a new post in the #⁠ 🐈 nestjs-help forum. Make sure to include a link to this issue, so you don't need to write it all again. We have a large community of helpful members, who will assist you in getting this to work.