fix(roles): remove duplicate RLS fragment definitions in getRolesQuery
https://sonarly.com/issue/35597?type=bug The settings roles page fails with a GraphQL validation error due to duplicate fragment definitions in the GetRoles query, preventing users from viewing or managing roles. Fix: ## What Changed Removed duplicate GraphQL fragment definitions from `getRolesQuery.ts`: 1. **Removed imports** (lines 7-8): - `ROW_LEVEL_PERMISSION_PREDICATE_FRAGMENT` - `ROW_LEVEL_PERMISSION_PREDICATE_GROUP_FRAGMENT` 2. **Removed fragment inclusions** from the gql template (lines 20-21): - `${ROW_LEVEL_PERMISSION_PREDICATE_FRAGMENT}` - `${ROW_LEVEL_PERMISSION_PREDICATE_GROUP_FRAGMENT}` ## Why This Fixes the Bug The query was including the RLS fragment definitions twice: - Once directly in `getRolesQuery.ts` (lines 20-21) - Once inside `OBJECT_PERMISSION_FRAGMENT` (which is included on line 16) When Apollo Client compiled the query, it encountered duplicate definitions of `RowLevelPermissionPredicateFragment` and `RowLevelPermissionPredicateGroupFragment`, causing the GraphQL validation error: "Fields '__type' conflict because they have differing arguments." The fix removes the direct inclusion while keeping the fragments available through `OBJECT_PERMISSION_FRAGMENT`, which correctly defines them for its nested fields. ## Query Structure After Fix The query still fetches all the same data: - `getRoles.objectPermissions.rowLevelPermissionPredicates` uses the fragment from `OBJECT_PERMISSION_FRAGMENT` - `getRoles.rowLevelPermissionPredicates` uses the same fragment definition (available in the query scope via `OBJECT_PERMISSION_FRAGMENT`) - No duplicate definitions, no validation error ## Pattern Consistency This fix aligns with the team's established pattern. Other queries using `OBJECT_PERMISSION_FRAGMENT` correctly omit direct RLS fragment imports: - `upsertObjectPermissionsMutation.ts` ✓ - `userQueryFragment.ts` ✓ - `getRolesQuery.ts` ✓ (after this fix)
This commit is contained in:
@@ -4,8 +4,6 @@ import { FIELD_PERMISSION_FRAGMENT } from '@/settings/roles/graphql/fragments/fi
|
||||
import { OBJECT_PERMISSION_FRAGMENT } from '@/settings/roles/graphql/fragments/objectPermissionFragment';
|
||||
import { PERMISSION_FLAG_FRAGMENT } from '@/settings/roles/graphql/fragments/permissionFlagFragment';
|
||||
import { ROLE_FRAGMENT } from '@/settings/roles/graphql/fragments/roleFragment';
|
||||
import { ROW_LEVEL_PERMISSION_PREDICATE_FRAGMENT } from '@/settings/roles/graphql/fragments/rowLevelPermissionPredicateFragment';
|
||||
import { ROW_LEVEL_PERMISSION_PREDICATE_GROUP_FRAGMENT } from '@/settings/roles/graphql/fragments/rowLevelPermissionPredicateGroupFragment';
|
||||
import { PARTIAL_WORKSPACE_MEMBER_QUERY_FRAGMENT } from '@/workspace-member/graphql/fragments/partialWorkspaceMemberQueryFragment';
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
@@ -17,8 +15,6 @@ export const GET_ROLES = gql`
|
||||
${PERMISSION_FLAG_FRAGMENT}
|
||||
${OBJECT_PERMISSION_FRAGMENT}
|
||||
${FIELD_PERMISSION_FRAGMENT}
|
||||
${ROW_LEVEL_PERMISSION_PREDICATE_FRAGMENT}
|
||||
${ROW_LEVEL_PERMISSION_PREDICATE_GROUP_FRAGMENT}
|
||||
query GetRoles {
|
||||
getRoles {
|
||||
...RoleFragment
|
||||
|
||||
Reference in New Issue
Block a user