@@ -17,59 +17,73 @@ using namespace std::literals;
17
17
18
18
namespace graphql ::service {
19
19
20
- void addErrorMessage (std::string&& message, response::Value& error )
20
+ response::ValueTokenStream addErrorMessage (std::string&& message)
21
21
{
22
- error.emplace_back (std::string { strMessage }, response::Value (std::move (message)));
22
+ response::ValueTokenStream result {};
23
+
24
+ result.push_back (response::ValueToken::AddMember { std::string { strMessage } });
25
+ result.push_back (response::ValueToken::StringValue { std::move (message) });
26
+
27
+ return result;
23
28
}
24
29
25
- void addErrorLocation (const schema_location& location, response::Value& error )
30
+ response::ValueTokenStream addErrorLocation (const schema_location& location)
26
31
{
32
+ response::ValueTokenStream result {};
33
+
27
34
if (location.line == 0 )
28
35
{
29
- return ;
36
+ return result ;
30
37
}
31
38
32
- response::Value errorLocation (response::Type::Map );
39
+ result. push_back ( response::ValueToken::AddMember { std::string { strLocations } } );
33
40
34
- errorLocation.reserve (2 );
35
- errorLocation.emplace_back (std::string { strLine },
36
- response::Value (static_cast <int >(location.line )));
37
- errorLocation.emplace_back (std::string { strColumn },
38
- response::Value (static_cast <int >(location.column )));
41
+ result.push_back (response::ValueToken::StartArray {});
42
+ result.push_back (response::ValueToken::Reserve { 1 });
43
+ result.push_back (response::ValueToken::StartObject {});
44
+ result.push_back (response::ValueToken::Reserve { 2 });
39
45
40
- response::Value errorLocations (response::Type::List);
46
+ result.push_back (response::ValueToken::AddMember { std::string { strLine } });
47
+ result.push_back (response::ValueToken::IntValue { static_cast <int >(location.line ) });
48
+ result.push_back (response::ValueToken::AddMember { std::string { strColumn } });
49
+ result.push_back (response::ValueToken::IntValue { static_cast <int >(location.column ) });
41
50
42
- errorLocations. reserve ( 1 );
43
- errorLocations. emplace_back ( std::move (errorLocation) );
51
+ result. push_back (response::ValueToken::EndObject {} );
52
+ result. push_back (response::ValueToken::EndArray {} );
44
53
45
- error. emplace_back (std::string { strLocations }, std::move (errorLocations)) ;
54
+ return result ;
46
55
}
47
56
48
- void addErrorPath (const error_path& path, response::Value& error )
57
+ response::ValueTokenStream addErrorPath (const error_path& path)
49
58
{
59
+ response::ValueTokenStream result {};
60
+
50
61
if (path.empty ())
51
62
{
52
- return ;
63
+ return result ;
53
64
}
54
65
55
- response::Value errorPath (response::Type::List);
66
+ result.push_back (response::ValueToken::AddMember { std::string { strPath } });
67
+ result.push_back (response::ValueToken::StartArray {});
68
+ result.push_back (response::ValueToken::Reserve { path.size () });
56
69
57
- errorPath.reserve (path.size ());
58
70
for (const auto & segment : path)
59
71
{
60
72
if (std::holds_alternative<std::string_view>(segment))
61
73
{
62
- errorPath. emplace_back (
63
- response::Value { std::string { std::get<std::string_view>(segment) } });
74
+ result. push_back (response::ValueToken::StringValue {
75
+ std::string { std::get<std::string_view>(segment) } });
64
76
}
65
77
else if (std::holds_alternative<std::size_t >(segment))
66
78
{
67
- errorPath. emplace_back (
68
- response::Value ( static_cast <int >(std::get<std::size_t >(segment))) );
79
+ result. push_back (response::ValueToken::IntValue {
80
+ static_cast <int >(std::get<std::size_t >(segment)) } );
69
81
}
70
82
}
71
83
72
- error.emplace_back (std::string { strPath }, std::move (errorPath));
84
+ result.push_back (response::ValueToken::EndArray {});
85
+
86
+ return result;
73
87
}
74
88
75
89
error_path buildErrorPath (const std::optional<field_path>& path)
@@ -99,22 +113,30 @@ error_path buildErrorPath(const std::optional<field_path>& path)
99
113
100
114
response::Value buildErrorValues (std::list<schema_error>&& structuredErrors)
101
115
{
102
- response::Value errors (response::Type::List);
116
+ return visitErrorValues (std::move (structuredErrors)).value ();
117
+ }
118
+
119
+ response::ValueTokenStream visitErrorValues (std::list<schema_error>&& structuredErrors)
120
+ {
121
+ response::ValueTokenStream errors;
103
122
104
- errors.reserve (structuredErrors.size ());
123
+ errors.push_back (response::ValueToken::StartArray {});
124
+ errors.push_back (response::ValueToken::Reserve { structuredErrors.size () });
105
125
106
126
for (auto & error : structuredErrors)
107
127
{
108
- response::Value entry (response::Type::Map);
128
+ errors.push_back (response::ValueToken::StartObject {});
129
+ errors.push_back (response::ValueToken::Reserve { 3 });
109
130
110
- entry.reserve (3 );
111
- addErrorMessage (std::move (error.message ), entry);
112
- addErrorLocation (error.location , entry);
113
- addErrorPath (error.path , entry);
131
+ errors.append (addErrorMessage (std::move (error.message )));
132
+ errors.append (addErrorLocation (error.location ));
133
+ errors.append (addErrorPath (error.path ));
114
134
115
- errors.emplace_back ( std::move (entry) );
135
+ errors.push_back (response::ValueToken::EndObject {} );
116
136
}
117
137
138
+ errors.push_back (response::ValueToken::EndArray {});
139
+
118
140
return errors;
119
141
}
120
142
@@ -245,17 +267,17 @@ void await_worker_queue::resumePending()
245
267
// Default to immediate synchronous execution.
246
268
await_async::await_async ()
247
269
: _pimpl { std::static_pointer_cast<const Concept>(
248
- std::make_shared<Model<std::suspend_never>>(std::make_shared<std::suspend_never>())) }
270
+ std::make_shared<Model<std::suspend_never>>(std::make_shared<std::suspend_never>())) }
249
271
{
250
272
}
251
273
252
274
// Implicitly convert a std::launch parameter used with std::async to an awaitable.
253
275
await_async::await_async (std::launch launch)
254
276
: _pimpl { ((launch & std::launch::async) == std::launch::async)
255
277
? std::static_pointer_cast<const Concept>(std::make_shared<Model<await_worker_thread>>(
256
- std::make_shared<await_worker_thread>()))
278
+ std::make_shared<await_worker_thread>()))
257
279
: std::static_pointer_cast<const Concept>(std::make_shared<Model<std::suspend_never>>(
258
- std::make_shared<std::suspend_never>())) }
280
+ std::make_shared<std::suspend_never>())) }
259
281
{
260
282
}
261
283
@@ -623,16 +645,25 @@ schema_location ResolverParams::getLocation() const
623
645
624
646
response::Value ResolverResult::document () &&
625
647
{
626
- response::Value document { response::Type::Map };
648
+ return std::move (*this ).visit ().value ();
649
+ }
627
650
628
- document.emplace_back (std::string { strData }, std::move (data).value ());
651
+ response::ValueTokenStream ResolverResult::visit () &&
652
+ {
653
+ response::ValueTokenStream result { response::ValueToken::StartObject {} };
654
+
655
+ result.push_back (response::ValueToken::AddMember { std::string { strData } });
656
+ result.append (std::move (data));
629
657
630
658
if (!errors.empty ())
631
659
{
632
- document.emplace_back (std::string { strErrors }, buildErrorValues (std::move (errors)));
660
+ result.push_back (response::ValueToken::AddMember { std::string { strErrors } });
661
+ result.append (visitErrorValues (std::move (errors)));
633
662
}
634
663
635
- return document;
664
+ result.push_back (response::ValueToken::EndObject {});
665
+
666
+ return result;
636
667
}
637
668
638
669
template <>
0 commit comments