Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Created April 18, 2020 05:40
Show Gist options
  • Save vladbatushkov/6cfc69aaa009991c22090a1aaf351e4b to your computer and use it in GitHub Desktop.
Save vladbatushkov/6cfc69aaa009991c22090a1aaf351e4b to your computer and use it in GitHub Desktop.
Custom GraphQL resolver
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