Created
April 18, 2020 07:07
-
-
Save vladbatushkov/4c1e783ca58c529327f9a1c8f14e6d31 to your computer and use it in GitHub Desktop.
Custom Scalar Types
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
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