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

Added duplicate check for ObjectTypeExtensionNode #316

Merged
merged 3 commits into from
Oct 2, 2024

Conversation

mgupta83
Copy link
Contributor

@mgupta83 mgupta83 commented Oct 1, 2024

This pull request fixes a duplicate check issue for the ObjectTypeExtensionNode. Previously, the code was not properly checking for duplicates when processing extension types. This PR adds a new function processExtensionTypeNode to handle extension types and ensures that duplicate fields are properly detected.

Summary by Sourcery

Fix the issue of not detecting duplicate fields in ObjectTypeExtensionNode by introducing a new function to process extension types and updating the logic to check for duplicates.

Bug Fixes:

  • Fix duplicate check for ObjectTypeExtensionNode by adding a new function to handle extension types and ensure duplicate fields are detected.

@mgupta83 mgupta83 requested a review from gidich as a code owner October 1, 2024 21:01
Copy link
Contributor

sourcery-ai bot commented Oct 1, 2024

Reviewer's Guide by Sourcery

This pull request adds functionality to check for duplicate fields in ObjectTypeExtensionNode, enhancing the existing duplicate check system for GraphQL schema definitions. The changes primarily involve adding new functions to handle extension types and modifying existing functions to accommodate these changes.

Class diagram for updated duplicate check system

classDiagram
    class AllowedOutputTypeDefinitionNode {
        <<type>>
    }
    class AllowedInputTypeDefinitionNode {
        <<type>>
    }
    class AllowedExtensionTypeDefinitionNode {
        <<type>>
    }
    class processExtensionTypeNode {
        +processExtensionTypeNode(outputTypeNode: AllowedExtensionTypeDefinitionNode, processedNodes: string[], errors: string[])
    }
    class recursiveFunctionToFindExtensionFieldDefinitions {
        +recursiveFunctionToFindExtensionFieldDefinitions(node: AllowedExtensionTypeDefinitionNode | FieldDefinitionNode, fieldDefinitions: FieldDefinitionNode[]): FieldDefinitionNode[]
    }
    class processOutputTypeNode {
        +processOutputTypeNode(outputTypeNode: AllowedOutputTypeDefinitionNode, processedNodes: string[], errors: string[])
    }
    class checkForDuplicateFieldsInOutputTypeNode {
        +checkForDuplicateFieldsInOutputTypeNode(outputTypeNode: AllowedOutputTypeDefinitionNode, errors: string[])
    }
    class recursiveFunctionToFindOutputFieldDefinitions {
        +recursiveFunctionToFindOutputFieldDefinitions(node: AllowedOutputTypeDefinitionNode | FieldDefinitionNode, fieldDefinitions: FieldDefinitionNode[]): FieldDefinitionNode[]
    }
    class processInputTypeNode {
        +processInputTypeNode(inputTypeNode: AllowedInputTypeDefinitionNode, processedNodes: string[], errors: string[])
    }
    class checkForDuplicateFieldsInInputTypeNode {
        +checkForDuplicateFieldsInInputTypeNode(inputTypeNode: AllowedInputTypeDefinitionNode, errors: string[])
    }
    class recursiveFunctionToFindInputValueDefinitions {
        +recursiveFunctionToFindInputValueDefinitions(node: AllowedInputTypeDefinitionNode | InputValueDefinitionNode, inputValueDefinitions: InputValueDefinitionNode[]): InputValueDefinitionNode[]
    }

    AllowedExtensionTypeDefinitionNode --> processExtensionTypeNode
    processExtensionTypeNode --> recursiveFunctionToFindExtensionFieldDefinitions
    AllowedOutputTypeDefinitionNode --> processOutputTypeNode
    processOutputTypeNode --> checkForDuplicateFieldsInOutputTypeNode
    checkForDuplicateFieldsInOutputTypeNode --> recursiveFunctionToFindOutputFieldDefinitions
    AllowedInputTypeDefinitionNode --> processInputTypeNode
    processInputTypeNode --> checkForDuplicateFieldsInInputTypeNode
    checkForDuplicateFieldsInInputTypeNode --> recursiveFunctionToFindInputValueDefinitions
Loading

File-Level Changes

Change Details Files
Added support for checking duplicates in ObjectTypeExtensionNode
  • Introduced new type AllowedExtensionTypeDefinitionNode for ObjectTypeExtensionNode
  • Created new function processExtensionTypeNode to handle extension types
  • Implemented recursiveFunctionToFindExtensionFieldDefinitions to traverse extension fields
  • Updated traverseDefinitions function to process ObjectTypeExtension nodes
  • Added ObjectTypeExtension to the processedNodesMap in the main execution block
data-access/src/functions/http-graphql/schema/builder/check-duplicate-types.ts
Refactored existing type definitions and function signatures
  • Renamed AllowedOutputTypeDefinitionNodes to AllowedOutputTypeDefinitionNode (singular)
  • Renamed AllowedInputTypeDefinitionNodes to AllowedInputTypeDefinitionNode (singular)
  • Updated function signatures to use the new type names
  • Imported ObjectTypeExtensionNode from graphql package
data-access/src/functions/http-graphql/schema/builder/check-duplicate-types.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@mgupta83 mgupta83 linked an issue Oct 1, 2024 that may be closed by this pull request
1 task
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @mgupta83 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider refactoring the process*TypeNode functions to reduce code duplication. There's significant overlap in functionality between processExtensionTypeNode, processOutputTypeNode, and processInputTypeNode.
  • The recursive functions for finding field definitions (recursiveFunctionToFind*FieldDefinitions) could potentially be generalized into a single function that works across different node types, improving code maintainability.
  • Consider standardizing the use of processedNodesMap. Currently, it's treated inconsistently as both a Map of arrays and a Map of Sets. Choosing one approach and sticking to it would improve code consistency.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Review instructions: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@mgupta83 mgupta83 merged commit fc6fb59 into main Oct 2, 2024
7 checks passed
@mgupta83 mgupta83 deleted the mg-graphql-op-dup-check branch October 2, 2024 23:44
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.

Work Item: Validate Graphql Schema before running codegen - 2
1 participant