Skip to content

Commit 3435894

Browse files
author
rafalh
committed
Benachmark prepare
1 parent b1a4d0a commit 3435894

File tree

9 files changed

+88
-6
lines changed

9 files changed

+88
-6
lines changed

include/graphqlservice/JSONResponse.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
#define JSONRESPONSE_H
88

99
#include "GraphQLResponse.h"
10+
#include "GraphQLService.h"
1011

1112
#include "internal/DllExports.h"
1213

1314
namespace graphql::response {
1415

1516
[[nodiscard("unnecessary conversion")]] JSONRESPONSE_EXPORT std::string toJSON(Value&& response);
17+
[[nodiscard("unnecessary conversion")]] JSONRESPONSE_EXPORT std::string toJSON(service::ResolverResult&& response);
1618

1719
[[nodiscard("unnecessary conversion")]] JSONRESPONSE_EXPORT Value parseJSON(
1820
const std::string& json);

samples/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ if(GRAPHQL_BUILD_MODULES)
1414
add_subdirectory(stitched)
1515
endif()
1616

17+
18+
add_subdirectory(extended)
19+
1720
add_subdirectory(validation)
1821

1922
if(GRAPHQL_BUILD_HTTP_SAMPLE)

samples/proxy/schema/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ enum OperationType {
1111
SUBSCRIPTION
1212
}
1313

14+
15+
1416
input QueryInput {
1517
type: OperationType!
1618
query: String!

samples/today/benchmark.cpp

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,60 @@ int main(int argc, char** argv)
117117
}
118118

119119
const auto startResolve = std::chrono::steady_clock::now();
120-
auto response = service->resolve({ query }).get();
121-
const auto startToJson = std::chrono::steady_clock::now();
122120

123-
if (response::toJSON(std::move(response)).empty())
121+
decltype(std::chrono::steady_clock::now()) startToJson;
122+
123+
124+
125+
/*
126+
Z tego zrobić test
127+
std::string a = response::toJSON(service->visit({ query }).get());
128+
std::string b = response::toJSON(service->resolve({ query }).get());
129+
130+
std::cout << "Visit: " << a << std::endl;
131+
std::cout << "Resolve: " << b << std::endl;
132+
133+
if (a.compare(b) != 0)
124134
{
125-
std::cerr << "Failed to convert to JSON!" << std::endl;
126-
break;
135+
std::cout << "Visit"
136+
<< " is not "
137+
<< "Resolve" << std::endl;
127138
}
139+
else
140+
{
141+
std::cout << "Visit is equal Resolve" << std::endl;
142+
}*/
143+
144+
145+
146+
if (1)
147+
{
148+
auto resolverResult = service->visit({ query }).get();
149+
startToJson = std::chrono::steady_clock::now();
150+
151+
if (response::toJSON(std::move(resolverResult)).empty())
152+
{
153+
std::cerr << "Failed to convert to JSON!" << std::endl;
154+
break;
155+
}
156+
}
157+
else
158+
{
159+
auto response = service->resolve({ query }).get();
160+
startToJson = std::chrono::steady_clock::now();
161+
162+
if (response::toJSON(std::move(response)).empty())
163+
{
164+
std::cerr << "Failed to convert to JSON!" << std::endl;
165+
break;
166+
}
167+
}
168+
169+
170+
171+
172+
173+
128174

129175
const auto endToJson = std::chrono::steady_clock::now();
130176

samples/today/schema.today.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type Query {
4040

4141
"Test C++ keyword names"
4242
default: String
43+
44+
4345
}
4446

4547
"Node interface for Relay support"

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ endif()
404404
if(BUILD_GRAPHQLJSON)
405405
add_library(cppgraphqlgen::graphqljson ALIAS graphqljson)
406406
target_compile_features(graphqljson PUBLIC cxx_std_20)
407-
target_link_libraries(graphqljson PUBLIC graphqlresponse)
407+
target_link_libraries(graphqljson PUBLIC graphqlresponse graphqlservice)
408408
target_sources(graphqljson PUBLIC FILE_SET HEADERS
409409
BASE_DIRS ${INCLUDE_ROOT}
410410
FILES ${INCLUDE_ROOT}/graphqlservice/JSONResponse.h)

src/RapidJSONResponse.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ class StreamWriter : public std::enable_shared_from_this<StreamWriter>
103103
rapidjson::Writer<rapidjson::StringBuffer> _writer;
104104
};
105105

106+
std::string toJSON(service::ResolverResult&& response)
107+
{
108+
std::ostringstream stream;
109+
auto writer = std::make_shared<ValueVisitor>(std::make_shared<StreamWriter>(stream));
110+
111+
std::move(response).visit().visit(writer);
112+
113+
return stream.str();
114+
}
115+
106116
std::string toJSON(Value&& response)
107117
{
108118
rapidjson::StringBuffer buffer;

src/SchemaLoader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,10 @@ void SchemaLoader::visitObjectTypeExtension(const peg::ast_node& objectTypeExten
655655
}
656656
}
657657
}
658+
else
659+
{
660+
visitObjectTypeDefinition(objectTypeExtension);
661+
}
658662
}
659663

660664
void SchemaLoader::visitInterfaceTypeDefinition(const peg::ast_node& interfaceTypeDefinition)

src/TaoCppJSONResponse.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@ class StreamWriter : public std::enable_shared_from_this<StreamWriter>
137137
std::vector<Scope> _scopeStack;
138138
};
139139

140+
141+
142+
143+
std::string toJSON(service::ResolverResult&& response)
144+
{
145+
std::ostringstream stream;
146+
auto writer = std::make_shared<ValueVisitor>(std::make_shared<StreamWriter>(stream));
147+
148+
std::move(response).visit().visit(writer);
149+
150+
return stream.str();
151+
}
152+
140153
std::string toJSON(Value&& response)
141154
{
142155
std::ostringstream stream;

0 commit comments

Comments
 (0)