Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch @graphql-mesh/string-interpolation for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/@graphql-mesh/string-interpolation/cjs/interpolator.js b/node_modules/@graphql-mesh/string-interpolation/cjs/interpolator.js
index 885e9b1..333d0e3 100644
--- a/node_modules/@graphql-mesh/string-interpolation/cjs/interpolator.js
+++ b/node_modules/@graphql-mesh/string-interpolation/cjs/interpolator.js
@@ -96,7 +96,12 @@ class Interpolator {
result === '' &&
strOrEmptyStr.startsWith('{') &&
strOrEmptyStr.endsWith('}')) {
- return undefined;
+ // Only return undefined when the data value was actually missing (undefined).
+ // An explicit empty string '' is a valid value and must be preserved.
+ const rawDataValue = this.applyData(rules[0].key, data);
+ if (rawDataValue === undefined) {
+ return undefined;
+ }
}
return result;
}
diff --git a/node_modules/@graphql-mesh/string-interpolation/esm/interpolator.js b/node_modules/@graphql-mesh/string-interpolation/esm/interpolator.js
index 6a302cf..00559c9 100644
--- a/node_modules/@graphql-mesh/string-interpolation/esm/interpolator.js
+++ b/node_modules/@graphql-mesh/string-interpolation/esm/interpolator.js
@@ -92,7 +92,12 @@ export class Interpolator {
result === '' &&
strOrEmptyStr.startsWith('{') &&
strOrEmptyStr.endsWith('}')) {
- return undefined;
+ // Only return undefined when the data value was actually missing (undefined).
+ // An explicit empty string '' is a valid value and must be preserved.
+ const rawDataValue = this.applyData(rules[0].key, data);
+ if (rawDataValue === undefined) {
+ return undefined;
+ }
}
return result;
}
The current implementation treats explicit empty strings as undefined values, causing silent data loss in string interpolation.
Problem:
When a template variable resolves to an empty string and the entire interpolated value consists only of that placeholder (e.g., "{fieldName}"), the Interpolator class unconditionally returns undefined instead of the empty string itself.
Example:
Template: "{fieldName}"
Data: { fieldName: "" }
Expected Result: ""
Actual Result: undefined ❌
This breaks GraphQL queries and mutations where empty strings are legitimate and required values, resulting in unexpected undefined fields in the final output.
Solution:
The provided fix distinguishes between truly missing/undefined values and explicit empty strings by checking the raw data value before deciding to return undefined.
The fix:
- Retrieves the raw data value using
this.applyData(rules[0].key, data)
- Only returns
undefined if the raw value is actually undefined (genuinely missing)
- Preserves explicit empty strings as valid interpolated values
This ensures that empty strings are treated as legitimate values while maintaining backward compatibility for undefined/missing data.
This issue body was partially generated by patch-package.
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
@graphql-mesh/string-interpolationfor the project I'm working on.Here is the diff that solved my problem:
The current implementation treats explicit empty strings as undefined values, causing silent data loss in string interpolation.
Problem:
When a template variable resolves to an empty string and the entire interpolated value consists only of that placeholder (e.g.,
"{fieldName}"), theInterpolatorclass unconditionally returnsundefinedinstead of the empty string itself.Example:
This breaks GraphQL queries and mutations where empty strings are legitimate and required values, resulting in unexpected
undefinedfields in the final output.Solution:
The provided fix distinguishes between truly missing/undefined values and explicit empty strings by checking the raw data value before deciding to return
undefined.The fix:
this.applyData(rules[0].key, data)undefinedif the raw value is actuallyundefined(genuinely missing)This ensures that empty strings are treated as legitimate values while maintaining backward compatibility for undefined/missing data.
This issue body was partially generated by patch-package.