Skip to content

Instantly share code, notes, and snippets.

@RyanCCollins
Last active February 20, 2017 23:10
Show Gist options
  • Save RyanCCollins/e2fb98e38e479df4eefe7a95912f1d18 to your computer and use it in GitHub Desktop.
Save RyanCCollins/e2fb98e38e479df4eefe7a95912f1d18 to your computer and use it in GitHub Desktop.
// From server/graph/queries/post/posts.ts
import {
GraphQLList,
} from 'graphql';
import types from '../../types';
import PostModel from '../../../db/models/post';
export default {
type: new GraphQLList(types.postType),
args: {},
resolve() {
return PostModel
.find()
.exec();
},
};
// From server/graph/queries/post/post.ts
import {
GraphQLNonNull,
GraphQLID,
} from 'graphql';
import types from '../../types';
import PostModel from '../../../db/models/post';
export default {
type: types.postType,
args: {
id: {
type: new GraphQLNonNull(GraphQLID),
},
},
resolve(_, args, __) {
return PostModel
.findById(args.id)
.populate('comments')
.exec();
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment