@graphql-mesh/string-interpolation 0.5.9 → 0.5.11-alpha-20260118224440-61f89a9c50880776828d92302448fd2f177e0e47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -87,10 +87,14 @@ class Interpolator {
87
87
  }
88
88
  return [];
89
89
  }
90
- parse(str = '', data = {}) {
90
+ parse(str, data = {}) {
91
91
  const rules = this.parseRules(str);
92
92
  if (rules && rules.length > 0) {
93
- return this.parseFromRules(str, data, rules);
93
+ const result = this.parseFromRules(str, data, rules);
94
+ if (result === '' && str.startsWith('{') && str.endsWith('}') && rules.length === 1) {
95
+ return undefined;
96
+ }
97
+ return result;
94
98
  }
95
99
  return str;
96
100
  }
@@ -100,7 +104,17 @@ class Interpolator {
100
104
  applyRule(str, rule, data = {}) {
101
105
  const dataToReplace = this.applyData(rule.key, data);
102
106
  if (dataToReplace !== undefined) {
103
- return str.replace(rule.replace, this.applyModifiers(rule.modifiers, dataToReplace, data));
107
+ const modifiedData = this.applyModifiers(rule.modifiers, dataToReplace, data);
108
+ // If the entire string is just the placeholder and the replacement is an object,
109
+ // return the object directly instead of converting to "[object Object]"
110
+ if (str === rule.replace && typeof modifiedData === 'object' && modifiedData !== null) {
111
+ return modifiedData;
112
+ }
113
+ // For objects embedded in a larger string, JSON stringify them
114
+ if (typeof modifiedData === 'object' && modifiedData !== null) {
115
+ return str.replace(rule.replace, JSON.stringify(modifiedData));
116
+ }
117
+ return str.replace(rule.replace, modifiedData);
104
118
  }
105
119
  else if (rule.alternativeText) {
106
120
  return str.replace(rule.replace, this.applyModifiers(rule.modifiers, rule.alternativeText, data));
@@ -83,10 +83,14 @@ export class Interpolator {
83
83
  }
84
84
  return [];
85
85
  }
86
- parse(str = '', data = {}) {
86
+ parse(str, data = {}) {
87
87
  const rules = this.parseRules(str);
88
88
  if (rules && rules.length > 0) {
89
- return this.parseFromRules(str, data, rules);
89
+ const result = this.parseFromRules(str, data, rules);
90
+ if (result === '' && str.startsWith('{') && str.endsWith('}') && rules.length === 1) {
91
+ return undefined;
92
+ }
93
+ return result;
90
94
  }
91
95
  return str;
92
96
  }
@@ -96,7 +100,17 @@ export class Interpolator {
96
100
  applyRule(str, rule, data = {}) {
97
101
  const dataToReplace = this.applyData(rule.key, data);
98
102
  if (dataToReplace !== undefined) {
99
- return str.replace(rule.replace, this.applyModifiers(rule.modifiers, dataToReplace, data));
103
+ const modifiedData = this.applyModifiers(rule.modifiers, dataToReplace, data);
104
+ // If the entire string is just the placeholder and the replacement is an object,
105
+ // return the object directly instead of converting to "[object Object]"
106
+ if (str === rule.replace && typeof modifiedData === 'object' && modifiedData !== null) {
107
+ return modifiedData;
108
+ }
109
+ // For objects embedded in a larger string, JSON stringify them
110
+ if (typeof modifiedData === 'object' && modifiedData !== null) {
111
+ return str.replace(rule.replace, JSON.stringify(modifiedData));
112
+ }
113
+ return str.replace(rule.replace, modifiedData);
100
114
  }
101
115
  else if (rule.alternativeText) {
102
116
  return str.replace(rule.replace, this.applyModifiers(rule.modifiers, rule.alternativeText, data));
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-mesh/string-interpolation",
3
- "version": "0.5.9",
3
+ "version": "0.5.11-alpha-20260118224440-61f89a9c50880776828d92302448fd2f177e0e47",
4
4
  "description": "Dynamic string manipulation",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
7
  "graphql": "*"
8
8
  },
9
9
  "dependencies": {
10
- "dayjs": "1.11.18",
10
+ "dayjs": "1.11.19",
11
11
  "json-pointer": "0.6.2",
12
12
  "lodash.get": "4.4.2",
13
13
  "tslib": "^2.4.0"
@@ -20,7 +20,7 @@ export class Interpolator {
20
20
  extractAfter(str: any, val: any): any;
21
21
  getAlternativeText(str: any): any;
22
22
  getModifiers(str: any): any;
23
- parse(str?: string, data?: {}): any;
23
+ parse(str: any, data?: {}): any;
24
24
  parseFromRules(str: any, data: any, rules: any): any;
25
25
  applyRule(str: any, rule: any, data?: {}): any;
26
26
  getFromAlias(key: any): any;
@@ -20,7 +20,7 @@ export class Interpolator {
20
20
  extractAfter(str: any, val: any): any;
21
21
  getAlternativeText(str: any): any;
22
22
  getModifiers(str: any): any;
23
- parse(str?: string, data?: {}): any;
23
+ parse(str: any, data?: {}): any;
24
24
  parseFromRules(str: any, data: any, rules: any): any;
25
25
  applyRule(str: any, rule: any, data?: {}): any;
26
26
  getFromAlias(key: any): any;