Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created June 23, 2016 21:50
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 chuck0523/da775661c6efd666d912fb00298a1a12 to your computer and use it in GitHub Desktop.
Save chuck0523/da775661c6efd666d912fb00298a1a12 to your computer and use it in GitHub Desktop.
// 別ファイルで定義したデータ
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