nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.46k stars 396 forks source link

federation gateway code-first approach throws error for entity type 'User' #843

Closed igortas closed 4 years ago

igortas commented 4 years ago

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I'm trying to create code-first federation approach. I'm following this example: https://github.com/nestjs/graphql/tree/master/tests/code-first-federation The current behaviour is that apollo-gateway throws error: This data graph is missing a valid configuration. Unknown type: "User".

Expected behavior

I don't expect gateway to throw error.

Minimal reproduction of the problem with instructions

User entity:

@ObjectType()
@Directive('@extends')
@Directive('@key(fields: "id")')
@Entity({ name: 'users' })
export class User {
 @Field(() => ID)
  @Directive('@external')
  @PrimaryGeneratedColumn('increment', { type: 'int' })
  id: number;

Graphql config service:

 public getGraphqlConfig(schemaName: string): GqlModuleOptions {
    return {
      autoSchemaFile: resolve(process.cwd(), `../../schema/${schemaName}`),
      debug: !envService.isProduction(),
      playground: !envService.isProduction(),
    };
  }

Users module:

@Module({
  imports: [
    GraphQLFederationModule.forRoot(
      graphqlService.getGraphqlConfig('users-schema.gql'),
    ),
  ],
})
export class AppModule {}

Gateway module:

@Module({
  imports: [
    GraphQLGatewayModule.forRoot({
      server: {
        // ... Apollo server options
        cors: true,
      },
      gateway: {
        serviceList: [
          { name: 'users', url: 'http://localhost:4000/graphql' },
          // { name: 'performers', url: 'http://localhost:5000/graphql' },
        ],
      },
    }),
  ],
})
export class AppModule {}

What is the motivation / use case for changing the behavior?

I like to create apollo federation with multiple microservices, and every microservice has it own feature implemented with own db, and i'm trying to follow how schema-first approach is working, but with code-first.

Environment

VS Code version: 1.44.2


Nest version: 7.1.4


For Tooling issues:
- Node version: 10.16.3 
- Platform:  Windows            
Ponjimon commented 4 years ago

What's the code for the module etc behind http://localhost:4000/graphql?

igortas commented 4 years ago

What's the code for the module etc behind http://localhost:4000/graphql?

I've updated the ticket with the users module code.

kamilmysliwiec commented 4 years ago

PR for the code-first & federation is in progress. Let's track this here https://github.com/nestjs/docs.nestjs.com/pull/1213