Last active
February 20, 2017 23:09
-
-
Save RyanCCollins/fd1e62cb80635ce27fff187c2e8d1cd5 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
// Comment Model Schema and related GraphQL Schema | |
// From /server/db/models/comment.ts | |
import mongoose from 'mongoose'; | |
const CommentSchema = new mongoose.Schema({ | |
author: String, | |
body: String, | |
post: { | |
type: String, | |
ref: 'Post', | |
required: true, | |
}, | |
}); | |
export default mongoose.model('Comment', CommentSchema); |
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
// From server/graph/types/comment/comment.ts | |
import { | |
GraphQLObjectType, | |
GraphQLNonNull, | |
GraphQLString, | |
GraphQLID, | |
} from 'graphql'; | |
export default new GraphQLObjectType({ | |
name: 'Comment', | |
fields: () => ({ | |
author: { type: GraphQLString }, | |
body: { type: GraphQLString }, | |
post: { type: new GraphQLNonNull(GraphQLID) }, | |
}), | |
}); |
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
// Post Model Schema and related GraphQL Schema | |
// From /server/db/models/post.ts | |
import mongoose from 'mongoose'; | |
const PostSchema = new mongoose.Schema({ | |
title: { | |
type: String, | |
}, | |
image: { | |
type: String, | |
}, | |
content: { | |
type: String, | |
}, | |
comments: [{ type: String, ref: 'Comment' }], | |
}); | |
export default mongoose.model('Post', PostSchema);po |
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
// From server/graph/types/post/post.ts | |
import { | |
GraphQLObjectType, | |
GraphQLList, | |
GraphQLString, | |
GraphQLID, | |
} from 'graphql'; | |
import commentType from '../comment/comment'; | |
export default new GraphQLObjectType({ | |
name: 'Post', | |
fields: () => ({ | |
_id: { type: GraphQLID }, | |
title: { type: GraphQLString }, | |
content: { type: GraphQLString }, | |
comments: { type: new GraphQLList(commentType) }, | |
image: { type: GraphQLString }, | |
}), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment