-
-
Notifications
You must be signed in to change notification settings - Fork 749
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
Configuration of AnyType #1303
Comments
There is one important aspect here. Any is not JSON. It is a GraphQL literal. So you do not get the json string. You have a GraphQL literal which is internally represented by an If we would allow If you want to have this than this is a field validation not a type requirement. Each type has to have one defined behavior throughout the schema. You can however with all types register them under a different name making them a different type. I do not yet see why we would need a factory for that. The new SchemaBuilder.New()
.AddType(new UuidType(name: "MySpecialType", format: 'D')
....
.Create() While this all are technicalities I also have may doubts about the value of this. The downside to your approach with the any type is that the any type is not anything anymore. It now has a fixed shape but does not give the GraphQL compilers, generators and tools any hint about its structure. From a usage standpoint this might not be ideal and takes away the advantages of GraphQL being predictable and strongly typed. Moreover, if you want to go down the route of a scalar in this case, wouldn't it be better to have a very specific scalar implementation for that. You do not need all the handling of all the possible type cases of any and the scalar would have a fixed representation in .NET which would save a lot of type conversions. Also for you to consider is that with GraphQL 2020 there will be a new |
The purpose of So that, I don't need to duplicate the same logic in my custom scalar implementation but instead want to pass just a validation logic. However I understand your position as well. So, it's up to you to decide whether to implement it or close. You do amazing work man, I like this project! :) |
I've recently run into this myself, also working with GeoJSON (I'm using the GeoJSON.NET library). The best way I've come up with to solve this was by implementing my own scalar type, which unfortunately resulted in a bunch of code duplication (including a couple types that are internal to HC). I would have preferred to have simply inherited and overridden What I ended up doing was creating a new generic abstract class on top of scalar that borrows all the relevant bits from
So the implementation becomes really slim, like this:
This solution is primarily concerned with output at this time, so I've essentially skipped over the deserialization bits for now. Anyhow, hope this helps someone. |
@Confusingboat just as an info, we have started work on integrating GeoJSON into Hot Chocolate ... on our slack channel is a channel called spatial in which the discussion are also we have an issues tracking the progress: It would be great if you chime into the discussion. |
Is your feature request related to a problem? Please describe.
Currently
AnyType
accepts any JSON value, for some cases I need to restrictAnyType
to accept only specific shape of the JSON. For example, GeoJSON specification says that a geo point is a JSON object with 2 propertiestype
andcoordinates
This is atomic thing, so I don't want to define it as a separate GraphQL type and instead I see it as a ScalarType (I can't display information on map having only
coordinates
or onlytype
it just doesn't make sense for me).Describe the solution you'd like
I see 2 ways to achieve this.
AnyType
and restrict it but then it breaks Liskov substitution principle and it's not goodAnyType
. In this case, it'd be good to have a factory function forAnyType
:The text was updated successfully, but these errors were encountered: