Skip to content

Conversation

Waqibsk
Copy link

@Waqibsk Waqibsk commented Oct 8, 2025

Introduce compile-time validation to ensure stub entities only contain fields
defined in their key fields list.

  • Add validation in ServiceValidator.java to check record fields against key fields
  • Add new diagnostic message for invalid additional fields

Purpose

Fixes: #4816

Examples

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests
  • Updated the spec
  • Checked native-image compatibility
  • No commons package changes (if there are any, please update the GraphQL version in GraphQL tools and Ballerina dev tools)
  • No compiler package changes (if there are any, please update the GraphQL version in Ballerina dev tools)

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 8, 2025

Copy link
Member

@ThisaruGuruge ThisaruGuruge left a comment

Choose a reason for hiding this comment

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

Please format the code and remove unnecessary empty lines.

You need to add tests for the fix in the compiler-plugin-tests submodule in order to validate the fix. Tests should be comprehensive, covering the following scenarios:

  1. Valid scenario where an entity is defined with just a key field
  2. Valid scenario where an entity is defined with key field and other additional fields with a resolve reference function
  3. Invalid scenario where an entity is defined with key field and other additional fields where resolve reference is not present.

@MohamedSabthar Please add if I missed anything.

INVALID_EMPTY_RECORD_INPUT_TYPE(DiagnosticMessage.ERROR_147, DiagnosticCode.GRAPHQL_147, DiagnosticSeverity.ERROR),
INVALID_MODIFICATION_OF_SERVICE_CONFIG_FIELD(DiagnosticMessage.ERROR_148, DiagnosticCode.GRAPHQL_148,
DiagnosticSeverity.ERROR),
INVALID_ENTITY_FIELD(DiagnosticMessage.ERROR_149, DiagnosticCode.GRAPHQL_149,DiagnosticSeverity.ERROR),
Copy link
Member

Choose a reason for hiding this comment

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

Check the formatting.

Suggested change
INVALID_ENTITY_FIELD(DiagnosticMessage.ERROR_149, DiagnosticCode.GRAPHQL_149,DiagnosticSeverity.ERROR),
INVALID_ENTITY_FIELD(DiagnosticMessage.ERROR_149, DiagnosticCode.GRAPHQL_149, DiagnosticSeverity.ERROR),

if (KEY.equals(fieldName)) {
validateKeyField(specificFieldNode);
keyFields = extractKeyFields(specificFieldNode);

Copy link
Member

Choose a reason for hiding this comment

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

Remove extra empty lines.

Suggested change

Comment on lines +210 to +212

validateFieldsAgainstKeys(keyFields, entityAnnotation.location());

Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Suggested change
validateFieldsAgainstKeys(keyFields, entityAnnotation.location());
validateFieldsAgainstKeys(keyFields, entityAnnotation.location());


if (keyFields == null || keyFields.isEmpty()) {
return;

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

}

private void validateFieldsAgainstKeys(List<String> keyFields, Location location) {

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

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.

Introduce a compile-time error when a stub entity contributes additional fields to a subgraph

3 participants