Created
December 1, 2015 15:54
-
-
Save v0lkan/196a770321ff7158443b to your computer and use it in GitHub Desktop.
FluentConf Node.JS API Performance Talk (draft for a demo schema)
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
'use strict'; | |
import { | |
GraphQLObjectType, | |
GraphQLSchema, | |
GraphQLList, | |
GraphQLString | |
} from 'graphql/type'; | |
import { Promise } from 'bluebird'; | |
let getTags = () => { | |
// A set of tags; normally this will return a `Promise`, and the result | |
// will vary based on the arguments passed. | |
return [ | |
'ecmascript', | |
'javascript', | |
'node', | |
'node.js', | |
'performance', | |
'perfmatters' | |
]; | |
}; | |
let getUrls = () => { | |
// A set of URLs; normally this will return a `Promise`, and the result | |
// will vary based on the arguments passed. | |
return [ | |
'http://becausejavascript.com/node-js-process-nexttick-vs-setimmediate', | |
'http://begriffs.com/posts/2015-07-22-essence-of-frp.html', | |
'http://benchmarkjs.com/', | |
'http://benhowdle.im/touche/', | |
'http://benmccormick.org/2015/09/09/what-can-backbone-developers-learn-from-react/', | |
'http://bennettfeely.com/csscreatures/', | |
'http://betterexplained.com/' | |
]; | |
}; | |
let query = new GraphQLObjectType( { | |
name: 'Query', | |
fields: () => ( { | |
tags: { | |
description: 'List of tags computed off of a URL.', | |
type: new GraphQLList( GraphQLString ), | |
args: { | |
url: { | |
description: 'The URL to auto-extract the tags from.', | |
type: GraphQLString | |
} | |
}, | |
resolve: ( root, { url } ) => getTags( url ) | |
}, | |
urls: { | |
description: 'List of urls that share a tag.', | |
type: new GraphQLList( GraphQLString ), | |
args: { | |
url: { | |
description: 'The tag to get the list of URLs.', | |
type: GraphQLString | |
} | |
}, | |
resolve: ( root, { url } ) => getTags( url ) | |
} | |
} ) | |
} ); | |
export default new GraphQLSchema( { query: query } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment