/
create-schema-customization.js
54 lines (45 loc) · 1.09 KB
/
create-schema-customization.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
44
45
46
47
48
49
50
51
52
53
54
const typeDefs = `
type MarkdownHeading {
id: String
value: String
depth: Int
}
enum MarkdownHeadingLevels {
h1
h2
h3
h4
h5
h6
}
enum MarkdownExcerptFormats {
PLAIN
HTML
MARKDOWN
}
type MarkdownWordCount {
paragraphs: Int
sentences: Int
words: Int
}
type MarkdownRemark implements Node @infer @childOf(mimeTypes: ["text/markdown", "text/x-markdown"]) {
id: ID!
}
`
module.exports = (nodeApiArgs, pluginOptions = {}) => {
const { plugins = [] } = pluginOptions
nodeApiArgs.actions.createTypes(typeDefs)
// This allows subplugins to use Node APIs bound to `gatsby-transformer-remark`
// to customize the GraphQL schema. This makes it possible for subplugins to
// modify types owned by `gatsby-transformer-remark`.
plugins.forEach(plugin => {
const resolvedPlugin = plugin.module
if (typeof resolvedPlugin.createSchemaCustomization === `function`) {
resolvedPlugin.createSchemaCustomization(
nodeApiArgs,
plugin.pluginOptions
)
}
})
}
module.exports.typeDefs = typeDefs