Skip to content

Commit

Permalink
fix: add apex rule msg referring to graphql and link rule doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-zhang-at-salesforce committed Nov 15, 2024
1 parent 32dac44 commit 6407e7e
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/rules/apex/apex-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 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';

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

Expand All @@ -23,12 +24,13 @@ export const rule = ESLintUtils.RuleCreator.withoutDocs({
},
meta: {
docs: {
url: getDocUrl(APEX_IMPORT_RULE_ID),
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 careful consideration in offline scenarios. 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'
},
type: 'suggestion',
schema: []
Expand Down
2 changes: 2 additions & 0 deletions src/rules/graphql/no-aggregate-query-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

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

Expand All @@ -16,6 +17,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID),
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
2 changes: 2 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,15 @@ 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';
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(NO_FISCAL_DATE_FILTER_SUPPORTED_RULE_ID),
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
2 changes: 2 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,6 +7,7 @@

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_1_PARENT_RECORD_RULE_ID = 'offline-graphql-no-more-than-1-parent-record';

Expand All @@ -16,6 +17,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(NO_MORE_THAN_1_PARENT_RECORD_RULE_ID),
description: `Queries fetching child entities can only fetch 1 parent record. Set the parent's 'first' argument value to 1.`,
examples: [
{
Expand Down
2 changes: 2 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,6 +13,7 @@ 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 MAX_SOQL_API_SERVER_ALLOWD_RECORD_NUMBER = 200;
Expand All @@ -23,6 +24,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(NO_MORE_THAN_100_FIELDS_RULE_ID),
description:
'For an entity with more than 100 fields, the server may not return all of the expected records',
examples: [
Expand Down
2 changes: 2 additions & 0 deletions src/rules/graphql/no-more-than-3-child-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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';

Expand All @@ -16,6 +17,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(NO_MORE_THAN_3_CHILD_ENTITIES_RULE_ID),
description: `Do not fetch more than 3 child entities.`,
examples: [
{
Expand Down
2 changes: 2 additions & 0 deletions src/rules/graphql/no-more-than-3-root-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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';

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

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

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

Expand All @@ -17,6 +18,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(NO_MUTATION_SUPPORTED_RULE_ID),
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
4 changes: 3 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,6 +6,7 @@
*/

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

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

Expand All @@ -14,9 +15,10 @@ export const rule: GraphQLESLintRule = {
type: 'problem',
hasSuggestions: false,
docs: {
category: 'Operations',
url: getDocUrl(NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID),
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
2 changes: 2 additions & 0 deletions src/rules/graphql/unsupported-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const SCOPE_SUPPORTED_FOR_CERTAIN_ENTITIES_ONLY = 'ASSIGNED_TO_ME__SERVIC
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 +26,7 @@ export const rule: GraphQLESLintRule = {
type: 'problem',
docs: {
category: 'Operations',
url: getDocUrl(UNSUPPORTED_SCOPE_RULE_ID),
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 6407e7e

Please sign in to comment.