Skip to content

Support ignoreClientDirectives in operation definitions #1076

@joelmukuthu

Description

@joelmukuthu

Is your feature request related to a problem? Please describe.

I have a graphql-eslint setup working well but ran into an issue with the @graphql-eslint/known-directives rule. I use https://www.npmjs.com/package/@habx/apollo-multi-endpoint-link which provides an @api client directive like so:

query projectList($params: Params) @api(name: projects) {
  projects(params: $params) {
    nodes {
      id
      name
    }
  }
}

I've tried to ignore the @api as follows but this doesn't seem to work:

module.exports = {
  overrides: [
    {
      files: ['browser/helpers/graphql/**/*.ts'],
      processor: '@graphql-eslint/graphql',
    },
    {
      files: ['*.graphql'],
      extends: 'plugin:@graphql-eslint/operations-all',
      rules: {
        '@graphql-eslint/known-directives': [
          'error',
          { ignoreClientDirectives: ['api', 'client'] },
        ],
      },
    },
  ],
};

I was about to add a failing test and came across this https://github.com/B2o5T/graphql-eslint/blob/441997657210c4fbf5ee27cedaa6a21033c8a299/packages/plugin/tests/known-directives.spec.ts#L38-L45

Which suggests that it was a conscious decision to only ignore client directives at certain positions.

Describe the solution you'd like

Enable ignoring client directives in the operation definition.

Describe alternatives you've considered

  • Disable the rule entirely
  • Disable the rule in every operation where it's used

Additional context

I know that what https://www.npmjs.com/package/@habx/apollo-multi-endpoint-link does is not encouraged in GraphQl. I work in a project where micro-services expose GraphQl endpoints and it didn't make sense for us to create a proxy GraphQl server to merge all the schemas, so we went with this direction. Anyway, I'd understand if you're not willing to add support for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stage/6-releasedThe issue has been solved on a released version of the library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions