-
-
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
[Discussion] Spatial data with hc #1650
Comments
Is there no proper solution to this right now or why did it get the HC-11.x.x tag? :) |
The tag is just backlog tag. HC-11.0.0 => current work backlog, HC => HC-11.x.x => later |
https://hasura.io/docs/1.0/graphql/manual/queries/query-filters.html#postgis-spatial-relationship-operators-st-contains-st-crosses-etc looks like a nice implementation with postgis |
@John0x we have opened a discussion on slack #spatial |
closing in favor of: #1878 |
Summary
Hey, as discussed before on slack with @PascalSenn and @michaelstaib, I'm kinda struggling with GeoJSON and hc right now.
My current project has to work with a lot of geo data, therefore I want it to be as comfortable as possible. The Geo data is stored in a PostgreSQL database using Postgis. For the interaction between my api and the database I'm using ef core with npgsql. They recommend using the NetTopologySuite to work with spatial data, see:
https://www.npgsql.org/efcore/mapping/nts.html
NetTopologySuite has a base type, called Geometry. It also has more specific types like Point and LineString which extend the Geometry class. The current standard for geo data transportation seems to be GeoJSON, which seems to work pretty well with NetTopologySuite. There even is an existing Json transformer for transforming between NetTopologySuite and GeoJSON: https://github.com/NetTopologySuite/NetTopologySuite.IO.GeoJSON
What's the best way to work with data like that using hc?
I tried different solutions (see attempts down below) and feel kinda stuck right now.
Slack discussion:
Related issues:
Attempt 1: Custom Scalar
Having read about the scalar implementation with hc from the docs I wanted to try that first.
I want to use the NetTopologySuite types like it's something that hc can handle. Being able to just have a Point for an argument type is quite nice. Something like this:
Scalars can be problematic for the tooling, as pointed out by @PascalSenn on slack, but they seem to be the most comfortable to use, since I can just bind them to the Point class (
.BindClrType<Point, GeoScalar>()
).My implementation: https://github.com/John0x/hotchocolate-geojson-test
It's using the aforementioned JsonTransformer but it feels really hacky :/
The input works but I cannot output a json structure. I could probably just return it as a string, but that feels way too hacky.
Attempt 2: Input and output objects and manual conversion
It would be nice to use GeoJSON, since it's used by a lot of people but it's also okayish to not use it, if it's too inconvenient for GraphQL. The idea for this one would be to have properly typed input and output objects for each specific spatial type (like Point and LineString) and then do the conversion manually using extension methods or something else.
Like this:
This would probably work just fine and be the cleanest from the perspective of someone consuming the API, but it's more overhead for the development team.
Conclusion
I'm not sure 😄
It would be nice to have a mix between attempt 1 and 2. Being able to use BindClrType to bind something like a DTO to a CLR Type, which takes care of the conversion between the GraphQL representation and the real class.
Or is there already something like that and I just didn't see it?
The text was updated successfully, but these errors were encountered: