-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
148 lines (136 loc) · 3.47 KB
/
index.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
147
148
import React from 'react'
class Index extends React.Component {
render() {
const rows = [
'string',
'int',
'date',
'arrayOfString',
'arrayOfNumbers',
'notUsedField',
'customType',
'mapping',
'localFile',
'union',
]
const edges = this.props.data.allMarkdownRemark.edges
const borderStyle = {
border: '1px solid #ccc',
padding: 5,
}
const dataCellStyle = {
...borderStyle,
textAlign: 'center',
}
const imgUrl = require('./graphiql.png')
return (
<div
style={{
margin: '0 auto',
fontFamily: 'sans-serif',
}}
>
<table style={{ borderCollapse: 'collapse' }}>
<thead>
<tr>
<th />
{edges.map(({ node }, index) => (
<th key={`head_${index}`} style={borderStyle} colSpan="2">
{node.frontmatter.title}.md
</th>
))}
</tr>
<tr>
<th />
<th style={borderStyle}>Output</th>
<th style={borderStyle}>Input</th>
<th style={borderStyle}>Output</th>
<th style={borderStyle}>Input</th>
<th style={borderStyle}>Output</th>
<th style={borderStyle}>Input</th>
</tr>
</thead>
<tbody>
{rows.map(row => {
const cells = [
<th style={borderStyle} key={`h${row}`}>
{row}
</th>,
]
edges.forEach(({ node }, index) => {
cells.push(
<td style={dataCellStyle} key={`h${row}_${index}_1`}>
<pre>{JSON.stringify(node.frontmatter[row])}</pre>
</td>
)
const input = JSON.parse(node.fields.data)[row]
cells.push(
<td style={dataCellStyle} key={`h${row}_${index}_2`}>
<pre>
{typeof input !== 'undefined'
? JSON.stringify(input)
: 'undefined'}
</pre>
</td>
)
})
return <tr key={`row_${row}`}>{cells}</tr>
})}
</tbody>
</table>
<div style={{ marginTop: 20 }}>
<h3>GraphiQL</h3>
<a href={imgUrl}>
<img src={imgUrl} style={{ maxWidth: '100%', height: 'auto' }} />
</a>
</div>
</div>
)
}
}
export default Index
export const pageQuery = graphql`
query IndexQuery {
allMarkdownRemark(sort: { fields: [frontmatter___title] }) {
edges {
node {
fields {
data
}
frontmatter {
title
string
int
date(formatString: "YYYY.MM.DD")
arrayOfString
arrayOfNumbers
notUsedField
customType {
string
int
float
bool
}
mapping {
id
}
localFile {
id
}
union {
__typename
... on File {
relativePath
}
... on MarkdownRemark {
frontmatter {
title
}
}
}
}
}
}
}
}
`