Quramy / ts-graphql-plugin

TypeScript Language Service Plugin for GraphQL developers
MIT License
726 stars 26 forks source link

ts-graphql-plugin does not understand directive @connection (relay) #118

Open devkral opened 4 years ago

devkral commented 4 years ago

In the relay standard exists an extra directive @connection for paging. It is at least used by the apollo and relay toolkits. ts-graphql-plugin complains that it doesn't know this directive. Can you whitelist it?

devkral commented 4 years ago

this only happens with the validate command.

Quramy commented 4 years ago

You can tell custom directives with local schema. see https://github.com/Quramy/ts-graphql-plugin#localschemaextensions

kirkobyte commented 3 years ago

I've tried defining a custom schema directive that way, and I'm receiving this error:

Schema build error: 'Directive "@client" already exists in the schema. It cannot be redefined.

Directive "@batch" already exists in the schema. It cannot be redefined.'

I think it could be because the directive exists in the introspection query result as a type. Here's my set-up:

schema.json:

{
  "__schema": {
    // ...
    "types": [
      {
        "name": "batch",
        "description": null,
        "isRepeatable": false,
        "locations": [
          "QUERY"
        ],
        "args": [
          {
            "name": "argument",
            "description": null,
            "type": {
              "kind": "SCALAR",
              "name": "String",
              "ofType": null
            },
            "defaultValue": null,
            "isDeprecated": false,
            "deprecationReason": null
          }
        ]
      }
    ]
  }
}

local-extensions.graphql:

directive @batch(argument: String) on QUERY

project-file.ts:

export const DECORATE_ALBUM_GROUPS = gql`
  query QueryName($ids: [String!]!) @batch(argument: "id") {
    //...
  }

tsconfig:

{
  // ...
  "compilerOptions": {
    "plugins": [
      {
        "name": "ts-graphql-plugin",
        "schema": "schema.json",
        "localSchemaExtensions": ["local-extensions.graphql"],
        "tag": "gql",
        "typegen": {
          "addons": ["ts-graphql-plugin/addons/typed-query-document"]
        }
      }
    ]
  },
}