How to write a GraphQL query from the cypher query example point.distance()?

Can someone please show me how to write a graphQL query from this cypher query as an example?

WITH
  point({longitude: 12.78, latitude: 56.7, height: 100}) AS p1,
  point({latitude: 56.71, longitude: 12.79, height: 100}) AS p2
RETURN point.distance(p1, p2) AS dist

Hi @jcct100 -

Your Cypher statement is computing the distance between two points - how do you want to use that in the context of GraphQL?

In general, when using the Neo4j GraphQL Library there are a few things you can do with Point types and distances.

First, let's say you have some type Building (that represents nodes in Neo4j with the label Building):

type Building {
  address: String
  location: Point
}

Since location is a Point field, by default you'll be able to use the filtering functionality built into the Neo4j GraphQL Library to search for buildings within some radius distance of a given point:

query MyQuery {
  buildings(
    where: {
      location_LT: {
        point: { longitude: 12.79, latitude: 56.71 }
        distance: 2000
      }
    }
  ) {
    address
    location {
      latitude
      longitude
    }
  }
}

Another option might be to use the @cypher GraphQL schema directive which allows you to "attach" a Cypher statement to a field in the GraphQL schema to define custom logic. Any field arguments defined for this field are passed to the attached Cypher statement as Cypher parameters. Here's how we could add a distance field to the Building type that calculates the distance from some given point to the value of the location point property on the resolved Building.:

extend type Building {
 distance(lat: Float, lng: Float): Float @cypher(statement: """
   RETURN point.distance(this.location, point({latitude: $lat, longitude: $lon})
""")
}