-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.ts
51 lines (47 loc) · 1.29 KB
/
gatsby-node.ts
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
44
45
46
47
48
49
50
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
import type { GatsbyNode } from 'gatsby'
export const onCreateNode: GatsbyNode['onCreateNode'] = require('./gatsby/onCreateNode')
export const createSchemaCustomization: GatsbyNode['createSchemaCustomization'] = ({ actions, schema }) => {
const { createTypes } = actions
const typeDefs = [
`type MarkdownRemark implements Node { frontmatter: Frontmatter! }`,
`type AuthorJson implements Node {
name: String!
jsonId: String!
posts: [MarkdownRemark] @link(by: "frontmatter.authors.elemMatch.jsonId", from: "jsonId")
}
`,
schema.buildObjectType({
name: `Frontmatter`,
fields: {
comingSoon: {
type: `Boolean`,
resolve(source) {
const {comingSoon} = source
return comingSoon == null ? false : comingSoon
}
},
summary: {
type: `String`
},
authors: {
type: `[AuthorJson]!`,
resolve(source) {
const {authors} = source
return authors == null ? [] : authors
},
extensions: {
link: {
by: 'jsonId'
}
}
}
}
})
]
createTypes(typeDefs)
}