Created
September 7, 2015 13:11
-
-
Save mfirry/10aeeb8fdf2352d8fb96 to your computer and use it in GitHub Desktop.
first-steps-with-relay-graphql
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
export class Ticket extends Object {} | |
var tickets = []; | |
(function() { | |
var t1 = new Ticket(); | |
t1.id = '1'; | |
t1.from = 'CTA'; | |
t1.via = 'FCO'; | |
t1.to = 'JFK'; | |
t1.airports = ['CTA', 'FCO', 'JFK']; | |
var t2 = new Ticket(); | |
t2.id = '2'; | |
t2.from = 'FCO'; | |
t2.via = null; | |
t2.to = 'JFK'; | |
t2.airports = ['FCO', 'JFK']; | |
var t3 = new Ticket(); | |
t3.id = '3'; | |
t3.from = 'FCO'; | |
t3.via = null; | |
t3.to = 'JFK'; | |
t3.airports = ['MXP', 'CIY']; | |
tickets.push(t1); | |
tickets.push(t2); | |
tickets.push(t3); | |
})(); | |
export function getTicket(id) { | |
return tickets.find(t => t.id === id) | |
} | |
export function getTickets() { | |
return tickets; | |
} |
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
var {nodeInterface, nodeField} = nodeDefinitions( | |
(globalId) => { | |
var {type, id} = fromGlobalId(globalId); | |
if (type === 'Ticket') { | |
return getTicket(id); | |
} else { | |
return null; | |
} | |
}, | |
(obj) => { | |
if (obj instanceof Ticket) { | |
return ticketType; | |
} else { | |
return null; | |
} | |
} | |
); | |
var ticketType = new GraphQLObjectType({ | |
name: 'Ticket', | |
description: 'A ticket for a flight from A to B', | |
fields: () => ({ | |
id: { | |
type: globalIdField('Ticket'), | |
description: 'The id of the flight.' | |
}, | |
from: { | |
type: GraphQLString, | |
description: 'IATA CODE for the departing airport' | |
}, | |
via: { | |
type: GraphQLString, | |
description: 'IATA CODE for the connection airport' | |
}, | |
to: { | |
type: GraphQLString, | |
description: 'IATA CODE for the arriving airport' | |
}, | |
airports: { | |
type: new GraphQLList(GraphQLString), | |
description: 'List of involved airports' | |
} | |
}), | |
interfaces: [nodeInterface], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment