forked from vinsol/spree_graphql_playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_script.rb
164 lines (152 loc) · 2.44 KB
/
test_script.rb
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
require_relative 'lib/spree_graphql'
require 'pp'
query1 = <<-GRAPHQL
{
product_with_id: product(id: 3) {
id
name
master {
id
sku
}
variants {
id
sku
}
}
product_filtered_by_id: products(ids: [1, 3]) {
id
name
master {
id
sku
}
variants {
id
sku
products {
name
}
}
}
}
GRAPHQL
query2 = <<-GRAPHQL
{
me: user(id: 2) {
email
orders {
id
line_items {
id
variant {
name
}
}
}
}
}
GRAPHQL
query_with_fragment = <<-GRAPHQL
query getProducts {
product_1: product(id: 1) {
... productDetails
}
product_2: product(id: 2) {
... productDetails
}
}
fragment productDetails on Product {
id
name
master {
id
}
}
GRAPHQL
product_taxon_example = <<-GRAPHQL
{
pr: product(id: 3) {
classification {
taxon {
name
products {
name
}
}
}
}
}
GRAPHQL
# Can be a huge hit on DB!!
products_by_taxon_example = <<-GRAPHQL
{
products: taxons {
name
id
products {
name
master {
id
}
classification {
position
taxon {
id
name
products {
name
}
}
}
}
}
}
GRAPHQL
all_products = <<-GRAPHQL
{
products {
name
classification {
taxon {
pretty_name
name
}
}
}
}
GRAPHQL
partial = <<-GRAPHQL
{
t1: taxons(page: 1, per_page: 1) {
name
products {
name
master {
sku
}
variants {
name
}
}
}
taxon_list: taxons {
id
name
}
}
GRAPHQL
# puts "Introspection Result"
# pp SpreeSchema.execute(GraphQL::Introspection::INTROSPECTION_QUERY)
admin_token = '49b9a05392f74da503346207a6ce157482e6be92db444726'
regular_token = '1ace9f313ace13c8d86a80819f4b65ed117865116ff55ff3'
# puts "Running Query 1"
# pp SpreeSchema.execute(query1, context: { token: regular_token })
# puts "Running Query 2"
# pp SpreeSchema.execute(query2, context: { token: regular_token })
# puts "Running Query with fragments"
pp SpreeSchema.execute(products_by_taxon_example, context: { token: regular_token })
# puts "Running Product with taxon"
# pp SpreeSchema.execute(partial, context: { token: regular_token })
# puts "Fetching products by taxon ids"
# pp SpreeSchema.execute(query_with_fragment, context: { token: regular_token })