Skip to content

Commit

Permalink
Improve error messages for parserServices
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Dec 21, 2020
1 parent 63cecdd commit 1594288
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-feet-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

Improve error messages for parserServices
8 changes: 4 additions & 4 deletions packages/plugin/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { SiblingOperations } from './sibling-operations';
export function requireSiblingsOperations(ruleName: string, context: GraphQLESlintRuleContext<any>): SiblingOperations {
if (!context || !context.parserServices) {
throw new Error(
`You have used a rule ("${ruleName}") which requires parserServices to be generated with operations. You must therefore provide a value for the "parserOptions.operations" property for "@typescript-graphql/parser", or use graphql-config!`
`Rule '${ruleName}' requires 'parserOptions.operations' to be set and loaded. See http://bit.ly/graphql-eslint-operations for more info`
);
}

if (!context.parserServices.siblingOperations.available) {
throw new Error(
`You have used a rule which requires GraphQL operations to be loaded. Found "parserServices" generated, but unable to load your GraphQL operations.`
`Rule '${ruleName}' requires 'parserOptions.operations' to be set and loaded. See http://bit.ly/graphql-eslint-operations for more info`
);
}

Expand All @@ -25,13 +25,13 @@ export function requireGraphQLSchemaFromContext(
): GraphQLSchema {
if (!context || !context.parserServices) {
throw new Error(
`You have used a rule ("${ruleName}") which requires parserServices to be generated with GraphQL schema. You must therefore provide a value for the "parserOptions.schema" property for "@typescript-graphql/parser", or use graphql-config!`
`Rule '${ruleName}' requires 'parserOptions.schema' to be set. See http://bit.ly/graphql-eslint-schema for more info`
);
}

if (!context.parserServices.hasTypeInfo) {
throw new Error(
`You have used a rule which requires GraphQL Schema to be loaded. Found "parserServices" generated, but unable to load your GraphQL schema and it's type-info!`
`Rule '${ruleName}' requires 'parserOptions.schema' to be set and schema to be loaded. See http://bit.ly/graphql-eslint-schema for more info`
);
}

Expand Down

1 comment on commit 1594288

@bennypowers
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 nice

Please sign in to comment.