Last active
March 26, 2017 19:12
-
-
Save petrbela/0872f3c4bb05944c17a0 to your computer and use it in GitHub Desktop.
GraphQL types in separate files
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, | |
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 |
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 default {} |
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, | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice, this is good sample using graphql. i'm adding querytype field into it too.