Skip to content

Commit

Permalink
polishing up registering rule in to index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-zhang-at-salesforce committed May 17, 2024
1 parent d5a7449 commit fce4248
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 145 deletions.
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import base from './configs/base.js';
import recommended from './configs/recommended.js';
import enforceFooBar from './rules/dummy/enforce-foo-bar.js';
import { rule as noAggregateQuerySupported } from './rules/graphql/no-aggregate-query-supported.js';
import {
NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID,
rule as noAggregateQuerySupported
} from './rules/graphql/no-aggregate-query-supported.js';

import { name, version } from '../package.json';

Expand All @@ -23,6 +26,6 @@ export = {
},
rules: {
'enforce-foo-bar': enforceFooBar,
'no-aggregate-query-supported': noAggregateQuerySupported
[NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID]: noAggregateQuerySupported
}
};
37 changes: 32 additions & 5 deletions src/rules/graphql/no-aggregate-query-supported.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
import { FieldNode } from 'graphql';
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';

export const NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID = 'no-aggregate-query-supported';

export const rule: GraphQLESLintRule = {
meta: {
type: 'suggestion',
docs: {
category: 'Operations',
description:
'Inform that aggregate operation in graphql query is not supported for mobile offline.'
'Inform that aggregate operation in graphql query is not supported for mobile offline.',
// url:
examples: [{
title: 'Incorrect',
code: /* GraphQL */ `
query AvgOpportunityExample {
uiapi {
aggregate {
Opportunity {
edges {
node {
aggregate {
Amount {
avg {
value
displayValue
}
}
}
}
}
}
}
}
}
`
}]
},
messages: {
aggregateQueryNotSupported:
[NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID]:
'Aggregate operation in graphql query is not supported for mobile offline'
},
schema: []
Expand All @@ -20,7 +47,7 @@ export const rule: GraphQLESLintRule = {
create(context: GraphQLESLintRuleContext) {
return {
Field(node) {
// report
// report lint issue if the graphql is like '... uiapi { aggregate { ...'
if (
node.name.value !== 'aggregate' ||
node.parent?.parent === undefined ||
Expand All @@ -34,10 +61,10 @@ export const rule: GraphQLESLintRule = {
if (upperField.name.value === 'uiapi') {
context.report({
node: node.name,
messageId: 'aggregateQueryNotSupported'
messageId: NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID
});
}
}
};
}
};
};
138 changes: 0 additions & 138 deletions src/rules/graphql/utils/types.ts

This file was deleted.

0 comments on commit fce4248

Please sign in to comment.