-
Notifications
You must be signed in to change notification settings - Fork 273
Description
Problem statement
A table or a view in SQL may have special characters such as space for column names. If the developer does not provide explicit fieldmappings under the entity in config, then the field names are derived as is from column names. However special characters such as spaces are not supported in GraphQL names(acceptable characters per spec) and while DAB starts up fine, the GraphQL calls fail due to invalid schema. Specifying fieldmappings for applicable entities may be cumbersome process if numerous table names have special characters. Note that the issue does not impact REST endpoint/swagger as special characters for entity fields are escaped and accepted.
See related discussion on #1528, #692 and #1479.
There are several ways we can look to address the issue for GraphQL involved if no field mappings provided.
1. Throw error upfront
- If GraphQL or GraphQL + REST is enabled in DAB, then during provisioning DAB will verify that column names are valid to be used as GraphQL field names.
- If invalid, then throw fatal error during startup/config enablement and provide suggestion to use fieldmappings in config.
- If GraphQL is not enabled, then this behavior does not apply
2. Introduce config option sanitize-fields-for-graphql
standardize-fieldnames
with boolean type defaulting to false.
sanitize-fields-for-graphql
This approach looks to sanitize the field names only when invalid and avoid impacting REST by default.
- If GraphQL or GraphQL + REST is enabled in DAB, then during provisioning DAB will verify that column names are valid to be used as GraphQL field names based on below conditions.
- If standardize-fieldnames= false and invalid name, then throw error upfront similar to previous approach indicating that valid field names could not be derived and to specify fieldmappings in config.
- If standardize-fieldnames=true and invalid name, then sanitize the column names to field names using this styling convention (already being leveraged in DAB for query names for relations).
- Given GraphQL names can only be in English chars, if the name sanitization results in no chars left, then throw error indicating that valid field names could not be derived and to use fieldmappings.
- If standardize-fieldnames=true and valid name, no sanitization will occur even if the derived field name does not follow styling convention.
- Alternately we can choose to always sanitize all field names per the convention even if column names are valid for GraphQL naming but not per the convention.
- Note that the sanitized field names will be used for both GraphQL and REST endpoint for parity across both endpoints and to avoid introducing complexity with maintaining separate mappings
- Since this option would impact both GraphQL and REST, we have several locations where we can introduce this option
"runtime": { "standardize-fieldnames": true, "graphql": { "enabled": true }, "rest": { .... }
3. Sanitize column names to field names whenever invalid characters present with no config option
- In this approach, DAB will verify that column names are valid to be used as GraphQL field names.
- If invalid, then sanitize column names to field names using the previously stated convention
- These sanitized field names will also be used for REST endpoint for parity. This will be breaking change but we can minimize the impact by applying this policy only when GraphQL endpoint is enabled while REST may or may not be enabled.
I propose we go with Option 2 to avoid breaking changes for customers who have REST enabled. The documentation can clarify the impact of enabling this option.
Looking forward to feedback and alternative proposals if any.