forked from grafana/postman-to-k6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphql.js
82 lines (71 loc) · 1.52 KB
/
graphql.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
import test from 'ava'
import convertFile from 'convert/file'
function render (body) {
const content = JSON.stringify(body)
const escaped = content.replace(/\\/g, '\\\\')
return `'${escaped}'`
}
test('body simple', async t => {
const [ main ] = await convertFile(
'test/material/2.1/graphql-body-simple.json'
)
const query = '' +
`{
user {
name
}
}`
const body = { query }
t.is(main, `// Auto-generated by the Load Impact converter
import "./libs/shim/core.js";
export let options = { maxRedirects: 4 };
const Request = Symbol.for("request");
postman[Symbol.for("initial")]({
options
});
export default function() {
postman[Request]({
name: "Test Request",
method: "POST",
address: "http://graphql.example.com/",
data: ${render(body)}
});
}
`)
})
test('body var', async t => {
const [ main ] = await convertFile(
'test/material/2.1/graphql-body-var.json'
)
const query = '' +
`query UserName($id: UserId) {
user(id: $id) {
name
}
}`
const variables = '' +
`{
\t"id": "{{userId}}"
}`
const body = { query, variables }
t.is(main, `// Auto-generated by the Load Impact converter
import "./libs/shim/core.js";
export let options = { maxRedirects: 4 };
const Request = Symbol.for("request");
postman[Symbol.for("initial")]({
options,
collection: {
userId: "5"
}
});
export default function() {
postman[Request]({
name: "Test Request",
method: "POST",
address: "http://graphql.example.com/",
data:
${render(body)}
});
}
`)
})