Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/__tests__/starWarsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
* JSON objects in a more complex demo.
*/

var luke = {
/**
* We export luke directly because the schema returns him
* from a root field, and hence needs to reference him.
*/
export var luke = {
id: '1000',
name: 'Luke Skywalker',
friends: ['1002', '1003', '2000', '2001'],
Expand Down
21 changes: 17 additions & 4 deletions src/__tests__/starWarsIntrospectionTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ describe('Star Wars Introspection Tests', () => {
{
name: 'Query'
},
{
name: 'Episode'
},
{
name: 'Character'
},
Expand All @@ -42,9 +45,6 @@ describe('Star Wars Introspection Tests', () => {
{
name: 'String'
},
{
name: 'Episode'
},
{
name: 'Droid'
},
Expand Down Expand Up @@ -327,7 +327,20 @@ describe('Star Wars Introspection Tests', () => {
fields: [
{
name: 'hero',
args: []
args: [
{
defaultValue: null,
description: 'If omitted, returns the hero of the whole ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

'saga. If provided, returns the hero of ' +
'that particular episode.',
name: 'episode',
type: {
kind: 'ENUM',
name: 'Episode',
ofType: null
}
}
]
},
{
name: 'human',
Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/starWarsQueryTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,24 @@ describe('Star Wars Query Tests', () => {
var result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});

it('Allows us to verify that Luke is a human', async () => {
var query = `
query CheckTypeOfLuke {
hero(episode: EMPIRE) {
__typename
name
}
}
`;
var expected = {
hero: {
__typename: 'Human',
name: 'Luke Skywalker'
},
};
var result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
});
});
22 changes: 18 additions & 4 deletions src/__tests__/starWarsSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
* }
Expand Down Expand Up @@ -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
* }
Expand All @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you misspelled "Lando" here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return luke;
}
// Artoo is the hero otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

return artoo;
}
},
human: {
type: humanType,
Expand Down