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

Strawberry Shake query with scalar `AnyType` fails.

Open nightroman opened this issue 4 years ago • 4 comments
trafficstars

Strawberry Shake query with scalar AnyType fails.

  • ref: Slack
  • Strawberry Shake: 11.2.0-preview.24
  • Windows 10

The schema has the scalar Map. One of object types has the field counts: Map!. The GraphQL service sends some JSON object as counts.

We use this service in our gateway scenario and add the scalar Map as AnyType:

.AddType(new AnyType("Map"))
...
.ConfigureSchema(x => x.AddType(new AnyType("Map"))
...

The result gateway service with such a schema and data works fine with Banana Cake Pop. BCP successfully gets and displays the result counts as an object with keys and values.

But in Strawberry Shake this scenario does not work.

(1) The generated type is public global::System.String Counts { get; }. String does not look ideal for this kind data, a set of key / value pairs. Perhaps it's work in progress and it's supposed to get results as JSON strings. But this is not working in any case.

(2) On running a query with counts Strawberry Shake generated code fails with the error

The requested operation requires an element of type 'String', but the target element has type 'Object'.

nightroman avatar Apr 19 '21 06:04 nightroman

I'm having this issue as well. I'll just mention JSONObject here, because that name is often used for this GraphQL type.

There needs to be a way for field serializers to either access the JSONElement or the raw JSON string.

Right now, the following is generated:

return _jSONObjectParser.Parse(obj.Value.GetString()!);

This needs to be either:

return _jSONObjectParser.Parse(obj.Value!);
return _jSONObjectParser.Parse(obj.Value.GetRawText()!);

I need this functionality ASAP so I am going to make an attempt at this in a PR.

jorrit avatar Jun 01 '21 14:06 jorrit

This one is now implemented.

michaelstaib avatar Jun 14 '21 21:06 michaelstaib

i had same fail but i got next message:

The requested operation requires an element of type 'String', but the target element has type 'Number'.

timeshift92 avatar Aug 15 '21 13:08 timeshift92

@michaelstaib This is not fixed for me in StrawberryShake 12.11.1, was it merged into another version? Only difference for me is the type is called JSON

geometrikal avatar Jun 28 '22 06:06 geometrikal

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 Oct 26 '22 12:10 stale[bot]

Looks like this is still an issue in 12.15.2? Failing to deserialize a JSON object with "Exception = {"The requested operation requires an element of type 'String', but the target element has type 'Object'."}"

Villawhatever avatar Nov 12 '22 08:11 Villawhatever

This is now fixed in the newest version 12 and preview 13

PascalSenn avatar Jan 02 '23 17:01 PascalSenn