Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automating the doc schema generation using husky. #2851

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

Suyash878
Copy link
Contributor

@Suyash878 Suyash878 commented Jan 13, 2025

What kind of change does this PR introduce?

Feature

Issue Number:

Fixes #2818

Snapshots/Videos:

NA

If relevant, did you update the documentation?

Not sure.

Summary

I have added a new schema-script.mjs which automates the generation of schema.json and schema.md.

Does this PR introduce a breaking change?

NA

Checklist

CodeRabbit AI Review

  • I have reviewed and addressed all critical issues flagged by CodeRabbit AI
  • I have implemented or provided justification for each non-critical suggestion
  • I have documented my reasoning in the PR comments where CodeRabbit AI suggestions were not implemented

Test Coverage

  • I have written tests for all new changes/features
  • I have verified that test coverage meets or exceeds 95%
  • I have run the test suite locally and all tests pass

Other information

NA

Have you read the contributing guide?

Yes

Summary by CodeRabbit

Release Notes

  • Chores

    • Updated pre-commit hook to improve development workflow.
    • Reorganized project scripts and import fixing processes.
  • Documentation

    • Added comprehensive GraphQL schema documentation to improve developer understanding.
  • Build

    • Updated build script paths to reflect new project structure.

These changes enhance project development processes and documentation, providing better clarity and workflow management.

Copy link

coderabbitai bot commented Jan 13, 2025

Walkthrough

The pull request introduces modifications to the pre-commit hook script, enhancing the development workflow by removing the command for generating the schema and adjusting the sequence of commands executed during the commit process. A new command sleep 10 is added to wait for the server to be ready, and npm run format:fix is now executed before linting. Additionally, comprehensive GraphQL schema documentation has been added, and the package.json file reflects updated script paths for the fix-imports commands.

Changes

File Change Summary
.husky/pre-commit - Removed npm run gen:schema
- Added sleep 10
- Added npm run format:fix
- Commented out npm run lint:fix
docs/docs/Schema.md - Added comprehensive GraphQL schema documentation with detailed type descriptions
package.json - Updated build script paths for fix-imports from ./fix-imports/ to ./scripts/fix-imports/

Assessment against linked issues

Objective Addressed Explanation
Automate JSON schema file generation
Generate Schema markdown for Docusaurus
Create Docusaurus menu sidebar Requires verification of sidebar generation

Possibly related PRs

Suggested labels

ignore-sensitive-files-pr

Suggested reviewers

  • palisadoes

Poem

🐰 In the realm of code, a rabbit's delight,
Pre-commit hooks now dance with might!
Servers spin, schemas unfurl,
Documentation starts to swirl,
A commit's journey, smooth and bright! 🚀


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 033db80 and b30e9f4.

📒 Files selected for processing (1)
  • .husky/pre-commit (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .husky/pre-commit
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (typescript)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (3)
package.json (1)

26-27: Consider removing outdated scripts generate:graphql-markdown and generate:graphql-schema

With the introduction of the new generate:docs script, the previous scripts generate:graphql-markdown and generate:graphql-schema may no longer be necessary. Removing them can reduce confusion and redundancy.

Apply this diff to remove the outdated scripts:

-        "generate:graphql-markdown": "graphql-markdown http://localhost:4000/graphql > docs/docs/Schema.md",
-        "generate:graphql-schema": "get-graphql-schema http://localhost:4000/graphql --json > docs/github-actions/schema.json",
🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Package version mismatch: lock file's @types/[email protected] does not satisfy @types/[email protected]

docs/docs/Schema.md (2)

3-239: Enhance documentation structure for better readability

Consider organizing the table of contents hierarchically by grouping related types (e.g., Event-related types, User-related types, etc.) instead of a flat alphabetical list. This would make it easier for developers to find related functionality.

Example structure:

## Table of Contents

### Core Types
- Organization
- User
- Group

### Event Management
- Event
- EventAttendee
- EventVolunteer
- EventVolunteerGroup

### Content Management
- Post
- Comment
- Advertisement

...

2630-2641: Enhance connection types with additional fields

The UserTagsConnection type could benefit from additional fields to support more advanced pagination and filtering scenarios.

Consider adding:

type UserTagsConnection {
  edges: [UserTagsConnectionEdge!]!
  pageInfo: DefaultConnectionPageInfo!
  totalCount: Int
  # Add these fields
  filteredCount: Int
  hasMore: Boolean
  filterInfo: FilterMetadata
}

type FilterMetadata {
  appliedFilters: [String!]
  availableFilters: [String!]
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 25207c5 and 9ccdecd.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • .husky/pre-commit (1 hunks)
  • docs/docs/Schema.md (1 hunks)
  • package.json (3 hunks)
  • scripts/schema-generator.mjs (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: PR Workflow
.husky/pre-commit

[error] Unauthorized file modification or deletion attempt

scripts/schema-generator.mjs

[error] Unauthorized file modification or deletion attempt

package.json

[error] Package version mismatch: lock file's @types/[email protected] does not satisfy @types/[email protected]

🪛 eslint
scripts/schema-generator.mjs

[error] 30-30: 'schemaStr' is assigned a value but never used.

(@typescript-eslint/no-unused-vars)

🪛 Markdownlint (0.37.0)
docs/docs/Schema.md

645-645: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

(MD055, table-pipe-style)


646-646: Expected: leading_and_trailing; Actual: trailing_only; Missing leading pipe
Table pipe style

(MD055, table-pipe-style)


647-647: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

(MD055, table-pipe-style)


648-648: Expected: leading_and_trailing; Actual: trailing_only; Missing leading pipe
Table pipe style

(MD055, table-pipe-style)


649-649: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

(MD055, table-pipe-style)


650-650: Expected: leading_and_trailing; Actual: trailing_only; Missing leading pipe
Table pipe style

(MD055, table-pipe-style)


651-651: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

(MD055, table-pipe-style)


652-652: Expected: leading_and_trailing; Actual: trailing_only; Missing leading pipe
Table pipe style

(MD055, table-pipe-style)


2570-2570: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

(MD055, table-pipe-style)


2571-2571: Expected: leading_and_trailing; Actual: trailing_only; Missing leading pipe
Table pipe style

(MD055, table-pipe-style)


2575-2575: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

(MD055, table-pipe-style)


2576-2576: Expected: leading_and_trailing; Actual: trailing_only; Missing leading pipe
Table pipe style

(MD055, table-pipe-style)


2577-2577: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

(MD055, table-pipe-style)


2578-2578: Expected: leading_and_trailing; Actual: trailing_only; Missing leading pipe
Table pipe style

(MD055, table-pipe-style)


646-646: Expected: 3; Actual: 1; Too few cells, row will be missing data
Table column count

(MD056, table-column-count)


648-648: Expected: 3; Actual: 1; Too few cells, row will be missing data
Table column count

(MD056, table-column-count)


650-650: Expected: 3; Actual: 1; Too few cells, row will be missing data
Table column count

(MD056, table-column-count)


652-652: Expected: 3; Actual: 1; Too few cells, row will be missing data
Table column count

(MD056, table-column-count)


2571-2571: Expected: 3; Actual: 1; Too few cells, row will be missing data
Table column count

(MD056, table-column-count)


2576-2576: Expected: 3; Actual: 1; Too few cells, row will be missing data
Table column count

(MD056, table-column-count)


2578-2578: Expected: 3; Actual: 1; Too few cells, row will be missing data
Table column count

(MD056, table-column-count)

🪛 LanguageTool
docs/docs/Schema.md

[typographical] ~1322-~1322: If you want to indicate numerical ranges or time ranges, consider using an en dash.
Context: ...epresent values between -(2^31) and 2^31 - 1. ### InvalidCursor #### Fields | Fi...

(DASH_RULE)


[style] ~2843-~2843: Using many exclamation marks might seem excessive (in this case: 639 exclamation marks for a text that’s 57918 characters long)
Context: ...| | title | String! | | | userIds | [ID!]! | |

(EN_EXCESSIVE_EXCLAMATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (2)
scripts/schema-generator.mjs (1)

78-79: Verify if writing to 'docs/github-actions/' and 'docs/docs/' is allowed

The script writes files to docs/github-actions/schema.json and docs/docs/Schema.md. According to the pipeline failure:

[error]  Unauthorized file modification or deletion attempt

Please verify whether modifying files in these directories is permitted in the pre-commit hook or CI pipeline.

Run the following script to check if modifications to these directories are causing the pipeline failure:

Also applies to: 95-97, 101-104

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Unauthorized file modification or deletion attempt

package.json (1)

118-118: Verify if @graphql-markdown/docusaurus is required

The dependency @graphql-markdown/docusaurus has been added, but it appears that the new schema-generator.mjs script does not utilize it. Please verify if this dependency is necessary, and remove it if it's unused to keep the dependencies lean.

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Package version mismatch: lock file's @types/[email protected] does not satisfy @types/[email protected]

}

function generateSimpleMarkdown(schema) {
const schemaStr = printSchema(schema);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove unused variable schemaStr

The variable schemaStr is assigned a value but never used, leading to a linting error:

[error] 30-30: 'schemaStr' is assigned a value but never used. (@typescript-eslint/no-unused-vars)

Please remove it to clean up the code.

Apply this diff to fix the issue:

-  const schemaStr = printSchema(schema);
🧰 Tools
🪛 eslint

[error] 30-30: 'schemaStr' is assigned a value but never used.

(@typescript-eslint/no-unused-vars)

🪛 GitHub Actions: PR Workflow

[error] Unauthorized file modification or deletion attempt

@@ -13,6 +13,7 @@ npm run typecheck
npm run lint-staged

npm run gen:schema
npm run generate:docs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Remove generate:docs from pre-commit hook to prevent pipeline failures

The generate:docs script modifies git-tracked files in the docs/ directory, which can cause the pipeline to fail with "Unauthorized file modification" errors. Documentation generation should be moved to the CI/CD pipeline instead of running during pre-commit to:

  • Prevent commit failures due to unauthorized file modifications
  • Ensure consistent documentation across all branches
  • Avoid race conditions during concurrent commits
🔗 Analysis chain

Verify the impact of running npm run generate:docs in pre-commit

Adding npm run generate:docs to the pre-commit hook may cause the script to modify files that are not supposed to be changed during commit, leading to the pipeline failure:

[error]  Unauthorized file modification or deletion attempt

Please verify whether running this command in the pre-commit hook is appropriate and allowed.

Run the following script to identify files modified by the pre-commit hook:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check files modified by the pre-commit hook.

# Temporarily stash any staged changes
git stash -k --keep-index

# Run the pre-commit script
.husky/pre-commit

# List files modified by the pre-commit hook
git diff --name-only

# Restore the stashed changes
git stash pop

Length of output: 135


Script:

#!/bin/bash
# Check package.json for generate:docs script and search for documentation patterns
echo "=== Package.json scripts ==="
cat package.json | jq -r '.scripts | select(.["generate:docs"] != null)'

echo -e "\n=== Documentation output patterns ==="
# Look for common documentation output directories
fd -t d '(docs?|documentation|api-docs|reference)$'

echo -e "\n=== Documentation generation patterns ==="
# Search for documentation generation patterns
rg -l -i '(generate|build|create).*docs?' --type js --type json --type ts

Length of output: 3446


Script:

#!/bin/bash
# Examine schema generator implementation
echo "=== Schema Generator Content ==="
cat scripts/schema-generator.mjs

echo -e "\n=== Files in docs directory ==="
# Check if docs files are tracked
git ls-files docs/

echo -e "\n=== Git ignore patterns ==="
# Check if docs are ignored
cat .gitignore | grep -i "doc"

Length of output: 4268

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Unauthorized file modification or deletion attempt

Comment on lines +814 to +816
| Field | Type | Description |
|-------|------|-------------|
| success | Boolean! | |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding validation constraints to input types

Input types like UpdateUserInput lack validation constraints. Consider adding:

  • Length constraints for string fields
  • Range constraints for numeric fields
  • Format validation for specialized fields

Example:

input UpdateUserInput {
  firstName: String! @constraint(minLength: 1, maxLength: 50)
  lastName: String! @constraint(minLength: 1, maxLength: 50)
  email: EmailAddress! @constraint(format: "email")
  phone: UserPhoneInput
  birthDate: Date @constraint(min: "1900-01-01")
}

Also applies to: 2372-2388

Comment on lines +1473 to +1606
| createDonation | Donation! | |
| createEvent | Event! | |
| createEventVolunteer | EventVolunteer! | |
| createEventVolunteerGroup | EventVolunteerGroup! | |
| createFund | Fund! | |
| createFundraisingCampaign | FundraisingCampaign! | |
| createFundraisingCampaignPledge | FundraisingCampaignPledge! | |
| createMember | CreateMemberPayload! | |
| createNote | Note! | |
| createOrganization | Organization! | |
| createPlugin | Plugin! | |
| createPost | Post | |
| createSampleOrganization | Boolean! | |
| createUserFamily | UserFamily! | |
| createUserTag | UserTag | |
| createVenue | Venue | |
| createVolunteerMembership | VolunteerMembership! | |
| deleteAdvertisement | DeleteAdvertisementPayload | |
| deleteAgendaCategory | ID! | |
| deleteDonationById | DeletePayload! | |
| deleteNote | ID! | |
| deleteVenue | Venue | |
| editVenue | Venue | |
| forgotPassword | Boolean! | |
| inviteEventAttendee | EventAttendee! | |
| joinPublicOrganization | User! | |
| leaveOrganization | User! | |
| likeComment | Comment | |
| likePost | Post | |
| login | AuthData! | |
| logout | Boolean! | |
| markChatMessagesAsRead | Chat! | |
| otp | OtpData! | |
| recaptcha | Boolean! | |
| refreshToken | ExtendSession! | |
| registerEventAttendee | EventAttendee! | |
| registerForEvent | EventAttendee! | |
| rejectMembershipRequest | MembershipRequest! | |
| removeActionItem | ActionItem! | |
| removeAdmin | AppUserProfile! | |
| removeAdvertisement | Advertisement | |
| removeAgendaItem | AgendaItem! | |
| removeAgendaSection | ID! | |
| removeComment | Comment | |
| removeEvent | Event! | |
| removeEventAttendee | User! | |
| removeEventVolunteer | EventVolunteer! | |
| removeEventVolunteerGroup | EventVolunteerGroup! | |
| removeFromUserTags | UserTag | |
| removeFundraisingCampaignPledge | FundraisingCampaignPledge! | |
| removeMember | Organization! | |
| removeOrganization | UserData! | |
| removeOrganizationCustomField | OrganizationCustomField! | |
| removeOrganizationImage | Organization! | |
| removePost | Post | |
| removeSampleOrganization | Boolean! | |
| removeUserCustomData | UserCustomData! | |
| removeUserFamily | UserFamily! | |
| removeUserFromUserFamily | UserFamily! | |
| removeUserImage | User! | |
| removeUserTag | UserTag | |
| resetCommunity | Boolean! | |
| revokeRefreshTokenForUser | Boolean! | |
| saveFcmToken | Boolean! | |
| sendMembershipRequest | MembershipRequest! | |
| sendMessageToChat | ChatMessage! | |
| signUp | AuthData! | |
| togglePostPin | Post! | |
| unassignUserTag | User | |
| unblockUser | User! | |
| unlikeComment | Comment | |
| unlikePost | Post | |
| unregisterForEventByUser | Event! | |
| updateActionItem | ActionItem | |
| updateActionItemCategory | ActionItemCategory | |
| updateAdvertisement | UpdateAdvertisementPayload | |
| updateAgendaCategory | AgendaCategory | |
| updateAgendaItem | AgendaItem | |
| updateAgendaSection | AgendaSection | |
| updateChat | Chat! | |
| updateChatMessage | ChatMessage! | |
| updateCommunity | Boolean! | |
| updateEvent | Event! | |
| updateEventVolunteer | EventVolunteer! | |
| updateEventVolunteerGroup | EventVolunteerGroup! | |
| updateFund | Fund! | |
| updateFundraisingCampaign | FundraisingCampaign! | |
| updateFundraisingCampaignPledge | FundraisingCampaignPledge! | |
| updateLanguage | User! | |
| updateNote | Note! | |
| updateOrganization | Organization! | |
| updatePluginStatus | Plugin! | |
| updatePost | Post! | |
| updateSessionTimeout | Boolean! | |
| updateUserPassword | UserData! | |
| updateUserProfile | User! | |
| updateUserRoleInOrganization | Organization! | |
| updateUserTag | UserTag | |
| updateVolunteerMembership | VolunteerMembership! | |

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add access control directives and rate limiting documentation

The Mutation type contains sensitive operations that should be protected. Consider:

  1. Adding @auth directives to specify required permissions
  2. Documenting rate limiting for mutations like createDonation, sendMessageToChat
  3. Adding security considerations to the field descriptions

Example:

type Mutation {
  """
  Create a new donation.
  Requires: ADMIN role
  Rate limit: 10 requests per minute
  """
  createDonation(input: DonationInput!): Donation! @auth(requires: ADMIN)
}

Comment on lines +246 to +265
| Field | Type | Description |
|-------|------|-------------|
| _id | ID! | |
| actionItemCategory | ActionItemCategory | |
| allottedHours | Float | |
| assignee | EventVolunteer | |
| assigneeGroup | EventVolunteerGroup | |
| assigneeType | String! | |
| assigneeUser | User | |
| assigner | User | |
| assignmentDate | Date! | |
| completionDate | Date! | |
| createdAt | Date! | |
| creator | User | |
| dueDate | Date! | |
| event | Event | |
| isCompleted | Boolean! | |
| postCompletionNotes | String | |
| preCompletionNotes | String | |
| updatedAt | Date! | |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add missing field descriptions

Many fields lack descriptions, which makes it harder for API consumers to understand their purpose. Consider adding meaningful descriptions for all fields.

Example:

| Field | Type | Description |
|-------|------|-------------|
-| _id | ID! |  |
+| _id | ID! | Unique identifier for the action item |
-| actionItemCategory | ActionItemCategory |  |
+| actionItemCategory | ActionItemCategory | Category classification for the action item |
-| allottedHours | Float |  |
+| allottedHours | Float | Estimated time in hours to complete the action item |
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| Field | Type | Description |
|-------|------|-------------|
| _id | ID! | |
| actionItemCategory | ActionItemCategory | |
| allottedHours | Float | |
| assignee | EventVolunteer | |
| assigneeGroup | EventVolunteerGroup | |
| assigneeType | String! | |
| assigneeUser | User | |
| assigner | User | |
| assignmentDate | Date! | |
| completionDate | Date! | |
| createdAt | Date! | |
| creator | User | |
| dueDate | Date! | |
| event | Event | |
| isCompleted | Boolean! | |
| postCompletionNotes | String | |
| preCompletionNotes | String | |
| updatedAt | Date! | |
| Field | Type | Description |
|-------|------|-------------|
| _id | ID! | Unique identifier for the action item |
| actionItemCategory | ActionItemCategory | Category classification for the action item |
| allottedHours | Float | Estimated time in hours to complete the action item |
| assignee | EventVolunteer | The volunteer assigned to this action item |
| assigneeGroup | EventVolunteerGroup | The volunteer group assigned to this action item |
| assigneeType | String! | Type of assignee (individual or group) |
| assigneeUser | User | The user assigned to this action item |
| assigner | User | User who assigned this action item |
| assignmentDate | Date! | Date when the action item was assigned |
| completionDate | Date! | Date when the action item was completed |
| createdAt | Date! | Timestamp when the action item was created |
| creator | User | User who created this action item |
| dueDate | Date! | Deadline for completing the action item |
| event | Event | Associated event for this action item |
| isCompleted | Boolean! | Flag indicating if the action item is completed |
| postCompletionNotes | String | Notes added after completing the action item |
| preCompletionNotes | String | Notes added before completing the action item |
| updatedAt | Date! | Timestamp when the action item was last updated |

@Suyash878
Copy link
Contributor Author

Coderabbit is suggesting we do not use husky pre-commit hook for this since it will trigger a pipeline failure and therefore perform this via CI/CD.

@Suyash878
Copy link
Contributor Author

I am not quite sure why the npm ci is failing in the workflow, I tried it running locally and it worked fine.

@palisadoes
Copy link
Contributor

palisadoes commented Jan 13, 2025

@Suyash878

This can be done much more simply.

  1. We already have this in package.json
    1. "generate:graphql-schema": "get-graphql-schema http://localhost:4000/graphql --json > docs/schema.json",
  2. In husky, why don't you:
    1. start the app
    2. run the command
    3. stop the app
  3. You'll need to update the JSON location.

@palisadoes
Copy link
Contributor

palisadoes commented Jan 13, 2025

  1. Similarly, couldn't this be done as part of a GitHub action?
    1. start the app
    2. run npm run generate:graphql-schema
    3. add the changes to a commit and push
      1. https://github.com/actions/checkout#push-a-commit-using-the-built-in-token
    4. Stop the app
  2. The GitHub action is greatly preferred as it will be consistent

@palisadoes
Copy link
Contributor

palisadoes commented Jan 18, 2025

  1. Have you managed to make any progress on this?
  2. @xoldd may be able to assist

@Suyash878
Copy link
Contributor Author

yes I am working on this, And for the get-graphql-schema http://localhost:4000/graphql --json > docs/schema.json , we will have to start the server first and then only it will be able to get the schema.

@palisadoes
Copy link
Contributor

  1. Will that be practical to start the app with every commit?
  2. How could we do it to be less intrusive? We tried using the PR process but can't do it due to branch protection rules.
  3. @vasujain275 Do you think we could do this on the cloud instance running a localhost only version of the develop-postgres branch?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
.husky/pre-commit (1)

13-19: ⚠️ Potential issue

Remove documentation generation from pre-commit hook.

The documentation generation commands are causing pipeline failures due to unauthorized file modifications. This is a duplicate of the previous review comment.

As discussed in the PR:

  1. Move schema generation to CI/CD pipeline
  2. Use existing commands in package.json
  3. Consider implementing as a GitHub action

This will:

  • Prevent pipeline failures
  • Ensure consistent documentation
  • Avoid blocking developer workflows
🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Unauthorized file modification or deletion attempt

🧹 Nitpick comments (1)
.husky/pre-commit (1)

Line range hint 1-24: Architectural recommendation for schema generation.

Based on the PR discussion, here's a recommended approach:

  1. Create a GitHub Action that:
    • Runs on the develop-postgres branch
    • Starts the server
    • Generates schema documentation
    • Commits and pushes changes
    • Stops the server

Would you like me to help create a GitHub Action workflow for this automation?

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Unauthorized file modification or deletion attempt

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 704cca4 and 20efc77.

📒 Files selected for processing (1)
  • .husky/pre-commit (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: PR Workflow
.husky/pre-commit

[error] Unauthorized file modification or deletion attempt

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (typescript)

Comment on lines 6 to 10
npm run dev &
SERVER_PID=$!

# Checks code for typescript type errors and throws errors if found.
npm run typecheck
# Wait for server to be ready (adjust sleep time as needed)
sleep 10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove server management from pre-commit hook.

Starting a server in a pre-commit hook introduces several risks:

  • Race conditions if multiple developers commit simultaneously
  • Potential port conflicts if a server is already running
  • Unreliable sleep-based timing
  • Resource overhead for every commit

Based on the PR discussion with @palisadoes, this should be moved to a CI/CD workflow instead.

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Unauthorized file modification or deletion attempt

Comment on lines 21 to 22
# Kill the background server process
kill $SERVER_PID
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove server cleanup code.

The server cleanup is tightly coupled with the server startup, which should be removed from the pre-commit hook.

If the server fails to start or the script exits prematurely, this could kill unrelated processes or leave orphaned processes.

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Unauthorized file modification or deletion attempt

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (3)
.husky/pre-commit (3)

6-10: ⚠️ Potential issue

Remove server management from pre-commit hook.

Starting a server in a pre-commit hook introduces several risks:

  • Race conditions if multiple developers commit simultaneously
  • Port conflicts if a server is already running
  • Unreliable sleep-based timing
  • Resource overhead for every commit

Based on the PR discussion with @palisadoes, this should be moved to a CI/CD workflow instead.

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Unauthorized modification or deletion of protected file '.husky/pre-commit'. This file is restricted from changes.


18-19: ⚠️ Potential issue

Remove documentation generation from pre-commit hook.

The GraphQL documentation generation commands modify git-tracked files, causing pipeline failures with "Unauthorized file modification" errors. Documentation generation should be moved to the CI/CD pipeline to:

  • Prevent commit failures due to unauthorized file modifications
  • Ensure consistent documentation across all branches
  • Avoid race conditions during concurrent commits
🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Unauthorized modification or deletion of protected file '.husky/pre-commit'. This file is restricted from changes.


21-21: ⚠️ Potential issue

Remove server cleanup code.

The server cleanup is tightly coupled with the server startup, which should be removed from the pre-commit hook. If the server fails to start or the script exits prematurely, this could kill unrelated processes or leave orphaned processes.

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Unauthorized modification or deletion of protected file '.husky/pre-commit'. This file is restricted from changes.

🧹 Nitpick comments (1)
.husky/pre-commit (1)

6-21: Move schema generation to GitHub Actions workflow.

Based on the PR discussion, here's a recommended approach:

  1. Create a new GitHub Action workflow that:
    • Starts the server
    • Waits for server health check
    • Generates schema and documentation
    • Commits and pushes changes if needed
    • Stops the server
  2. Remove all server management and documentation generation from pre-commit hook
  3. Keep only local development concerns in pre-commit (linting, formatting, type checking)

This approach will:

  • Ensure reliable and consistent schema generation
  • Prevent pipeline failures
  • Reduce complexity in local development workflow

Would you like me to help create this GitHub Action workflow?

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] Unauthorized modification or deletion of protected file '.husky/pre-commit'. This file is restricted from changes.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20efc77 and 033db80.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • .husky/pre-commit (1 hunks)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🪛 GitHub Actions: PR Workflow
.husky/pre-commit

[error] Unauthorized modification or deletion of protected file '.husky/pre-commit'. This file is restricted from changes.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (typescript)

@palisadoes
Copy link
Contributor

Please work with @gautam-divyanshu and @tasneemkoushar to get this PR merged.

@Suyash878
Copy link
Contributor Author

Sure I would like to collaborate with them to come up with a better approach, however I have been facing this issue with npm ci it says my package files are out of sync but I have tried numerous times and it did not cause any issues in my local, I still do not understand why they are failing in this workflow.

@gautam-divyanshu
Copy link
Member

@Suyash878 npm error npm ci can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with npm install before continuing.

@Suyash878
Copy link
Contributor Author

Suyash878 commented Jan 22, 2025

Do you think I should proceed with this as a github action?
`name: Generate GraphQL Schema
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
generate-schema:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Required for pushing changes back
token: ${{ secrets.GITHUB_TOKEN }}

  - name: Setup Node.js
    uses: actions/setup-node@v4
    with:
      node-version: '18'
      cache: 'npm'

  - name: Install dependencies
    run: npm ci

  - name: Start application
    run: |
      npm run start & 
      echo "Waiting for server to start..."
      sleep 30  # Adjust this value based on your app's startup time

  - name: Generate GraphQL schema
    run: |
      npm run generate:graphql-schema
      npm run generate:graphql-markdown

  - name: Commit and push if changes exist
    run: |
      git config --global user.name 'GitHub Action'
      git config --global user.email '[email protected]'
      
      if [[ -n "$(git status --porcelain)" ]]; then
        git add docs/schema.json docs/Schema.md
        git commit -m "chore: update GraphQL schema"
        git push
      else
        echo "No changes to commit"
      fi

  - name: Stop application
    run: |
      pkill node || true`

@Suyash878
Copy link
Contributor Author

The best way to go about this issue is to use CI/CD as it is a consistent and reliable in comparison to husky's pre-commit approach which has a lot of caveats to it.
For that we will need to host a local server somewhere on a cloud platform and then based on that we can run out npm generate:schema command to fetch the schema and produce the required files.

@Suyash878
Copy link
Contributor Author

Comparison of the Two Options

Feature Option 1: Local Server Option 2: Docker Server
Ease of Setup Easier, no extra tools required Requires Docker knowledge
Environment Isolation Depends on test config Fully isolated
Startup Time Faster Slower (build + container start)
Reproducibility May vary based on CI environment Fully consistent
Dependencies Relies on host setup (Node.js, etc.) Self-contained

These are two simple ways in which we can start the local server for schema generation, I feel we should prefer using localhost as it is faster less heavier compared to the docker approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants