-
-
Notifications
You must be signed in to change notification settings - Fork 744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom scalar for JObject is not parsed correctly #1051
Comments
So, the What is possible is to define a json string .... {
"input": "{ ... }"
}
So while you can have complex scalars they cannot build structured data. This is a bigger problem for output types where you could not properly write selections on those types. There will be some more clarification on this with the future spec that all custom scalars have to serialize to the built-in ones. But what should work is having a JSON string. |
Ah ... just forgot it... the GraphQL spec can be found here: |
Apollo server supports JSON as scalar type. Sometimes it’s a good trade off when you don’t want to bother with types. For example, GeoJson spec says that Point can be described as:
So, in this case client doesn’t bother about selecting fields for the Point as the shape of Point is strictly defined and there is no sense to select one field but not another. There are also other cases like this |
Json string looks like a hack. Especially from client side (e.g., js in browser) update: also it will be hard to specify it fir example in graphql playground |
|
Let me look into the Apollo implementation. I will also discuss that with some other people to get their thoughts on this one. If there is a way to implement it without violating the spec we will do it. |
Also, as a side note. One thing why it won't work is that you use JObject as a backing type whereas we are not using Json.net for parsing variables and requests. We getting rid of Json.net and have only I think two places where we still use it. The literal would need to be a But in any case, this will make your GraphQL server non-spec compliant and might have an impact on tooling. I will give you feedback on that too. |
So, we will build in a proper any type with 10.1 |
I have talked to Ivan about this (the graphql-js maintainer) and it is not forbidding to do that. I had interpreted some sections of the spec differently but I was wrong here. We will create the new AnyType so that it really can be anything (object, int, float, string, bool). I will describe the AnyType in more detail in a separate issue that I will link to this issue. We will put this in 10.1.0 so expect it in the next two weeks. |
Awesome! Thanks for the amazing support! Keep on doing this great project! |
I Have now implemented the type and will release a first preview ... 10.2.0-preview.1. I still need to write mire tests for this one. If you want to have a look how this type works head over to the unit tests here: |
I still have to smooth out the implementation so feedback is appreciated. Important we are not using json.net here. This is done by our own parser. So there are now JObjects... Since GraphQL is transport agnostic there should be no json type. So the any type can be anything. You can also get as anything. The type is in it serialized state and IReadOnlyDictionary<string, object> or IReadOnlyList or a scalar. If we cannot serialize the type you can register type converters like for any type and then intercept conversion. |
We have merged it now and will close this issue... the new version is now in preview.2. |
Thanks a lot for your help but how i can define this ANY type in code first ? there's only an example of "SCHEMA" first : https://hotchocolate.io/docs/custom-scalar-types#any-type I have read that
but actually i have an Input object called "GetListQueryInput" and it has a property called "query" of type object but i am getting an error : |
I think you can find examples in tests for now |
@stalniy thanks a lot for your reply however the link for test is invalid, it gives me 404 error |
For posterity, the tests have moved here and if you actually want to return a serialized |
Describe the bug
I want to write a custom scalar for the JSON object of any shape (I know I know about strong typing and GraphQL but...) and when I do this hotchocolate incorrectly parses the input object.
All works fine if you use this scalar type as mutation argument but doesn't work when it's a field of InputObjectType.
To Reproduce
Steps to reproduce the behavior:
Scalar Implementation
Input Object Type
Mutation
Variables:
Expected behavior
Custom scalar is correctly parsed into
JObject
Actual behavior:
null
is returnedAdditional context
.NET Core 2.2
hotchocolate version 11.0.0-preview.2
The text was updated successfully, but these errors were encountered: