-
Notifications
You must be signed in to change notification settings - Fork 67
[FEAT] (compile-time error): prevent stub entities from having fields beyond their key fields #2445
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
base: master
Are you sure you want to change the base?
[FEAT] (compile-time error): prevent stub entities from having fields beyond their key fields #2445
Conversation
…yond their key fields
|
|
There was a problem hiding this 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:
- Valid scenario where an entity is defined with just a key field
- Valid scenario where an entity is defined with key field and other additional fields with a resolve reference function
- 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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the formatting.
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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra empty lines.
|
||
validateFieldsAgainstKeys(keyFields, entityAnnotation.location()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
validateFieldsAgainstKeys(keyFields, entityAnnotation.location()); | |
validateFieldsAgainstKeys(keyFields, entityAnnotation.location()); |
|
||
if (keyFields == null || keyFields.isEmpty()) { | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
private void validateFieldsAgainstKeys(List<String> keyFields, Location location) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduce compile-time validation to ensure stub entities only contain fields
defined in their key fields list.
ServiceValidator.java
to check record fields against key fieldsPurpose
Fixes: #4816
Examples
Checklist
commons
package changes (if there are any, please update the GraphQL version in GraphQL tools and Ballerina dev tools)compiler
package changes (if there are any, please update the GraphQL version in Ballerina dev tools)