Adds graphql-eslint to require id fields when available on a type (#3002)

This commit is contained in:
Kamil Kisiela 2023-10-04 16:28:35 +02:00 committed by GitHub
parent cb466c7658
commit b039a05be9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 294 additions and 266 deletions

View file

@ -4,6 +4,13 @@ const guildConfig = require('@theguild/eslint-config/base');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { REACT_RESTRICTED_SYNTAX, RESTRICTED_SYNTAX } = require('@theguild/eslint-config/constants');
const SCHEMA_PATH = './packages/services/api/src/modules/*/module.graphql.ts';
const OPERATIONS_PATHS = [
'./packages/web/app/**/*.ts',
'./packages/web/app/**/*.tsx',
'./packages/web/app/**/*.graphql',
];
const rulesToExtends = Object.fromEntries(
Object.entries(guildConfig.rules).filter(([key]) =>
[
@ -32,7 +39,6 @@ const HIVE_RESTRICTED_SYNTAX = [
];
module.exports = {
reportUnusedDisableDirectives: true,
ignorePatterns: [
'scripts',
'rules',
@ -47,52 +53,86 @@ module.exports = {
'codegen.cjs',
'tsup',
],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
project: ['./tsconfig.eslint.json'],
},
parser: '@typescript-eslint/parser',
plugins: [...guildConfig.plugins, 'hive'],
extends: guildConfig.extends,
rules: {
'no-process-env': 'error',
'no-empty': ['error', { allowEmptyCatch: true }],
'import/no-absolute-path': 'error',
'import/no-self-import': 'error',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'packages/services/storage/tools/*.js',
'packages/services/**',
'packages/migrations/**',
],
optionalDependencies: false,
},
],
'hive/enforce-deps-in-dev': [
'error',
{
scopes: ['@hive', '@graphql-hive'],
ignored: ['packages/libraries/**', 'packages/web/**'],
},
],
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
...rulesToExtends,
'no-restricted-syntax': ['error', ...HIVE_RESTRICTED_SYNTAX, ...RESTRICTED_SYNTAX],
// 🚨 The following rules needs to be fixed and was temporarily disabled to avoid printing warning
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/triple-slash-reference': 'off',
},
// parserOptions: {
// ecmaVersion: 2020,
// sourceType: 'module',
// project: ['./tsconfig.eslint.json'],
// },
// parser: '@typescript-eslint/parser',
// plugins: [...guildConfig.plugins, 'hive'],
// extends: guildConfig.extends,
overrides: [
{
// Setup GraphQL Parser
files: '*.{graphql,gql}',
parser: '@graphql-eslint/eslint-plugin',
plugins: ['@graphql-eslint'],
parserOptions: {
schema: SCHEMA_PATH,
operations: OPERATIONS_PATHS,
},
},
{
// Setup processor for operations/fragments definitions on code-files
files: ['packages/web/app/**/*.tsx', 'packages/web/app/**/*.ts'],
processor: '@graphql-eslint/graphql',
},
{
files: ['packages/web/app/**/*.graphql'],
plugins: ['@graphql-eslint'],
rules: {
'@graphql-eslint/require-id-when-available': 'error',
},
},
{
files: ['packages/**/*.ts', 'packages/**/*.tsx', 'cypress/**/*.ts', 'cypress/**/*.tsx'],
reportUnusedDisableDirectives: true,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
project: ['./tsconfig.eslint.json'],
},
parser: '@typescript-eslint/parser',
plugins: [...guildConfig.plugins, 'hive'],
extends: guildConfig.extends,
rules: {
'no-process-env': 'error',
'no-empty': ['error', { allowEmptyCatch: true }],
'import/no-absolute-path': 'error',
'import/no-self-import': 'error',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'packages/services/storage/tools/*.js',
'packages/services/**',
'packages/migrations/**',
],
optionalDependencies: false,
},
],
'hive/enforce-deps-in-dev': [
'error',
{
scopes: ['@hive', '@graphql-hive'],
ignored: ['packages/libraries/**', 'packages/web/**'],
},
],
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
...rulesToExtends,
'no-restricted-syntax': ['error', ...HIVE_RESTRICTED_SYNTAX, ...RESTRICTED_SYNTAX],
// 🚨 The following rules needs to be fixed and was temporarily disabled to avoid printing warning
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/triple-slash-reference': 'off',
},
},
{
files: ['packages/web/**'],
extends: [

View file

@ -61,6 +61,7 @@
"@graphql-codegen/typescript": "4.0.1",
"@graphql-codegen/typescript-operations": "4.0.1",
"@graphql-codegen/typescript-resolvers": "4.0.1",
"@graphql-eslint/eslint-plugin": "3.20.1",
"@graphql-inspector/cli": "4.0.2",
"@manypkg/get-packages": "2.2.0",
"@next/eslint-plugin-next": "13.5.3",

View file

@ -103,6 +103,7 @@ const TargetExplorerPageQuery = graphql(`
cleanId
}
target(selector: { organization: $organizationId, project: $projectId, target: $targetId }) {
id
cleanId
latestSchemaVersion {
__typename

View file

@ -131,6 +131,7 @@ const TargetExplorerTypenamePageQuery = graphql(`
cleanId
}
target(selector: { organization: $organizationId, project: $projectId, target: $targetId }) {
id
cleanId
latestSchemaVersion {
__typename

View file

@ -359,6 +359,7 @@ const TargetHistoryPageQuery = graphql(`
}
}
me {
id
...TargetLayout_MeFragment
}
...TargetLayout_IsCDNEnabledFragment

View file

@ -164,6 +164,7 @@ const SchemaView_SchemaFragment = graphql(`
const SchemaView_TargetFragment = graphql(`
fragment SchemaView_TargetFragment on Target {
id
cleanId
latestSchemaVersion {
id

View file

@ -112,6 +112,7 @@ const TargetOperationsPageQuery = graphql(`
cleanId
}
target(selector: { organization: $organizationId, project: $projectId, target: $targetId }) {
id
cleanId
}
hasCollectedOperations(

View file

@ -148,6 +148,7 @@ const OperationInsightsPageQuery = graphql(`
cleanId
}
target(selector: { organization: $organizationId, project: $projectId, target: $targetId }) {
id
cleanId
}
hasCollectedOperations(

View file

@ -369,6 +369,7 @@ const ClientInsightsPageQuery = graphql(`
cleanId
}
target(selector: { organization: $organizationId, project: $projectId, target: $targetId }) {
id
cleanId
}
hasCollectedOperations(

View file

@ -383,9 +383,11 @@ const TargetSchemaCoordinatePageQuery = graphql(`
}
project(selector: { organization: $organizationId, project: $projectId }) {
...TargetLayout_CurrentProjectFragment
id
cleanId
}
target(selector: { organization: $organizationId, project: $projectId, target: $targetId }) {
id
cleanId
}
hasCollectedOperations(

View file

@ -641,6 +641,7 @@ const TargetLaboratoryPageQuery = graphql(`
organization {
...TargetLayout_CurrentOrganizationFragment
me {
id
...CanAccessTarget_MemberFragment
}
}
@ -657,6 +658,7 @@ const TargetLaboratoryPageQuery = graphql(`
}
}
me {
id
...TargetLayout_MeFragment
}
...TargetLayout_IsCDNEnabledFragment

View file

@ -839,6 +839,7 @@ const TargetSettingsPage_UpdateTargetNameMutation = graphql(`
const TargetSettingsPage_TargetFragment = graphql(`
fragment TargetSettingsPage_TargetFragment on Target {
id
name
baseSchema
}
@ -903,6 +904,7 @@ const TargetSettingsPageQuery = graphql(`
}
organization(selector: { organization: $organizationId }) {
organization {
id
cleanId
...TargetLayout_CurrentOrganizationFragment
...TargetSettingsPage_OrganizationFragment
@ -912,10 +914,12 @@ const TargetSettingsPageQuery = graphql(`
}
}
project(selector: { organization: $organizationId, project: $projectId }) {
id
cleanId
...TargetLayout_CurrentProjectFragment
}
target(selector: { organization: $organizationId, project: $projectId, target: $targetId }) {
id
cleanId
name
graphqlEndpointUrl

View file

@ -362,6 +362,7 @@ const ProjectOverviewPageQuery = graphql(`
}
}
me {
id
...ProjectLayout_MeFragment
}
}

View file

@ -155,8 +155,10 @@ export function Alerts(props: {
const ProjectAlertsPage_OrganizationFragment = graphql(`
fragment ProjectAlertsPage_OrganizationFragment on Organization {
id
cleanId
me {
id
...CanAccessProject_MemberFragment
}
}
@ -189,6 +191,7 @@ const ProjectAlertsPageQuery = graphql(`
...ProjectLayout_OrganizationConnectionFragment
}
me {
id
...ProjectLayout_MeFragment
}
}

View file

@ -30,6 +30,7 @@ const ProjectPolicyPageQuery = graphql(`
}
}
me {
id
...CanAccessProject_MemberFragment
}
...ProjectLayout_CurrentOrganizationFragment
@ -49,6 +50,7 @@ const ProjectPolicyPageQuery = graphql(`
...ProjectLayout_OrganizationConnectionFragment
}
me {
id
...ProjectLayout_MeFragment
}
}

View file

@ -50,6 +50,7 @@ const GithubIntegration_GithubIntegrationDetailsQuery = graphql(`
query getGitHubIntegrationDetails($selector: OrganizationSelectorInput!) {
organization(selector: $selector) {
organization {
id
gitHubIntegration {
repositories {
nameWithOwner
@ -208,8 +209,11 @@ const ProjectSettingsPage_UpdateProjectNameMutation = graphql(`
const ProjectSettingsPage_OrganizationFragment = graphql(`
fragment ProjectSettingsPage_OrganizationFragment on Organization {
id
cleanId
name
me {
id
...CanAccessProject_MemberFragment
}
...ExternalCompositionSettings_OrganizationFragment
@ -242,6 +246,7 @@ const ProjectSettingsPageQuery = graphql(`
...ProjectLayout_OrganizationConnectionFragment
}
me {
id
...ProjectLayout_MeFragment
}
isGitHubIntegrationFeatureEnabled

View file

@ -242,6 +242,7 @@ const OrganizationProjectsPageQuery = graphql(`
organization(selector: { organization: $organizationId }) {
organization {
...OrganizationLayout_CurrentOrganizationFragment
id
cleanId
}
}

View file

@ -211,6 +211,7 @@ const Invitation = (props: {
const Page_OrganizationFragment = graphql(`
fragment Page_OrganizationFragment on Organization {
me {
id
...CanAccessOrganization_MemberFragment
...ChangePermissionsModal_MemberFragment
}
@ -223,6 +224,7 @@ const Page_OrganizationFragment = graphql(`
id
...ChangePermissionsModal_MemberFragment
user {
id
provider
displayName
email
@ -237,6 +239,7 @@ const Page_OrganizationFragment = graphql(`
const OrganizationInvitations_OrganizationFragment = graphql(`
fragment OrganizationInvitations_OrganizationFragment on Organization {
id
cleanId
invitations {
nodes {
@ -414,6 +417,7 @@ const OrganizationMembersPageQuery = graphql(`
...OrganizationLayout_OrganizationConnectionFragment
}
me {
id
...OrganizationLayout_MeFragment
...OrganizationMembersPage_MeFragment
}

View file

@ -35,6 +35,7 @@ const SubscriptionPage_OrganizationFragment = graphql(`
id
}
upcomingInvoice {
id
amount
date
}

View file

@ -24,6 +24,7 @@ const JoinOrganizationPage_JoinOrganizationMutation = graphql(`
organization
}
organization {
id
name
cleanId
}

View file

@ -175,12 +175,15 @@ const AdminStatsQuery = graphql(`
cleanId
name
owner {
id
user {
id
email
}
}
members {
nodes {
id
user {
id
email

View file

@ -28,6 +28,7 @@ const TargetLayout_CurrentOrganizationFragment = graphql(`
name
cleanId
me {
id
...CanAccessTarget_MemberFragment
}
...UserMenu_CurrentOrganizationFragment

View file

@ -456,6 +456,7 @@ const OperationsList_OperationsStatsQuery = graphql(`
}
operations {
nodes {
id
__typename
}
}

View file

@ -6,6 +6,7 @@ export { OrganizationAccessScope };
const CanAccessOrganization_MemberFragment = graphql(`
fragment CanAccessOrganization_MemberFragment on Member {
id
organizationAccessScopes
}
`);

View file

@ -6,6 +6,7 @@ export { ProjectAccessScope };
const CanAccessProject_MemberFragment = graphql(`
fragment CanAccessProject_MemberFragment on Member {
id
projectAccessScopes
}
`);

View file

@ -6,6 +6,7 @@ export { TargetAccessScope };
export const CanAccessTarget_MemberFragment = graphql(`
fragment CanAccessTarget_MemberFragment on Member {
id
targetAccessScopes
}
`);

File diff suppressed because it is too large Load diff