Skip to content

Instantly share code, notes, and snippets.

@brygrill
Last active January 30, 2018 02:00
Show Gist options
  • Save brygrill/6ae474c580f07b12125fb2b6ac0594bf to your computer and use it in GitHub Desktop.
Save brygrill/6ae474c580f07b12125fb2b6ac0594bf to your computer and use it in GitHub Desktop.
// mock data
const data = [
{ vehicleid: 1, latitude: 40.1, longitude: -76.5 },
{ vehicleid: 2, latitude: 40.2, longitude: -76.6 },
{ vehicleid: 3, latitude: 40.3, longitude: -76.7 }
]
const resolvers = {
Coordinates: new GraphQLScalarType({
name: 'Coordinates',
description: 'A set of coordinates. x, y',
parseValue(value) {
return value;
},
serialize(value) {
return value;
},
parseLiteral(ast) {
return ast.value;
},
}),
PointGeometry: {
type() {
return 'Point';
},
coordinates(item) {
return [item.longitude, item.latitude];
},
},
PointProps: {
id(item) {
return item.vehicleid;
},
lat(item) {
return item.latitude;
},
lon(item) {
return item.longitude;
},
},
PointObject: {
type() {
return 'Feature';
},
geometry(item) {
return item;
},
properties(item) {
return item;
},
},
FeatureCollection: {
type() {
return 'FeatureCollection';
},
features(data) {
return data
},
},
Query: {
transit_feed(_, args, ctx) {
// make your async call for data here
return data;
},
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment