-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
Copy pathplugin-options.js
48 lines (46 loc) · 1.19 KB
/
plugin-options.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
import { parse } from "gatsby/graphql"
import { stripIndent } from "common-tags"
const feed = ({ Joi }) =>
Joi.object({
output: Joi.string().required(),
query: Joi.string().required(),
title: Joi.string().required(),
serialize: Joi.func().required(),
match: Joi.string(),
link: Joi.string(),
})
.unknown(true)
.external(({ query }) => {
if (query) {
try {
parse(query)
} catch (e) {
throw new Error(
stripIndent`
Invalid plugin options for "gatsby-plugin-feed":
"query" must be a valid GraphQL query. Received the error "${e.message}"`
)
}
}
})
export default ({ Joi }) =>
Joi.object({
generator: Joi.string(),
query: Joi.string(),
setup: Joi.func(),
feeds: Joi.array().items(feed({ Joi })).required(),
})
.unknown(true)
.external(({ query }) => {
if (query) {
try {
parse(query)
} catch (e) {
throw new Error(
stripIndent`
Invalid plugin options for "gatsby-plugin-feed":
"query" must be a valid GraphQL query. Received the error "${e.message}"`
)
}
}
})