Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Created April 18, 2020 07:07
Show Gist options
  • Save vladbatushkov/4c1e783ca58c529327f9a1c8f14e6d31 to your computer and use it in GitHub Desktop.
Save vladbatushkov/4c1e783ca58c529327f9a1c8f14e6d31 to your computer and use it in GitHub Desktop.
Custom Scalar Types
const pad = (s) => {
let str = s + "";
while (str.length < 2)
str = "0" + str;
return str;
}
const flightsDateTime = new GraphQLScalarType({
name: 'FlightsDateTime',
description: 'Description of flights dateTime type',
serialize(value) {
return `${pad(value.day.low)}.${pad(value.month.low)}.${value.year.low} ${pad(value.hour.low)}:${pad(value.minute.low)}`;
}
});
const flightsInt = new GraphQLScalarType({
name: 'FlightsInt',
description: 'Description of flights int type',
serialize(value) {
return value.low;
}
});
export const resolvers = {
FlightsInt: flightsInt,
FlightsDateTime: flightsDateTime,
Query: { ... }
}
export const typeDefs = `
scalar FlightsDateTime
scalar FlightsInt
type FlightDetails {
departs_local: FlightsDateTime!
arrival_local: FlightsDateTime!
}
type FlightsSearchResult {
flights: [FlightInfo] @neo4j_ignore
route: [RouteInfo] @neo4j_ignore
stops: FlightsInt!
}
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment