-
-
Save arunoda/2cbba32de83bfa96099d to your computer and use it in GitHub Desktop.
Schema File with the Post type
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 * as _ from 'underscore'; | |
// This is the Dataset in our blog | |
import PostsList from './data/posts'; | |
import AuthorsList from './data/authors'; | |
import {CommentList, ReplyList} from './data/comments'; | |
import { | |
// These are the basic GraphQL types | |
GraphQLInt, | |
GraphQLFloat, | |
GraphQLString, | |
GraphQLList, | |
GraphQLObjectType, | |
GraphQLEnumType, | |
// This is used to create required fileds and arguments | |
GraphQLNonNull, | |
// This is the class we need to create the schema | |
GraphQLSchema, | |
} from 'graphql'; | |
/** | |
DEFINE YOUR TYPES BELOW | |
**/ | |
const Post = new GraphQLObjectType({ | |
name: "Post", | |
description: "This represent a Post", | |
fields: () => ({ | |
_id: {type: new GraphQLNonNull(GraphQLString)}, | |
title: {type: new GraphQLNonNull(GraphQLString)}, | |
content: {type: GraphQLString} | |
}) | |
}); | |
// This is the Root Query | |
const Query = new GraphQLObjectType({ | |
name: 'BlogSchema', | |
description: "Root of the Blog Schema", | |
fields: () => ({ | |
posts: { | |
type: new GraphQLList(Post), | |
resolve: function() { | |
return PostsList; | |
} | |
}, | |
echo: { | |
type: GraphQLString, | |
description: "Echo what you enter", | |
args: { | |
message: {type: GraphQLString} | |
}, | |
resolve: function(source, {message}) { | |
return {aa: 10}; | |
} | |
} | |
}) | |
}); | |
// This the Schema | |
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