Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 別ファイルで定義したデータ
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