extract queries into their own files

This commit is contained in:
Sacha Greif 2016-11-08 15:04:17 +09:00
parent ce13bf11c0
commit 4907310480
11 changed files with 161 additions and 149 deletions

View file

@ -11,5 +11,6 @@ import './permissions.js';
import './published_fields.js';
import './resolvers.js';
import './mutations.js';
import './queries.js';
export default Categories;

View file

@ -0,0 +1,26 @@
import Telescope from 'meteor/nova:lib';
import Categories from './collection.js';
Telescope.graphQL.addQuery(`
categories: [Category]
category(_id: String): Category
`);
Categories.graphQLQueries = {
single: `
_id
name
description
order
slug
image
parent {
_id
name
description
order
slug
image
}
`
}

View file

@ -1,6 +1,6 @@
import Telescope from 'meteor/nova:lib';
const resolvers = {
export default resolvers = {
Post: {
categories(post, args, context) {
return post.categories ? context.Categories.find({_id: {$in: post.categories}}, { fields: context.getViewableFields(context.currentUser, context.Categories) }).fetch() : [];

View file

@ -143,28 +143,4 @@ Categories.attachSchema(Categories.schema);
Telescope.graphQL.addCollection(Categories, 'Category');
Telescope.graphQL.addQuery(`
categories: [Category]
category(_id: String): Category
`);
Categories.graphQLQueries = {
single: `
_id
name
description
order
slug
image
parent {
_id
name
description
order
slug
image
}
`
}
Telescope.graphQL.addToContext({ Categories });

View file

@ -13,5 +13,6 @@ import './published_fields.js';
import './permissions.js';
import './resolvers.js';
import './mutations.js';
import './queries.js';
export default Comments;

View file

@ -0,0 +1,27 @@
import Telescope from 'meteor/nova:lib';
import Comments from './collection.js';
// declare comments queries
Telescope.graphQL.addQuery(`
comments(postId: String): [Comment]
comment(_id: String): Comment
`);
Comments.graphQLQueries = {
single: `
_id
postId
parentCommentId
topLevelCommentId
body
htmlBody
postedAt
user {
_id
telescope {
slug
emailHash # used for the avatar
}
}
`
}

View file

@ -227,31 +227,7 @@ if (typeof Telescope.notifications !== "undefined") {
// }
// `;
// add Comments collection to list to auto-generate its GraphQL schema
Telescope.graphQL.addCollection(Comments, 'Comment');
// Telescope.graphQL.addSchema(Comments.graphQLSchema);
Telescope.graphQL.addQuery(`
comments(postId: String): [Comment]
comment(_id: String): Comment
`);
Comments.graphQLQueries = {
single: `
_id
postId
parentCommentId
topLevelCommentId
body
htmlBody
postedAt
user {
_id
telescope {
slug
emailHash # used for the avatar
}
}
`
}
Telescope.graphQL.addToContext({ Comments });

View file

@ -10,7 +10,8 @@ import './callbacks.js';
import './emails.js';
import './methods.js';
import './permissions.js';
// import './resolvers.js';
// import './mutations.js';
import './resolvers.js';
import './mutations.js';
import './queries.js';
export default Posts;

View file

@ -0,0 +1,99 @@
import Telescope from 'meteor/nova:lib';
import Posts from './collection.js';
Telescope.graphQL.addQuery(`
posts(terms: Terms, offset: Int, limit: Int): [Post]
postsViewTotal(terms: Terms): Int
post(_id: String): Post
`);
Posts.graphQLQueries = {
list: `
_id
title
url
slug
thumbnailUrl
baseScore
postedAt
sticky
categories {
_id
name
slug
}
commentCount
commenters {
_id
telescope {
displayName
emailHash
slug
}
}
upvoters {
_id
}
downvoters {
_id
}
upvotes # should be asked only for admins?
score # should be asked only for admins?
viewCount # should be asked only for admins?
clickCount # should be asked only for admins?
user {
_id
telescope {
displayName
slug
emailHash
}
}
`,
single: `
_id
title
url
slug
body
htmlBody
thumbnailUrl
baseScore
postedAt
sticky
status
categories {
_id
name
slug
}
commentCount
commenters {
_id
telescope {
slug
emailHash
}
}
upvoters {
_id
}
downvoters {
_id
}
upvotes # should be asked only for admins?
score # should be asked only for admins?
viewCount # should be asked only for admins?
clickCount # should be asked only for admins?
user {
_id
telescope {
displayName
slug
emailHash
}
}
`
};

View file

@ -36,3 +36,5 @@ export default resolvers = {
},
Mutation: mutations
};
Telescope.graphQL.addResolvers(resolvers);

View file

@ -2,8 +2,6 @@ import Telescope from 'meteor/nova:lib';
import Posts from './collection.js';
import Users from 'meteor/nova:users';
import resolvers from './resolvers.js';
/**
* @summary Posts config namespace
* @type {Object}
@ -371,94 +369,6 @@ if (typeof SimpleSchema !== "undefined") {
// }
// `;
Posts.graphQLQueries = {
list: `
_id
title
url
slug
thumbnailUrl
baseScore
postedAt
sticky
categories {
_id
name
slug
}
commentCount
commenters {
_id
telescope {
displayName
emailHash
slug
}
}
upvoters {
_id
}
downvoters {
_id
}
upvotes # should be asked only for admins?
score # should be asked only for admins?
viewCount # should be asked only for admins?
clickCount # should be asked only for admins?
user {
_id
telescope {
displayName
slug
emailHash
}
}
`,
single: `
_id
title
url
slug
body
htmlBody
thumbnailUrl
baseScore
postedAt
sticky
status
categories {
_id
name
slug
}
commentCount
commenters {
_id
telescope {
slug
emailHash
}
}
upvoters {
_id
}
downvoters {
_id
}
upvotes # should be asked only for admins?
score # should be asked only for admins?
viewCount # should be asked only for admins?
clickCount # should be asked only for admins?
user {
_id
telescope {
displayName
slug
emailHash
}
}
`
};
Telescope.graphQL.addCollection(Posts, 'Post');
@ -478,13 +388,6 @@ const termsSchema = `
Telescope.graphQL.addSchema(termsSchema);
Telescope.graphQL.addQuery(`
posts(terms: Terms, offset: Int, limit: Int): [Post]
postsViewTotal(terms: Terms): Int
post(_id: String): Post
`);
Telescope.graphQL.addToContext({ Posts });
Telescope.graphQL.addResolvers(resolvers);