Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown directive "client" #209

Open
pitops opened this issue Jan 21, 2019 · 7 comments
Open

Unknown directive "client" #209

pitops opened this issue Jan 21, 2019 · 7 comments

Comments

@pitops
Copy link

pitops commented Jan 21, 2019

Using Apollo Client with gql

Consider the following query

mutation SET_FILTERS_MUTATION($fromDate: String!, $toDate: String!) {
    setFilters(fromDate: $fromDate, toDate: $toDate) @client
  }

The @client is not recognised by the plugin. Am I doing something wrong here?

eslint settings

rules: {
    'graphql/template-strings': [
      'error',
      {
        env: 'apollo',
        tagName: 'gql',
        projectName: 'app'
      }
    ]
  }
@JayKan
Copy link

JayKan commented Feb 20, 2019

I'm also having the similar issue, I believe the PR is currently being reviewed here 👍

@sampsonjoliver
Copy link

sampsonjoliver commented Jun 11, 2019

#117 hasn't had any movement for almost a year. This is a pretty significant issue to using the lint plugin within the apollo ecosystem.

@Nnoerregaard
Copy link

I experienced this problem as well and fixed it by upgrading the apollo CLI tooling to the latest version (currently 2.22.0).
I had a project on 2.18.x for which the problem did not occur and one with an identical eslint setup on 2.16.x where it did occur.
It seems that somewhere between 2.16.x and 2.18.x apollo client:download-schema must have been fixed to correctly include the directives that the backend accepts in the schema.json file it generates)

@sampsonjoliver
Copy link

sampsonjoliver commented Feb 6, 2020

I can confirm after updating graphql and apollo that the schema file generated after running apollo client:download-schema does include the client directive.

But the linter still fails on annotated fields that don't exist in the schema. So while the directive is recognised, the field still throws an error.

@sirugh
Copy link

sirugh commented Mar 17, 2020

But the linter still fails on annotated fields that don't exist in the schema. So while the directive is recognised, the field still throws an error.

I am seeing the same issue. Here's the query:

const GET_CHECKOUT_STEP = gql`
    query getCheckoutStep {
        # The current checkout step, stored locally for persistence.
        checkoutStep @client
    }
`;

and here's the lint error:

25:9 error Cannot query field "checkoutStep" on type "Query". Did you mean "checkoutAgreements"? graphql/template-strings

@mikeyrt16
Copy link

mikeyrt16 commented Mar 26, 2020

It's super annoying to not have full linter support for something so seemingly popular.

A workaround is to add something like this to your local schema definitions (https://graphql-code-generator.com/docs/integrations/apollo-local-state)

type User {
  isLoggedIn: Boolean!
}

directive @client on FIELD <---- This

I prevents the linting error, but obviously doesn't give us complete confidence that it's being used appropriately. Putting @client on a server field or missing it from a locally field both pass, but at least it still allows your linter to pass... For the love of God, someone point me to a library/plugin I've overlooked!

@penx
Copy link

penx commented Jul 13, 2020

A bit hacky but something like this in .eslintrc.js may help those using a local json file:

const schema = require('./schema.json');

schema.__schema.directives.push({
	name: 'client',
	locations: ['FIELD'],
	args: [],
});

module.exports = {
	rules: {
		'graphql/template-strings': [
			'warn',
			{
				env: 'apollo',
				schemaJson: schema,
			},
		],
	},
	plugins: ['graphql'],
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants