forked from microsoft/cppgraphqlgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxySharedTypes.cpp
More file actions
165 lines (133 loc) · 4.59 KB
/
Copy pathProxySharedTypes.cpp
File metadata and controls
165 lines (133 loc) · 4.59 KB
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
165
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// WARNING! Do not edit this file manually, your changes will be overwritten.
#include "graphqlservice/GraphQLService.h"
#include "ProxySharedTypes.h"
#include <algorithm>
#include <array>
#include <cstddef>
#include <functional>
#include <stdexcept>
#include <string_view>
#include <utility>
#include <vector>
using namespace std::literals;
namespace graphql {
namespace service {
static const auto s_namesOperationType = proxy::getOperationTypeNames();
static const auto s_valuesOperationType = proxy::getOperationTypeValues();
template <>
proxy::OperationType Argument<proxy::OperationType>::convert(const response::Value& value)
{
if (!value.maybe_enum())
{
throw service::schema_exception { { R"ex(not a valid OperationType value)ex" } };
}
const auto result = internal::sorted_map_lookup<internal::shorter_or_less>(
s_valuesOperationType,
std::string_view { value.get<std::string>() });
if (!result)
{
throw service::schema_exception { { R"ex(not a valid OperationType value)ex" } };
}
return *result;
}
template <>
service::AwaitableResolver Result<proxy::OperationType>::convert(service::AwaitableScalar<proxy::OperationType> result, ResolverParams&& params)
{
return ModifiedResult<proxy::OperationType>::resolve(std::move(result), std::move(params),
[](proxy::OperationType value, const ResolverParams&)
{
const auto idx = static_cast<size_t>(value);
if (idx >= s_namesOperationType.size())
{
throw service::schema_exception { { R"ex(Enum value out of range for OperationType)ex" } };
}
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesOperationType[idx] } } } };
});
}
template <>
void Result<proxy::OperationType>::validateScalar(const response::Value& value)
{
if (!value.maybe_enum())
{
throw service::schema_exception { { R"ex(not a valid OperationType value)ex" } };
}
const auto [itr, itrEnd] = internal::sorted_map_equal_range<internal::shorter_or_less>(
s_valuesOperationType.begin(),
s_valuesOperationType.end(),
std::string_view { value.get<std::string>() });
if (itr == itrEnd)
{
throw service::schema_exception { { R"ex(not a valid OperationType value)ex" } };
}
}
template <>
proxy::QueryInput Argument<proxy::QueryInput>::convert(const response::Value& value)
{
auto valueType = service::ModifiedArgument<proxy::OperationType>::require("type", value);
auto valueQuery = service::ModifiedArgument<std::string>::require("query", value);
auto valueOperationName = service::ModifiedArgument<std::string>::require<service::TypeModifier::Nullable>("operationName", value);
auto valueVariables = service::ModifiedArgument<std::string>::require<service::TypeModifier::Nullable>("variables", value);
return proxy::QueryInput {
std::move(valueType),
std::move(valueQuery),
std::move(valueOperationName),
std::move(valueVariables)
};
}
} // namespace service
namespace proxy {
QueryInput::QueryInput() noexcept
: type {}
, query {}
, operationName {}
, variables {}
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}
QueryInput::QueryInput(
OperationType typeArg,
std::string queryArg,
std::optional<std::string> operationNameArg,
std::optional<std::string> variablesArg) noexcept
: type { std::move(typeArg) }
, query { std::move(queryArg) }
, operationName { std::move(operationNameArg) }
, variables { std::move(variablesArg) }
{
}
QueryInput::QueryInput(const QueryInput& other)
: type { service::ModifiedArgument<OperationType>::duplicate(other.type) }
, query { service::ModifiedArgument<std::string>::duplicate(other.query) }
, operationName { service::ModifiedArgument<std::string>::duplicate<service::TypeModifier::Nullable>(other.operationName) }
, variables { service::ModifiedArgument<std::string>::duplicate<service::TypeModifier::Nullable>(other.variables) }
{
}
QueryInput::QueryInput(QueryInput&& other) noexcept
: type { std::move(other.type) }
, query { std::move(other.query) }
, operationName { std::move(other.operationName) }
, variables { std::move(other.variables) }
{
}
QueryInput::~QueryInput()
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}
QueryInput& QueryInput::operator=(const QueryInput& other)
{
QueryInput value { other };
std::swap(*this, value);
return *this;
}
QueryInput& QueryInput::operator=(QueryInput&& other) noexcept
{
type = std::move(other.type);
query = std::move(other.query);
operationName = std::move(other.operationName);
variables = std::move(other.variables);
return *this;
}
} // namespace proxy
} // namespace graphql