Created
June 23, 2016 21:50
-
-
Save chuck0523/da775661c6efd666d912fb00298a1a12 to your computer and use it in GitHub Desktop.
This file contains 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
// 別ファイルで定義したデータ | |
import PostsList from './data/posts'; | |
import { | |
GraphQLString, | |
GraphQLList, | |
GraphQLObjectType, | |
GraphQLNonNull, | |
GraphQLSchema | |
} from 'graphql'; | |
const Post = new GraphQLObjectType({ | |
name: "Post", | |
description: "This represents a Post", | |
fields: () => ({ | |
// 必須項目はGraphQLNonNullで囲う。 | |
_id: {type: new GraphQLNonNull(GraphQLString)}, | |
title: {type: new GraphQLNonNull(GraphQLString)}, | |
content: {type: GraphQLString} | |
}) | |
}) | |
// ルートクエリ | |
const Query = new GraphQLObjectType({ | |
name: 'BlogSchema', | |
description: 'Root of the Blog Schema', | |
fields: () => ({ | |
posts: { | |
// Post型のGraphQLリスト | |
type: new GraphQLList(Post), | |
resolve: function() { | |
return PostsList | |
} | |
} | |
}) | |
}); | |
// スキーマ | |
const Schema = new GraphQLSchema({ | |
query: Query | |
}); | |
export default Schema; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment