Skip to content

chore: add lint rule for Node type#116

Merged
ddebrunner merged 2 commits intomainfrom
lint-Node
Jul 16, 2025
Merged

chore: add lint rule for Node type#116
ddebrunner merged 2 commits intomainfrom
lint-Node

Conversation

@ddebrunner
Copy link
Contributor

@ddebrunner ddebrunner commented Jul 15, 2025

Add Node Interface Linting Rule

Summary

This PR adds a new GraphQL linting rule that enforces the Node interface to be properly defined as an interface type with exactly one field: id: ID!.

Changes Made

New Linting Rule

  • Rule Name: node-interface-structure
  • Severity: Error
  • Purpose: Ensures Node interface follows the Relay specification

Rule Behavior

The rule checks for the following conditions:

  1. Node must be an interface, not a type: Reports error if type Node { ... } is found
  2. Exactly one field: Node interface must have exactly one field
  3. Correct field name: The field must be named id
  4. Correct field type: The field must be of type ID! (non-nullable ID)

Implementation Details

  • Added ObjectTypeDefinition visitor to detect when Node is incorrectly defined as a type
  • Enhanced InterfaceTypeDefinition visitor to validate Node interface structure
  • Integrated with existing configuration system (enabled by default)
  • Added comprehensive test coverage

Test Coverage

Added 5 new test cases:

  • ✅ Detects Node interface with wrong field name
  • ✅ Detects Node interface with wrong field type
  • ✅ Accepts correct Node interface (interface Node { id: ID! })
  • ✅ Does not affect other interfaces
  • ✅ Detects Node defined as object type instead of interface

Configuration

The rule is enabled by default and can be disabled via VS Code settings:

{
  "stepzen.graphqlLintRules": {
    "node-interface-structure": false
  }
}

Testing

  • All existing GraphQL linter tests continue to pass (39 tests)
  • New Node interface tests pass (5 tests)
  • Configuration tests updated to include the new rule
  • Total: 44 GraphQL linter tests passing

Impact

This enhancement helps developers maintain GraphQL schemas that conform to the Relay specification for Node interfaces, improving schema consistency and reducing potential runtime errors.

Files Changed

  • src/services/graphqlLinter.ts - Added Node interface rule implementation
  • src/test/unit/services/graphqlLinter.test.ts - Added comprehensive test coverage
  • src/test/unit/graphqlLinter.test.ts - Updated configuration test

@ddebrunner ddebrunner marked this pull request as ready for review July 15, 2025 19:44
Copy link
Contributor

@carloseberhardt carloseberhardt left a comment

Choose a reason for hiding this comment

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

gtg

@ddebrunner ddebrunner merged commit f979c3e into main Jul 16, 2025
1 check passed
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.

2 participants