-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow an episode to be passed to hero #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ import { | |
GraphQLString, | ||
} from '../type'; | ||
|
||
import { starWarsData, getFriends, artoo } from './starWarsData.js'; | ||
import { starWarsData, getFriends, artoo, luke } from './starWarsData.js'; | ||
|
||
/** | ||
* This is designed to be an end-to-end test, demonstrating | ||
|
@@ -60,7 +60,7 @@ import { starWarsData, getFriends, artoo } from './starWarsData.js'; | |
* } | ||
* | ||
* type Query { | ||
* hero: Character | ||
* hero(episode: Episode): Character | ||
* human(id: String!): Human | ||
* droid(id: String!): Droid | ||
* } | ||
|
@@ -222,7 +222,7 @@ var droidType = new GraphQLObjectType({ | |
* | ||
* This implements the following type system shorthand: | ||
* type Query { | ||
* hero: Character | ||
* hero(episode: Episode): Character | ||
* human(id: String!): Human | ||
* droid(id: String!): Droid | ||
* } | ||
|
@@ -233,7 +233,21 @@ var queryType = new GraphQLObjectType({ | |
fields: () => ({ | ||
hero: { | ||
type: characterInterface, | ||
resolve: () => artoo, | ||
args: { | ||
episode: { | ||
description: 'If omitted, returns the hero of the whole saga. If ' + | ||
'provided, returns the hero of that particular episode.', | ||
type: episodeEnum | ||
} | ||
}, | ||
resolve: (root, {episode}) => { | ||
if (episode === 5) { | ||
// Luke is the hero of Episode V. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you misspelled "Lando" here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return luke; | ||
} | ||
// Artoo is the hero otherwise. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol |
||
return artoo; | ||
} | ||
}, | ||
human: { | ||
type: humanType, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice