Skip to content

Commit 68d0812

Browse files
committed
Add enum serialize/parse and start on input serialize
1 parent eaa0619 commit 68d0812

20 files changed

+436
-126
lines changed

samples/CMakeLists.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ target_compile_definitions(separateschema PUBLIC IMPL_SEPARATE_TODAY)
171171
target_include_directories(separateschema PUBLIC
172172
${CMAKE_CURRENT_SOURCE_DIR}/../include
173173
${CMAKE_CURRENT_SOURCE_DIR}/../PEGTL/include
174-
separate)
174+
${CMAKE_CURRENT_SOURCE_DIR}/separate)
175175

176176
if(GRAPHQL_UPDATE_SAMPLES)
177177
# wait for the sample update to complete
@@ -191,7 +191,7 @@ target_compile_definitions(separateschema_nointrospection PUBLIC IMPL_SEPARATE_T
191191
target_include_directories(separateschema_nointrospection PUBLIC
192192
${CMAKE_CURRENT_SOURCE_DIR}/../include
193193
${CMAKE_CURRENT_SOURCE_DIR}/../PEGTL/include
194-
separate_nointrospection)
194+
${CMAKE_CURRENT_SOURCE_DIR}/separate_nointrospection)
195195

196196
if(GRAPHQL_UPDATE_SAMPLES)
197197
# wait for the sample update to complete
@@ -274,12 +274,12 @@ endif()
274274

275275
if(GRAPHQL_BUILD_TESTS)
276276
# tests
277-
add_library(unifiedschema STATIC unified/TodaySchema.cpp)
277+
add_library(unifiedschema STATIC ${CMAKE_CURRENT_SOURCE_DIR}/unified/TodaySchema.cpp)
278278
target_link_libraries(unifiedschema PUBLIC graphqlintrospection)
279279
target_include_directories(unifiedschema PUBLIC
280280
${CMAKE_CURRENT_SOURCE_DIR}/../include
281281
${CMAKE_CURRENT_SOURCE_DIR}/../PEGTL/include
282-
unified)
282+
${CMAKE_CURRENT_SOURCE_DIR}/unified)
283283

284284
if(GRAPHQL_UPDATE_SAMPLES)
285285
# wait for the sample update to complete
@@ -291,12 +291,12 @@ if(GRAPHQL_BUILD_TESTS)
291291
target_include_directories(unifiedgraphql PUBLIC today)
292292
add_bigobj_flag(unifiedgraphql)
293293

294-
add_library(unifiedschema_nointrospection STATIC unified_nointrospection/TodaySchema.cpp)
294+
add_library(unifiedschema_nointrospection STATIC ${CMAKE_CURRENT_SOURCE_DIR}/unified_nointrospection/TodaySchema.cpp)
295295
target_link_libraries(unifiedschema_nointrospection PUBLIC graphqlservice)
296296
target_include_directories(unifiedschema_nointrospection PUBLIC
297297
${CMAKE_CURRENT_SOURCE_DIR}/../include
298298
${CMAKE_CURRENT_SOURCE_DIR}/../PEGTL/include
299-
unified_nointrospection)
299+
${CMAKE_CURRENT_SOURCE_DIR}/unified_nointrospection)
300300

301301
if(GRAPHQL_UPDATE_SAMPLES)
302302
# wait for the sample update to complete
@@ -309,13 +309,13 @@ if(GRAPHQL_BUILD_TESTS)
309309
add_bigobj_flag(unifiedgraphql_nointrospection)
310310

311311
add_library(validationgraphql STATIC
312-
validation/ValidationMock.cpp
313-
validation/ValidationSchema.cpp)
312+
${CMAKE_CURRENT_SOURCE_DIR}/validation/ValidationMock.cpp
313+
${CMAKE_CURRENT_SOURCE_DIR}/validation/ValidationSchema.cpp)
314314
target_link_libraries(validationgraphql PUBLIC graphqlintrospection)
315315
target_include_directories(validationgraphql PUBLIC
316316
${CMAKE_CURRENT_SOURCE_DIR}/../include
317317
${CMAKE_CURRENT_SOURCE_DIR}/../PEGTL/include
318-
validation)
318+
${CMAKE_CURRENT_SOURCE_DIR}/validation)
319319
add_bigobj_flag(validationgraphql)
320320

321321
if(GRAPHQL_UPDATE_SAMPLES)
@@ -327,16 +327,16 @@ endif()
327327
if(GRAPHQL_BUILD_CLIENTGEN)
328328
# todayclient
329329
add_library(todayclient STATIC
330-
client/QueryClient.cpp
331-
client/MutateClient.cpp
332-
client/SubscribeClient.cpp)
330+
${CMAKE_CURRENT_SOURCE_DIR}/client/QueryClient.cpp
331+
${CMAKE_CURRENT_SOURCE_DIR}/client/MutateClient.cpp
332+
${CMAKE_CURRENT_SOURCE_DIR}/client/SubscribeClient.cpp)
333333
target_link_libraries(todayclient PUBLIC
334334
graphqlpeg
335335
graphqlresponse)
336336
target_include_directories(todayclient PUBLIC
337337
${CMAKE_CURRENT_SOURCE_DIR}/../include
338338
${CMAKE_CURRENT_SOURCE_DIR}/../PEGTL/include
339-
client)
339+
${CMAKE_CURRENT_SOURCE_DIR}/client)
340340

341341
if(GRAPHQL_UPDATE_SAMPLES)
342342
# wait for the sample update to complete

samples/client/MutateClient.cpp

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#include "MutateClient.h"
77

8+
#include "graphqlservice/GraphQLService.h"
9+
810
#include <algorithm>
911
#include <array>
10-
#include <functional>
1112
#include <sstream>
12-
#include <stdexcept>
1313
#include <string_view>
1414

1515
using namespace std::literals;
@@ -51,4 +51,67 @@ const peg::ast& GetRequestObject() noexcept
5151
return s_request;
5252
}
5353

54+
static const std::array<std::string_view, 4> s_namesTaskState = {
55+
"New"sv,
56+
"Started"sv,
57+
"Complete"sv,
58+
"Unassigned"sv,
59+
};
60+
61+
response::Value serializeTaskState(TaskState value)
62+
{
63+
response::Value result(response::Type::EnumValue);
64+
65+
result.set<response::StringType>(response::StringType { s_namesTaskState[static_cast<size_t>(value)] });
66+
67+
return result;
68+
}
69+
70+
response::Value serializeCompleteTaskInput(Variables::CompleteTaskInput&& inputValue)
71+
{
72+
response::Value result;
73+
74+
// response::IdType id;
75+
// std::optional<TaskState> testTaskState;
76+
// std::optional<response::BooleanType> isComplete;
77+
// std::optional<response::StringType> clientMutationId;
78+
79+
return result;
80+
}
81+
82+
response::Value serializeVariables(Variables&& variables)
83+
{
84+
response::Value result;
85+
86+
// input = serializeCompleteTaskInput(std::move(variables.input));
87+
88+
return result;
89+
}
90+
91+
TaskState parseTaskState(const response::Value& value)
92+
{
93+
if (!value.maybe_enum())
94+
{
95+
throw service::schema_exception { { "not a valid TaskState value" } };
96+
}
97+
98+
const auto itr = std::find(s_namesTaskState.cbegin(), s_namesTaskState.cend(), value.get<response::StringType>());
99+
100+
if (itr == s_namesTaskState.cend())
101+
{
102+
throw service::schema_exception { { "not a valid TaskState value" } };
103+
}
104+
105+
return static_cast<TaskState>(itr - s_namesTaskState.cbegin());
106+
}
107+
108+
Response parseResponse(response::Value&& response)
109+
{
110+
Response result;
111+
112+
// completedTask_CompleteTaskPayload completedTask;
113+
114+
return result;
115+
}
116+
54117
} /* namespace graphql::mutation::CompleteTaskMutation */

samples/client/MutateClient.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ static_assert(graphql::internal::MinorVersion == 6, "regenerate with clientgen:
2424

2525
#include <optional>
2626
#include <string>
27-
#include <variant>
2827
#include <vector>
2928

3029
namespace graphql::mutation::CompleteTaskMutation {
@@ -53,18 +52,29 @@ const std::string& GetRequestText() noexcept;
5352
// Return a pre-parsed, pre-validated request object.
5453
const peg::ast& GetRequestObject() noexcept;
5554

56-
struct CompleteTaskInput
55+
enum class TaskState
5756
{
58-
response::IdType id;
59-
std::optional<response::BooleanType> isComplete;
60-
std::optional<response::StringType> clientMutationId;
57+
New,
58+
Started,
59+
Complete,
60+
Unassigned,
6161
};
6262

6363
struct Variables
6464
{
65+
struct CompleteTaskInput
66+
{
67+
response::IdType id;
68+
std::optional<TaskState> testTaskState;
69+
std::optional<response::BooleanType> isComplete;
70+
std::optional<response::StringType> clientMutationId;
71+
};
72+
6573
CompleteTaskInput input;
6674
};
6775

76+
response::Value serializeVariables(Variables&& variables);
77+
6878
struct Response
6979
{
7080
struct completedTask_CompleteTaskPayload
@@ -84,6 +94,8 @@ struct Response
8494
completedTask_CompleteTaskPayload completedTask;
8595
};
8696

97+
Response parseResponse(response::Value&& response);
98+
8799
} /* namespace graphql::mutation::CompleteTaskMutation */
88100

89101
#endif // MUTATECLIENT_H

samples/client/QueryClient.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#include "QueryClient.h"
77

8+
#include "graphqlservice/GraphQLService.h"
9+
810
#include <algorithm>
911
#include <array>
10-
#include <functional>
1112
#include <sstream>
12-
#include <stdexcept>
1313
#include <string_view>
1414

1515
using namespace std::literals;
@@ -77,4 +77,40 @@ const peg::ast& GetRequestObject() noexcept
7777
return s_request;
7878
}
7979

80+
static const std::array<std::string_view, 4> s_namesTaskState = {
81+
"New"sv,
82+
"Started"sv,
83+
"Complete"sv,
84+
"Unassigned"sv,
85+
};
86+
87+
TaskState parseTaskState(const response::Value& value)
88+
{
89+
if (!value.maybe_enum())
90+
{
91+
throw service::schema_exception { { "not a valid TaskState value" } };
92+
}
93+
94+
const auto itr = std::find(s_namesTaskState.cbegin(), s_namesTaskState.cend(), value.get<response::StringType>());
95+
96+
if (itr == s_namesTaskState.cend())
97+
{
98+
throw service::schema_exception { { "not a valid TaskState value" } };
99+
}
100+
101+
return static_cast<TaskState>(itr - s_namesTaskState.cbegin());
102+
}
103+
104+
Response parseResponse(response::Value&& response)
105+
{
106+
Response result;
107+
108+
// appointments_AppointmentConnection appointments;
109+
// tasks_TaskConnection tasks;
110+
// unreadCounts_FolderConnection unreadCounts;
111+
// std::optional<TaskState> testTaskState;
112+
113+
return result;
114+
}
115+
80116
} /* namespace graphql::query::Query */

samples/client/QueryClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ static_assert(graphql::internal::MinorVersion == 6, "regenerate with clientgen:
2424

2525
#include <optional>
2626
#include <string>
27-
#include <variant>
2827
#include <vector>
2928

3029
namespace graphql::query::Query {
@@ -153,6 +152,8 @@ struct Response
153152
std::optional<TaskState> testTaskState;
154153
};
155154

155+
Response parseResponse(response::Value&& response);
156+
156157
} /* namespace graphql::query::Query */
157158

158159
#endif // QUERYCLIENT_H

samples/client/SubscribeClient.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#include "SubscribeClient.h"
77

8+
#include "graphqlservice/GraphQLService.h"
9+
810
#include <algorithm>
911
#include <array>
10-
#include <functional>
1112
#include <sstream>
12-
#include <stdexcept>
1313
#include <string_view>
1414

1515
using namespace std::literals;
@@ -49,4 +49,13 @@ const peg::ast& GetRequestObject() noexcept
4949
return s_request;
5050
}
5151

52+
Response parseResponse(response::Value&& response)
53+
{
54+
Response result;
55+
56+
// std::optional<nextAppointment_Appointment> nextAppointment;
57+
58+
return result;
59+
}
60+
5261
} /* namespace graphql::subscription::TestSubscription */

samples/client/SubscribeClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ static_assert(graphql::internal::MinorVersion == 6, "regenerate with clientgen:
2424

2525
#include <optional>
2626
#include <string>
27-
#include <variant>
2827
#include <vector>
2928

3029
namespace graphql::subscription::TestSubscription {
@@ -64,6 +63,8 @@ struct Response
6463
std::optional<nextAppointment_Appointment> nextAppointment;
6564
};
6665

66+
Response parseResponse(response::Value&& response);
67+
6768
} /* namespace graphql::subscription::TestSubscription */
6869

6970
#endif // SUBSCRIBECLIENT_H

samples/schema.today.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type FolderConnection {
7878

7979
input CompleteTaskInput {
8080
id: ID!
81+
testTaskState: TaskState
8182
isComplete: Boolean = true
8283
clientMutationId: String
8384
}

0 commit comments

Comments
 (0)