-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresolver.js
executable file
·63 lines (60 loc) · 1.79 KB
/
resolver.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
55
56
57
58
59
60
61
62
63
import config from 'config'
import Prismic from 'prismic-javascript'
import PrismicDOM from 'prismic-dom'
import Slice from './helpers/slice'
const apiEndpoint = config.prismic.baseUrl
let cmsBlockType = (typeof config.prismic.cmsBlockEntityType !== 'undefined') ? config.prismic.cmsBlockEntityType : 'cms-block'
let cmsPageType = (typeof config.prismic.cmsPageEntityType !== 'undefined') ? config.prismic.cmsPageEntityType : 'cms-page'
const resolver = {
Query: {
prismicCmsBlocks: () => {
return Prismic.getApi(apiEndpoint).then((api) => {
return api.query(Prismic.Predicates.at('document.type', cmsBlockType))
}).then(response => response.results)
},
prismicCmsPages: () => {
return Prismic.getApi(apiEndpoint).then((api) => {
return api.query(Prismic.Predicates.at('document.type', cmsPageType))
}).then(response => response.results)
},
},
PrismicCmsBlock: {
identifier: parent => {
return parent.uid
},
title: parent => {
const { data } = parent
return PrismicDOM.RichText.asHtml(data.title)
},
content: parent => {
const { data } = parent
return Slice.parse(data.body)
},
creation_time: parent => {
return parent.first_publication_date
},
update_time: parent => {
return parent.last_publication_date
}
},
PrismicCmsPage: {
slug: parent => {
return parent.uid
},
title: parent => {
const { data } = parent
return PrismicDOM.RichText.asHtml(data.title)
},
content: parent => {
const { data } = parent
return Slice.parse(data.body)
},
creation_time: parent => {
return parent.first_publication_date
},
update_time: parent => {
return parent.last_publication_date
}
}
}
export default resolver