-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
146 lines (131 loc) · 2.86 KB
/
gatsby-node.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const path = require(`path`)
const makeRequest = (graphql, request) =>
new Promise((resolve, reject) => {
// Query for nodes to use in creating pages.
resolve(
graphql(request).then(result => {
if (result.errors) {
reject(result.errors)
}
return result
})
)
})
// Implement the Gatsby API “createPages”. This is called once the
// data layer is bootstrapped to let plugins create pages from data.
exports.createPages = ({ actions, graphql }) => {
const { createPage } = actions
const getTrails = makeRequest(
graphql,
`
{
allStrapiTrail {
edges {
node {
slug
}
}
}
}
`
).then(result => {
// Create pages for each article.
result.data.allStrapiTrail.edges.forEach(({ node }) => {
createPage({
path: `/${node.slug}`,
component: path.resolve(`src/templates/trasa.tsx`),
context: {
slug: node.slug,
},
})
})
})
// Query for articles nodes to use in creating pages.
return getTrails
}
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type Query {
allStrapiTrail: StrapiTrail!
strapiTrail: StrapiTrail!
}
type StrapiTrail implements Node {
slug: String
title: String
trail_type: String
criterion: ENUM_TRAIL_CRITERION
availability_car: CarAvailibility
availability_bus: BusAvailibility
availability_train: TrainAvailibility
content: JSON!
coords: Coords
trail_type: ENUM_TRAIL_TRAIL_TYPE!
cover_image: UploadFile
}
enum ENUM_TRAIL_TRAIL_TYPE {
aa
ab
}
enum ENUM_TRAIL_CRITERION {
fast
short
bike1
bike2
bike3
turist1
turist2
}
type CarAvailibility implements Node {
parking1: String
parking2: String
parking3: String
}
type BusAvailibility implements Node {
stop1: String
stop2: String
stop3: String
}
type TrainAvailibility implements Node {
station1: String
station2: String
station3: String
}
type Coords implements Node {
lat1: Float
lng1: Float
lat2: Float
lng2: Float
lat3: Float
lng3: Float
lat4: Float
lng4: Float
lat5: Float
lng5: Float
lat6: Float
lng6: Float
lat7: Float
lng7: Float
lat8: Float
lng8: Float
lat9: Float
lng9: Float
lat10: Float
lng10: Float
}
type UploadFile implements Node {
name: String!
alternativeText: String
caption: String
width: Int
height: Int
formats: JSON
hash: String!
ext: String
mime: String!
size: Float!
url: String!
}
`
createTypes(typeDefs)
}