This repository has been archived by the owner on Jul 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
createResolvers.js
43 lines (42 loc) 路 1.56 KB
/
createResolvers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const { GraphQLInt } = require(`gatsby/graphql`)
const { getRemainingSuggestions, isPost } = require(`./helpers`)
// based on https://github.com/gatsbyjs/gatsby/blob/master/examples/using-type-definitions/gatsby-node.js#L63
module.exports = store =>
function createResolvers({ createResolvers }) {
createResolvers({
Mdx: {
suggested: {
type: `[Mdx!]!`,
args: {
count: GraphQLInt,
},
resolve(source, { count }, { nodeModel }, info) {
const result = nodeModel.getAllNodes({ type: `Mdx` })
const posts = result.filter(n => isPost(n))
return getRemainingSuggestions(source.frontmatter.id, count)(posts)
// return getSuggestedNodes(posts, source, count)
},
},
older: {
type: `Mdx`,
resolve(source, _, { nodeModel }) {
const result = nodeModel.getAllNodes({ type: `Mdx` })
const posts = result.filter(n => isPost(n))
const index = posts.findIndex(n => n.id === source.id)
const older = posts[index + 1]
return older && older.id ? older : null
},
},
newer: {
type: `Mdx`,
resolve(source, _, { nodeModel }) {
const result = nodeModel.getAllNodes({ type: `Mdx` })
const posts = result.filter(n => isPost(n))
const index = posts.findIndex(n => n.id === source.id)
const newer = posts[index - 1]
return newer && newer.id ? newer : null
},
},
},
})
}