Skip to content

Instantly share code, notes, and snippets.

@petrbela
Last active March 26, 2017 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petrbela/0872f3c4bb05944c17a0 to your computer and use it in GitHub Desktop.
Save petrbela/0872f3c4bb05944c17a0 to your computer and use it in GitHub Desktop.
GraphQL types in separate files
'use strict'
import {
GraphQLObjectType,
GraphQLString,
} from 'graphql'
import Types from './Types'
Types.Album = new GraphQLObjectType({
name: 'Album',
description: 'Collection of assets.',
fields: () => ({
shortcut: {
type: GraphQLString,
description: 'Public shortcut.',
},
name: {
type: GraphQLString,
description: 'Album name.',
},
user: {
type: Types.User,
description: 'Album owner.',
resolve: (album, args) => ...
}
})
})
export default Types.Album
export default {}
'use strict'
import {
GraphQLObjectType,
GraphQLNonNull,
GraphQLList,
GraphQLString,
} from 'graphql'
import Types from './Types'
Types.User = new GraphQLObjectType({
name: 'User',
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLString),
},
name: {
type: GraphQLString,
description: 'Full name',
},
username: {
type: GraphQLString,
description: 'Username',
},
// connections
albums: {
type: new GraphQLList(Types.Album),
args: {
oauth_token: { type: GraphQLString }
},
resolve: (user, args) => ...
},
})
})
export default Types.User
@humadev
Copy link

humadev commented Mar 26, 2017

nice, this is good sample using graphql. i'm adding querytype field into it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment