Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-08-2023 05:13 AM - edited 02-08-2023 05:16 AM
Hi there,
I have added a @cypher directive to my GraphQL Type - getDistances.
I am getting an error returned from my graphQL query when I make a query using getDistances. Can you please tell me what might be causing the problem ?
const typeDefs = gql`
type Company {
id: Int
postCode: String
name: String
ratingValue: String
structuralScore: String
location: Point
localAuthority: String
isHospitality: Boolean
hygieneScore: String
confidenceInManagementScore: String
businessType: String
addressLineOne: String
addressLineTwo: String
addressLineThree: String
addressLineFour: String
getDistances(startLat: Float, startLng: Float, endLat: Float, endLng: Float): [Company]
@cypher(
statement: """
WITH
point({longitude: $startLng, latitude: $startLat, height: 100}) AS p1,
point({latitude: $endLat, longitude: $endLng, height: 100}) AS p2
RETURN point.distance(p1, p2) AS dist
""")
}
`;
GraphQL query
{
companies {
getDistances(startLat: 51.400616, startLng: -0.2645342, endLat: 51.6443052331424, endLng: 0.61920005649669) {
name
}
}
}
Error response
{
"errors": [
{
"message": "Double(6.695317e+04) (of class org.neo4j.values.storable.DoubleValue)",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"companies"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"code": "Neo.DatabaseError.Statement.ExecutionFailed",
"name": "Neo4jError",
"retriable": false,
"stacktrace": [
"Neo4jError: Double(6.695317e+04) (of class org.neo4j.values.storable.DoubleValue)",
"",
" at captureStacktrace (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/result.js:611:17)",
" at new Result (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/result.js:105:23)",
" at newCompletedResult (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/transaction.js:502:12)",
" at Object.run (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/transaction.js:334:20)",
" at Transaction.run (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/transaction.js:175:34)",
" at Executor.transactionRun (/Users/james/development/graphql_server/node_modules/@neo4j/graphql/dist/classes/Executor.js:138:28)",
" at /Users/james/development/graphql_server/node_modules/@neo4j/graphql/dist/classes/Executor.js:126:25",
" at TransactionExecutor._safeExecuteTransactionWork (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:141:26)",
" at TransactionExecutor.<anonymous> (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:128:46)",
" at step (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:52:23)"
]
}
}
}
],
"data": null
}
02-08-2023 07:38 AM
You're getting that error because the statement you have provided to the cypher directive returns a Float type. However, your type definitions expect a list of Company objects. The following type definition should work for you:
type Company {
id: Int
postCode: String
name: String
ratingValue: String
structuralScore: String
location: Point
localAuthority: String
isHospitality: Boolean
hygieneScore: String
confidenceInManagementScore: String
businessType: String
addressLineOne: String
addressLineTwo: String
addressLineThree: String
addressLineFour: String
getDistances(startLat: Float, startLng: Float, endLat: Float, endLng: Float): Float
@cypher(
statement: """
WITH
point({longitude: $startLng, latitude: $startLat, height: 100}) AS p1,
point({latitude: $endLat, longitude: $endLng, height: 100}) AS p2
RETURN point.distance(p1, p2) AS dist
"""
)
}
All the sessions of the conference are now available online