Apollo GraphQL swift Spatial Data

Hi @calvincestari ,
Really sorry for the late reply.

This is the graphQL Endpoint
https://dqt-geometry.azurewebsites.net/graphql/

Below is the query syntax

query a {
location(where: { id: { eq: 1 } }) {
nodes {
id
spatialData {
position {
coordinates
}
area {
coordinates
}
}
}
}
}

Without setting the headers it will work.

We are attaching the Drobox Link which is having the project for iOS Swift.

we are getting the below error while reading the graphQL spatial data.

Error: GraphQLResultError(path: location.nodes.0.spatialData.position.coordinates, underlying: Apollo.JSONDecodingError.couldNotConvert(value: <__NSArrayI 0x6000028df940>(

75.86227,

22.72567

)

, to: DemoGraphQlCustomscalar.DataInfoQuery.Data.Location.Node.SpatialDatum.Position))

with Version
graphQL :0.51.2
SqlLite : 0.13.3

We tried with Passthrough Custom Scalar in build phases.

Thanks, the query now works with the id parameter.

@Pramit_jain, @Priya_Soni - I have it working, here is the updated sample code.

There are a couple things to note:

  • You will need to alias the position field because it is causing the generated selection set type to be named Position (AbcQuery.Data.Location.Node.SpatialDatum.Position) which conflicts with the schema type Position; the position.coordinates and area.coordinates fields are schema type Position. You cannot rename a schema type.
  • You cannot simply extend AbcQuery.Data.Location.Node.SpatialDatum.Position to be JSONDecodable and use it for the coordinates values because it is a selection set.

Look at:

  1. abc.graphql to see the alias, geoPosition: position.
  2. API.swift to see the aliased field being used with the renamed type, public var geoPosition: GeoPosition. Also note that coordinates within GeoPosition is still type Position.
  3. NSDecodable+Extensions.swift to see the Position type alias and conformance to JSONDecodable.

Hope this helps in moving forward with your project.

1 Like

Hi @calvincestari ,

Thank you for your time for looking into our issue.

Yes, it worked for us. @Priya_Soni downloaded the code that you shared on google drive and she was able to get the spatial data.

Thank you very much again.

1 Like