Skip to content

Commit

Permalink
fix: add apex rule msg referring to graphql and link rule doc (#86)
Browse files Browse the repository at this point in the history
* fix: add apex rule msg referring to graphql and link rule doc

* fix: update message for apex rule

* docs: update the url to point to correct md file
  • Loading branch information
ben-zhang-at-salesforce authored Nov 22, 2024
1 parent 8e9702e commit bf87da8
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/rules/apex/apex-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { ESLintUtils } from '@typescript-eslint/utils';
import { getDocUrl } from '../../util/rule-helpers';

const RULE_NAME = 'apex-import';
export const APEX_IMPORT_RULE_ID = 'lwc-offline-apex-import';

export const rule = ESLintUtils.RuleCreator.withoutDocs({
Expand All @@ -23,12 +25,13 @@ export const rule = ESLintUtils.RuleCreator.withoutDocs({
},
meta: {
docs: {
url: getDocUrl(RULE_NAME),
description:
'Using Apex in LWC Offline-enabled mobile apps requires additional considerations to ensure proper functioning in offline scenarios. See Use Apex While Mobile and Offline (https://developer.salesforce.com/docs/atlas.en-us.mobile_offline.meta/mobile_offline/apex.htm) for more details. GraphQL API is a new paradigm of sending and receiving data. This API allows developers to interact with the Salesforce Platform through GraphQL, a standard query language for APIs and a runtime for fulfilling those queries with your data. Learn more about creating SOQL queries with GraphQL that may work better for mobile offline use cases. https://developer.salesforce.com/docs/platform/graphql/guide/graphql-wire-lwc.html'
},
messages: {
[APEX_IMPORT_RULE_ID]:
'Using Apex in LWC Offline-enabled mobile apps requires careful consideration in offline scenarios.'
'Using Apex in LWC Offline-enabled mobile apps requires additional considerations. Consider using GraphQL for mobile offline use cases.'
},
type: 'suggestion',
schema: []
Expand Down
3 changes: 3 additions & 0 deletions src/rules/graphql/no-aggregate-query-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import { Kind } from 'graphql';
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import { getDocUrl } from '../../util/rule-helpers';

const RULE_NAME = 'no-aggregate-query-supported';
export const NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID = 'offline-graphql-no-aggregate-query-supported';

export const rule: GraphQLESLintRule = {
Expand All @@ -16,6 +18,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(RULE_NAME),
description:
'Aggregate operations in a GraphQL query are not supported for mobile offline. See Feature Limitations of Offline GraphQL (https://developer.salesforce.com/docs/atlas.en-us.mobile_offline.meta/mobile_offline/use_graphql_limitations.htm) for more details.',
examples: [
Expand Down
4 changes: 4 additions & 0 deletions src/rules/graphql/no-fiscal-date-filtering-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import { ASTNode, Kind, ArgumentNode } from 'graphql';
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import { getClosestAncestorByType } from '../../util/graphql-ast-utils';
import { GraphQLESTreeNode } from '@graphql-eslint/eslint-plugin/estree-converter/types';
import { getDocUrl } from '../../util/rule-helpers';

const RULE_NAME = 'no-fiscal-date-filter-supported';
export const NO_FISCAL_DATE_FILTER_SUPPORTED_RULE_ID =
'offline-graphql-no-fiscal-date-filter-supported';

export const rule: GraphQLESLintRule = {
meta: {
type: 'problem',
docs: {
url: getDocUrl(RULE_NAME),
description:
'Fiscal date literals and ranges are not supported in filters for mobile offline. See Feature Limitations of Offline GraphQL (https://developer.salesforce.com/docs/atlas.en-us.mobile_offline.meta/mobile_offline/use_graphql_limitations.htm) for more details.',
category: 'Operations',
Expand Down
3 changes: 3 additions & 0 deletions src/rules/graphql/no-more-than-1-parent-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import { DocumentStat, ViolationType } from '../../util/entity-stats';
import { getDocUrl } from '../../util/rule-helpers';

const RULE_NAME = 'no-more-than-1-parent-record';
export const NO_MORE_THAN_1_PARENT_RECORD_RULE_ID = 'offline-graphql-no-more-than-1-parent-record';

export const rule: GraphQLESLintRule = {
Expand All @@ -16,6 +18,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(RULE_NAME),
description: `Queries fetching child entities can only fetch 1 parent record. Set the parent's 'first' argument value to 1.`,
examples: [
{
Expand Down
4 changes: 4 additions & 0 deletions src/rules/graphql/no-more-than-100-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import {
getPageSizeFromEntityNode,
getParentEntityNode
} from '../../util/graphql-ast-utils';
import { getDocUrl } from '../../util/rule-helpers';

export const NO_MORE_THAN_100_FIELDS_RULE_ID = 'offline-graphql-no-more-than-100-fields';

const RULE_NAME = 'no-more-than-100-fields';
const MAX_SOQL_API_SERVER_ALLOWD_RECORD_NUMBER = 200;

export const rule: GraphQLESLintRule = {
Expand All @@ -23,6 +26,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(RULE_NAME),
description:
'For an entity with more than 100 fields, the server may not return all of the expected records',
examples: [
Expand Down
6 changes: 5 additions & 1 deletion src/rules/graphql/no-more-than-3-child-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@

import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import { DocumentStat, ViolationType } from '../../util/entity-stats';
import { getDocUrl } from '../../util/rule-helpers';

export const NO_MORE_THAN_3_CHILD_ENTITIES_RULE_ID = 'offline-graphql-no-more-3-child-entities';
const RULE_NAME = 'no-more-than-3-child-entities';
export const NO_MORE_THAN_3_CHILD_ENTITIES_RULE_ID =
'offline-graphql-no-more-than-3-child-entities';

export const rule: GraphQLESLintRule = {
meta: {
type: 'suggestion',
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(RULE_NAME),
description: `Do not fetch more than 3 child entities.`,
examples: [
{
Expand Down
5 changes: 4 additions & 1 deletion src/rules/graphql/no-more-than-3-root-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@

import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import { DocumentStat, ViolationType } from '../../util/entity-stats';
import { getDocUrl } from '../../util/rule-helpers';

export const NO_MORE_THAN_3_ROOT_ENTITIES_RULE_ID = 'offline-graphql-no-more-3-root-entities';
const RULE_NAME = 'no-more-than-3-root-entities';
export const NO_MORE_THAN_3_ROOT_ENTITIES_RULE_ID = 'offline-graphql-no-more-than-3-root-entities';

export const rule: GraphQLESLintRule = {
meta: {
type: 'suggestion',
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(RULE_NAME),
description: `Do not fetch more than 3 root entities.`,
examples: [
{
Expand Down
3 changes: 3 additions & 0 deletions src/rules/graphql/no-mutation-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';

import { getLocation } from '../../util/graphql-ast-utils';
import { getDocUrl } from '../../util/rule-helpers';

const RULE_NAME = 'no-mutation-supported';
export const NO_MUTATION_SUPPORTED_RULE_ID = 'offline-graphql-no-mutation-supported';

export const rule: GraphQLESLintRule = {
Expand All @@ -17,6 +19,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(RULE_NAME),
description:
'Mutation (data modification) is not supported for mobile offline. See Feature Limitations of Offline GraphQL (https://developer.salesforce.com/docs/atlas.en-us.mobile_offline.meta/mobile_offline/use_graphql_limitations.htm) for more details.',
recommended: true,
Expand Down
5 changes: 4 additions & 1 deletion src/rules/graphql/no-semi-anti-join-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
*/

import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import { getDocUrl } from '../../util/rule-helpers';

const RULE_NAME = 'no-semi-anti-join-supported';
export const NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID = 'offline-graphql-no-semi-anti-join-supported';

export const rule: GraphQLESLintRule = {
meta: {
type: 'problem',
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(RULE_NAME),
description:
'Semi-join and anti-join filters are not supported for mobile offline. See Feature Limitations of Offline GraphQL (https://developer.salesforce.com/docs/atlas.en-us.mobile_offline.meta/mobile_offline/use_graphql_limitations.htm) for more details.',
category: 'Operations',
recommended: true,
examples: [
{
Expand Down
3 changes: 3 additions & 0 deletions src/rules/graphql/unsupported-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import { Kind, FieldNode } from 'graphql';

const RULE_NAME = 'unsupported-scope';
export const UNSUPPORTED_SCOPE_RULE_ID = 'offline-graphql-unsupported-scope';

export const SCOPE_SUPPORTED_FOR_CERTAIN_ENTITIES_ONLY = 'ASSIGNED_TO_ME__SERVICEAPPOINTMENT_ONLY';
export const OTHER_UNSUPPORTED_SCOPE = 'OTHER_UNSUPPORTED_SCOPE';

import { GraphQLESTreeNode } from '@graphql-eslint/eslint-plugin/estree-converter/types';
import { getDocUrl } from '../../util/rule-helpers';

// Record key is scope name, value is the array of supported entities. Empty array
// means that all entities are supported.
Expand All @@ -25,6 +27,7 @@ export const rule: GraphQLESLintRule = {
type: 'problem',
docs: {
category: 'Operations',
url: getDocUrl(RULE_NAME),
description: `Offline GraphQL supports the scope "MINE" for all entities, and "ASSIGNEDTOME" for ServiceAppointment. All other scopes (for example TEAM, QUEUE_OWNED and USER_OWNED) are not supported for mobile offline. See Feature Limitations of Offline GraphQL (https://developer.salesforce.com/docs/atlas.en-us.mobile_offline.meta/mobile_offline/use_graphql_limitations.htm) for more details.`,
recommended: true,
examples: [
Expand Down
2 changes: 1 addition & 1 deletion src/util/rule-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ESLintUtils } from '@typescript-eslint/utils';
import { version, homepage } from '../../package.json';

export function getDocUrl(ruleName: string): string {
return `${homepage}/blob/v${version}/lib/docs/${ruleName}.md`;
return `${homepage}/blob/v${version}/src/docs/${ruleName}.md`;
}

export const createRule = ESLintUtils.RuleCreator((name) => getDocUrl(name));
Expand Down
2 changes: 1 addition & 1 deletion test/util/rule-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ describe('getDocUrl', () => {
expect(
docUrl.startsWith('https://github.com/salesforce/eslint-plugin-lwc-mobile/blob/v')
).toBe(true);
expect(docUrl.endsWith('/lib/docs/ruleNameXYZ.md')).toBe(true);
expect(docUrl.endsWith('/src/docs/ruleNameXYZ.md')).toBe(true);
});
});

0 comments on commit bf87da8

Please sign in to comment.