graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Stitching with scoped field array variables not working

Open lken0815 opened this issue 4 years ago • 5 comments

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

lken0815 avatar Jan 20 '21 16:01 lken0815

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.

michaelstaib avatar Jan 21 '21 07:01 michaelstaib

+1

Hantsch avatar Jan 21 '21 08:01 Hantsch

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.

anthony-keller avatar Mar 30 '22 09:03 anthony-keller

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.

stale[bot] avatar May 29 '22 10:05 stale[bot]

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,

DuCNiKo avatar Jul 05 '22 14:07 DuCNiKo

+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.

JEMcAdam avatar Oct 10 '22 08:10 JEMcAdam

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

michaelstaib avatar Mar 08 '23 20:03 michaelstaib

Since fusion is not coming any time soon, any possibility that this gets fixed before then?

EricStG avatar Mar 30 '23 19:03 EricStG