Open bauti-defi opened 1 year ago
Hey guys, after further debugging i was always to find and patch the bug. The problem was in the @graphql-mesh/string-interpolator
package.
Today I used patch-package to patch @graphql-mesh/string-interpolation@0.4.2
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 b1e0487..4fcdb74 100644
--- a/node_modules/@graphql-mesh/string-interpolation/cjs/interpolator.js
+++ b/node_modules/@graphql-mesh/string-interpolation/cjs/interpolator.js
@@ -99,7 +99,7 @@ class Interpolator {
}
applyRule(str, rule, data = {}) {
const dataToReplace = this.applyData(rule.key, data);
- if (dataToReplace) {
+ if (typeof dataToReplace !== 'undefined') {
return str.replace(rule.replace, this.applyModifiers(rule.modifiers, dataToReplace, data));
}
else if (rule.alternativeText) {
This issue body was partially generated by patch-package.
In my example dataToReplace
had an int value of 0
. Which is considered falsey in javascript. This causes the if(dataToReplace)
conditional to return false and not interpolate the string correctly.
My solution was to check if the values typeof
is equal to undefined
. Let me know if this solution is good enough. If so, i'd be happy to open up a PR to patch it.
Cheers.
Thanks for opening the issue! We'd love to accept a PR :)
Issue workflow progress
Progress of the issue based on the Contributor Workflow
Describe the bug
The graphql-mesh server is making requests with malformed URLs.
To Reproduce Steps to reproduce the behavior:
I cannot provide everything required to reproduce out of the box. Here is the general idea.
I have done a lot of debugging but reached a dead end that may lead into the graphql-mesh codebase.
My mesh server has a openapi-3 source handler that consumes an internal API.
It constructs the schema based on a openapi3-api.json spec. Here is a yaml formatted snippet from that spec file. This is a single http GET route.
It builds, runs and queries! But i have found an edge case which causes the above route to not work as expected.
_
example:
Making this graphql request to the mesh server:
Produces the following http request from the mesh server to the api:
GET /api/v1/nfts/0x9e9c14f909f441bbf0e7a688f7df76e133ee8873/1?chain=1 HTTP/1.1 200 11 - undici
This is perfect! No problem here.
Expected behavior
BUT, the following graphql request is the one in question:
Notice, the only difference between the former and the latter is the tokenId parameter value.
This graphql request produces the following http request from the mesh server to the api:
GET /api/v1/nfts/0x9e9c14f909f441bbf0e7a688f7df76e133ee8873/[THERE SHOULD BE A 0 HERE]?chain=1 HTTP/1.1 200 11 - undici
This http request will always fail because it does not follow the format specified by the openapi-3 spec file.
Furthermore, any requests with tokenId=0 leads to the same url malformation.
Environment:
@graphql-mesh/...
:Additional context
I may post this in the
@graphql-mesh/openapi
repo.