dotansimha / dotansimha/graphql-code-generator

Issue with Federation when manually adding directives

Open
#5,033 4 comments 1 reaction 0 assignees View on GitHub
core plugins
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

Hi. This is in context with the discussion here: https://github.com/dotansimha/graphql-code-generator/issues/3033#issuecomment-721644587

I am not sure if I am doing something wrong here. I have my directives added manually to support VSCode GraphQL extension (since it does not support Apollo Federaton: graphql/graphiql#2351) like this:

```gql
scalar _Any
scalar _FieldSet

# a union of all types that use the @key directive
union _Entity

type _Service {
sdl: String
}

extend type Query {
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}

directive @external on FIELD_DEFINITION
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @key(fields: _FieldSet!) on OBJECT | INTERFACE

# this is an optional directive discussed below
directive @extends on OBJECT | INTERFACE
```

Now, the VSCode GraphQL extension works well after these directives are added.

If I run the codegen now, it runs but I see issues in generated types.

**With directives added manually:**

1

**Without directives:**

2

The error thrown: `Generic type 'DeepPartial' requires 1 type argument(s).`

The new types get added when I add the directives manually but not when I don't.

Now, if I try to exclude the directives from the codegen (since `federation:true` is already added) like this (Fed.gql contains the directives manually added):

```yml
schema:
- './packages/modules/**/schema/**/*.gql'
- ${GLOBAL_GQL_URL:http://g.lvh.me:2500/graphql}
- "!(packages/modules/**/schema/**/Fed.gql)"
```

I get the issue which I reported here: https://github.com/dotansimha/graphql-code-generator/issues/5013

Hope this clarifies.

**PS:** I am working on moving towards schema stitching and this might not be an issue for me over the long run. But may still be relevant for others.

**CC:** @dotansimha

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.