-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
query_parser.clj
67 lines (54 loc) · 1.66 KB
/
query_parser.clj
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
(ns graphql-clj-bench.query-parser
(:require [perforate.core :refer [defgoal defcase]]
[graphql-clj.parser :as ql]))
(defgoal query-parser-performance
"Verifying GraphQL query parser performance.")
(defcase query-parser-performance :simple-query
[]
(ql/parse "{ a { b { c,d } } }"))
(defcase query-parser-performance :simple-query-with-explicit-operation
[]
(ql/parse "query { a { b { c,d } } }"))
(defcase query-parser-performance :simple-query-with-explicit-name
[]
(ql/parse "query Q { a { b { c,d } } }"))
(defcase query-parser-performance :query-with-fragment-spread
[]
(ql/parse "{ a { b { ... fr } } } fragment fr on B { c,d }"))
(defcase query-parser-performance :query-with-inline-spread
[]
(ql/parse "{ a { b { ... on B { c,d } } } }"))
(defcase query-parser-performance :query-with-parameterized-fields
[]
(ql/parse "{ a { b(id: 10) { c,d } } }"))
(defcase query-parser-performance :query-with-parameterized-fields-and-variables
[]
(ql/parse "query Q($id: ID) { a { b(id: $id) { c,d } } }"))
(def complex-query
"{
newestUsers { name, image },
topUser: firstUser (sort: \"rank\", order: \"desc\") {
name,
projects {
__type,
name,
...Spreadsheet,
...Painting
}
}
}
fragment Spreadsheet on SpreadsheetProject {
rowCount,
columnCount
}
fragment Paiting on PaintingProject {
dominantColor { name, hexCode }
}
")
(defcase query-parser-performance :complex-query
[]
(ql/parse complex-query))
(let [parser-fn @#'ql/parser-fn]
(defcase query-parser-performance :complex-query-instaparse-only
[]
(parser-fn complex-query)))