mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
extract queries into their own files
This commit is contained in:
parent
ce13bf11c0
commit
4907310480
11 changed files with 161 additions and 149 deletions
|
@ -11,5 +11,6 @@ import './permissions.js';
|
|||
import './published_fields.js';
|
||||
import './resolvers.js';
|
||||
import './mutations.js';
|
||||
import './queries.js';
|
||||
|
||||
export default Categories;
|
26
packages/nova-categories/lib/queries.js
Normal file
26
packages/nova-categories/lib/queries.js
Normal 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
|
||||
}
|
||||
`
|
||||
}
|
|
@ -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() : [];
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -13,5 +13,6 @@ import './published_fields.js';
|
|||
import './permissions.js';
|
||||
import './resolvers.js';
|
||||
import './mutations.js';
|
||||
import './queries.js';
|
||||
|
||||
export default Comments;
|
27
packages/nova-comments/lib/queries.js
Normal file
27
packages/nova-comments/lib/queries.js
Normal 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
|
||||
}
|
||||
}
|
||||
`
|
||||
}
|
|
@ -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 });
|
||||
|
|
|
@ -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;
|
99
packages/nova-posts/lib/queries.js
Normal file
99
packages/nova-posts/lib/queries.js
Normal 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
|
||||
}
|
||||
}
|
||||
`
|
||||
};
|
|
@ -36,3 +36,5 @@ export default resolvers = {
|
|||
},
|
||||
Mutation: mutations
|
||||
};
|
||||
|
||||
Telescope.graphQL.addResolvers(resolvers);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue