Created
April 18, 2020 05:40
-
-
Save vladbatushkov/6cfc69aaa009991c22090a1aaf351e4b to your computer and use it in GitHub Desktop.
Custom GraphQL resolver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Query { | |
FlightsSearchObjects(from: String, to: String, date: String): [FlightsSearchResult] | |
} | |
const query = "CALL custom.getFlightsObjects($from, $to, $date, 2, 6) YIELD result RETURN result"; | |
export const resolvers = { | |
Query: { | |
FlightsSearchObjects : async (object, params, ctx, resolveInfo) => { | |
var result; | |
var session = ctx.driver.session(); | |
await session | |
.run(query, params) | |
.then(res => { | |
result = res.records.map(rec => rec.get("result")); | |
}) | |
.catch(error => { | |
result = []; | |
console.log(error); | |
}) | |
.then(() => session.close()); | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment