graphql / graphiql

GraphiQL & the GraphQL LSP Reference Ecosystem for building browser & IDE tools.
MIT License
15.94k stars 1.71k forks source link

Support for Apollo Federation #2351

Open tvvignesh opened 3 years ago

tvvignesh commented 3 years ago

Actual Behavior

If I have a schema which have Apollo Federation specific directives like @key and @external the extension fails with the error:

undefined
10/28/2020, 12:58:20 PM [1] (pid: 1120103) graphql-language-service-usage-logs: Error: Unknown directive "@key".

Unknown directive "@key".

Unknown directive "@key".

Unknown directive "@key".

Unknown directive "@external".

undefined

Expected Behavior

Having apollo federation support would be great. When using the graphql-config yaml, I anyway specify that the schema is federated using the config as per this doc: https://graphql-code-generator.com/docs/integrations/federation

config:
   federation: true

So, the extension can probably use a similar config to infer the same and allow use of such directives.

Steps to Reproduce the Problem Or Description

Try adding a Apollo Federation schema with relevant directives and the extension fails with errors.

Specifications

Version: 1.51.0-insider (user setup)
Commit: bb16786cff3d231facbdcee90741ac25fcffd3ac
Date: 2020-10-28T05:57:23.779Z
Electron: 9.3.3
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Windows_NT x64 10.0.20201

Logs Of TS Server || GraphQL Language Service

undefined
10/28/2020, 12:58:20 PM [1] (pid: 1120103) graphql-language-service-usage-logs: Error: Unknown directive "@key".

Unknown directive "@key".

Unknown directive "@key".

Unknown directive "@key".

Unknown directive "@external".

undefined

UPDATE:

I have managed to get it working for now manually declaring the Federation directives (had to comment out _entities though since it didn't work.

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
tvvignesh commented 3 years ago

Okay, this is tricky. Adding federation types manually would make VSCode GraphQL extension work, but codegen fail since both use the same graphql-config

For eg. if I have the schema like this:

schema:
      - "http://g.lvh.me:2500/graphql"
      - "./packages/modules/**/schema/**/*.gql"

(I have also added the apollo federation spec to my gql files in the wildcard)

VSCode extension will work but graphql-codegen will fail since I already have federation: true set there and it anyways generates all federation types for me. So, manually defining or overriding it myself are causing errors. So, there needs to be a way like what codegen offers with federation: true in this extension as well I guess to offer proper GQL Federation support.

felipeqq2 commented 3 years ago

Any update on this? I think it would be great to support custom directives, so other platforms also work. I'm having problems with Fauna, and I already noticed many issues concerning Apollo/Relay

vegerot commented 2 years ago

Has any work begun on this?

wangmir commented 1 week ago

Any update on this? At least can we ignore error, and support possible one?