-
Notifications
You must be signed in to change notification settings - Fork 420
Description
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 build multiple GraphQL Microservices (Experience Service and Company Service) by using Apollo Federation and code-first approach.
I've followed this documentation: https://docs.nestjs.com/graphql/federation#federation
Basically:
- inside the Experience Service you can find model, resolver and module related to the Experience entity.
- inside the Company Service you can find model, resolver and module related to the Company entity. Moreover, in order to separate by concern, in the Company Service you can find an extension of the Experience model in order to add the company field (as described here: https://docs.nestjs.com/graphql/federation#code-first-1):
@Schema()
@ObjectType()
@Directive('@extends')
@Directive('@key(fields: "_id")')
export class Experience {
@Field(() => String)
@Directive('@external')
_id: MongooseSchema.Types.ObjectId;
@Field(() => [Company])
@Prop({ type: [MongooseSchema.Types.ObjectId], ref: Company.name })
companies: MongooseSchema.Types.ObjectId[] | Company[];
}
The problem is that, the autogenerated GraphQL Schema ignores all the Directives, included the @extends one:
# ------------------------------------------------------
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------
directive @extends on INTERFACE | OBJECT
directive @external on FIELD_DEFINITION | OBJECT
directive @key(fields: String!) on INTERFACE | OBJECT
directive @provides(fields: String!) on FIELD_DEFINITION
directive @requires(fields: String!) on FIELD_DEFINITION
...
type Experience {
_id: String!
ciao: String!
companies: [Company!]!
}
...
Expected behavior
With the code-first approach I expect that NestJS, during the generation of the GraphQL Schema, takes into account all the directives added inside the model, autogenerating so a schema like the following one:
extend type User @key(fields: "id") {
id: ID! @external
posts: [Post]
}
Minimal reproduction of the problem with instructions
The repo with the full code (Experience Service, Company Service, Gateway) is the following one: https://github.com/keadex/keadex-einaudi/tree/0.0.1
This is the Experience model (which extends the one inside the Experience Service - https://github.com/keadex/keadex-einaudi/blob/0.0.1/apps/experience/src/models/experience.model.ts) inside the Company Service: https://github.com/keadex/keadex-einaudi/blob/0.0.1/apps/company/src/models/experience.model.ts
What is the motivation / use case for changing the behavior?
Is not possible to extend GraphQL types and create GraphQL microservices separated by concern leveraging on Apollo Federation.
Environment
Nest version: 7.6.0
For Tooling issues:
- Node version: 12.13.0
- Platform: Windows