Stitching with scoped field array variables not working
When stitching a service with an array of strings or ints as parameter the api returns this error
String cannot parse the given value of type HotChocolate.Language.StringValueNode.
To Reproduce I created a small example project containing a gateway and two services [User, Books]
https://github.com/lken0815/GraphQL-Demo
The User service returns a User type which contains a string array of OwnedBookIds
The Gateway extends the User type with a list of books which are fetched form the book service and the bookIds as parameter
extend type Query {
my: User! @delegate(schema: "users", path: "user(userId: \"Test-User1\")")
}
extend type User {
books: [Book!] @delegate(schema: "books", path: "books(bookIds: $fields:ownedBookIds)") # ownedBookIds is an array of strings
bookNumbers: [Book!] @delegate(schema: "books", path: "booksByNumber(numbers: $fields:testNumbers)") # testNumbers is an array of ints
}
If you now try to fetch data with the following GraphQl querry:
{
my {
books {
bookId
bookTitle
}
bookNumbers {
bookId
bookTitle
}
}
}
you get the following result
{
"errors": [
{
"message": "Int cannot parse the given value of type `HotChocolate.Language.IntValueNode`."
},
{
"message": "String cannot parse the given value of type `HotChocolate.Language.StringValueNode`."
}
],
"data": {
"my": {
"books": null,
"bookNumbers": null
}
}
}
I was able to fix this issue by adding these linse to ScalarType~2.cs:
84 public sealed override IValueNode ParseValue(object? runtimeValue)
85 {
...
90
91 if (runtimeValue is IValueNode node)
92 {
93 return node;
94 }
95
...
104 }
This fixes the issue for both, string- and int- arrays, however i don't know if that is the right approach to this problem?
Expected behavior The gateway service forwards the $field variable as array to the dowstream server and extends the Type by its result
Desktop (please complete the following information):
- OS: Windows 10 64bit
- Version: 11.08
Hi,
thanks for detailing this issue.
The ParseValue method demands a runtime value. IValueNode is not a runtime value and it should be used in this case. The stitching layer aims to not parse these values but keep them in their raw state. The issue here is that they are parsed in the first place.
+1
I'm getting this issue when stitching to a remote schema. It doesn't seem to be a problem when stitching to a local schema.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi @PascalSenn @michaelstaib, I'm still using the Stitching 12.7.0 and I still have the issue... Except modifying the source code, have you found a Workaround for this issue ?
Regards,
+1. I've recently been attempting to implement a fairly basic gateway API with remote schemas and this bug, along with 1920, almost forced me to discard the idea of HotChocolate stitching entirely.
HotChocolate.Stitching is now in legacy mode and is replaced by HotChocolate.Fusion. I am closing this issue as we essentially froze the fusion code.
You can join the preview of Hot Chocolate Fusion now on Slack
Since fusion is not coming any time soon, any possibility that this gets fixed before then?