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

Add support for linting optional GraphQL rules #42

Closed
jnwng opened this issue Jan 27, 2017 · 2 comments
Closed

Add support for linting optional GraphQL rules #42

jnwng opened this issue Jan 27, 2017 · 2 comments
Labels
easy feature New addition or enhancement to existing solutions help wanted

Comments

@jnwng
Copy link
Contributor

jnwng commented Jan 27, 2017

Currently, eslint-plugin-graphql will check gql tagged templates against a provided schema. However, there are a certain set of "optional" GraphQL parameters that aren't a part of the schema but would be handy rules to lint against anyway.

For example, specifying the operationName is a very useful tool for "tagging" your GraphQL queries (see @stubailo's explanation here). Having a lint rule that allowed you to optionally enforce a unique operation name would help make this more widespread (should you choose to enable it).

Additionally, depending on which GraphQL client you use, naming your fragments may be a necessary part of the developer workflow - having the eslint-plugin-graphql lint to make sure you're naming your fragments would be useful.

In both cases, it might even be nice to establish a format for that name, given the module or component name (in React).

Is this a problem you've faced while using GraphQL?

@jnwng jnwng added easy feature New addition or enhancement to existing solutions help wanted labels Feb 7, 2017
@gauravmk
Copy link
Contributor

Agreed, having a lint rule to enforce queries have an operationName would be great. We rely on operationNames for performance logging, so we definitely want to avoid nameless queries creeping into our codebase.

@gauravmk
Copy link
Contributor

gauravmk commented Mar 7, 2017

something like:

export function OperationsMustHaveNames(context) {
  return {
    OperationDefinition(node) {
      if (!node.name) {
        context.reportError(
          new GraphQLError("All queries must be named", [ node ])
        );
      }
    },
  };
}

This doesn't enforce name uniqueness though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy feature New addition or enhancement to existing solutions help wanted
Projects
None yet
Development

No branches or pull requests

2 participants