-
Notifications
You must be signed in to change notification settings - Fork 420
Description
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
Adding a decorator like @Directive('@key(fields: "id")') to a class adds the extend keyword to the definition of the GraphQL type in the SDL.
As I understand it, adding the @key directive should define a type as an entity in the subgraph that owns that type. Additional subgraphs that reference a type owned by another subgraph need the extend keyword to indicate that they're extending an entity. This bug causes every type with a key to be treated as an extension, so there's no primary entity, which breaks federation.
Minimum reproduction code
https://github.com/Maldron/nest/tree/key_directive_automatically_makes_type_extension
Steps to reproduce
Linked repo is a fork of the nest repo with sample/23-graphql-code-first tweaked to act as a subgraph.
cd sample/23-graphql-code-firstnpm install && npm run start- Grab the sdl through
rover subgraph introspect http://localhost:3000/graphqlor by running the following curl
curl --request POST \
--url http://localhost:3000/graphql \
--header 'Content-Type: application/json' \
--data '{"query":" query {\n _service {\n sdl\n }\n }"}'
It'll produce the following definition for Recipe:
extend type Recipe @key(fields: "id") {
id: ID!
title: String!
description: String
creationDate: Date!
ingredients: [String!]!
}
Expected behavior
The Recipe type should be defined as an entity in the schema, not an extension. I.e.:
type Recipe @key(fields: "id") {
id: ID!
title: String!
description: String
creationDate: Date!
ingredients: [String!]!
}
Package version
10.0.2
Graphql version
graphql: 16.3.0
apollo-server-express: 3.6.2
NestJS version
8.2.3
Node.js version
14.17.6
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response