Skip to content

Commit 7355979

Browse files
committed
Fill in RequestLoader versions of getInputCppType and getOutputCppType
1 parent e220447 commit 7355979

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

src/RequestLoader.cpp

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ std::string RequestLoader::getInputCppType(const RequestVariable& variable) cons
155155
}
156156
}
157157

158-
inputType << getCppType(field.type);
158+
inputType << _schemaLoader.getCppType(variable.type->name());
159159

160160
for (size_t i = 0; i < templateCount; ++i)
161161
{
@@ -167,7 +167,63 @@ std::string RequestLoader::getInputCppType(const RequestVariable& variable) cons
167167

168168
std::string RequestLoader::getOutputCppType(const ResponseField& field) const noexcept
169169
{
170+
bool nonNull = true;
171+
size_t templateCount = 0;
172+
std::ostringstream outputType;
173+
174+
for (auto modifier : field.modifiers)
175+
{
176+
if (!nonNull)
177+
{
178+
outputType << R"cpp(std::optional<)cpp";
179+
++templateCount;
180+
}
181+
182+
switch (modifier)
183+
{
184+
case service::TypeModifier::None:
185+
nonNull = true;
186+
break;
187+
188+
case service::TypeModifier::Nullable:
189+
nonNull = false;
190+
break;
191+
192+
case service::TypeModifier::List:
193+
nonNull = true;
194+
outputType << R"cpp(std::vector<)cpp";
195+
++templateCount;
196+
break;
197+
}
198+
}
199+
200+
switch (field.type->kind())
201+
{
202+
case introspection::TypeKind::OBJECT:
203+
case introspection::TypeKind::UNION:
204+
case introspection::TypeKind::INTERFACE:
205+
// Even if it's non-nullable, we still want to return a shared_ptr for complex types
206+
outputType << R"cpp(std::shared_ptr<)cpp";
207+
++templateCount;
208+
break;
209+
210+
default:
211+
if (!nonNull)
212+
{
213+
outputType << R"cpp(std::optional<)cpp";
214+
++templateCount;
215+
}
216+
break;
217+
}
218+
219+
outputType << _schemaLoader.getCppType(field.type->name());
220+
221+
for (size_t i = 0; i < templateCount; ++i)
222+
{
223+
outputType << R"cpp(>)cpp";
224+
}
170225

226+
return outputType.str();
171227
}
172228

173229
void RequestLoader::buildSchema()

0 commit comments

Comments
 (0)