Skip to content

Commit 2b8505b

Browse files
committed
Start emitting some of the Variables struct
1 parent 9b68d65 commit 2b8505b

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

samples/client/MutateClient.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ const std::string& GetRequestText() noexcept;
5353
// Return a pre-parsed, pre-validated request object.
5454
const peg::ast& GetRequestObject() noexcept;
5555

56+
struct CompleteTaskInput;
57+
58+
struct CompleteTaskInput {};
59+
60+
struct Variables
61+
{
62+
CompleteTaskInput input;
63+
};
64+
5665
} /* namespace graphql::mutation::CompleteTaskMutation */
5766

5867
#endif // MUTATECLIENT_H

src/ClientGenerator.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "GeneratorUtil.h"
66

77
#include "graphqlservice/internal/Version.h"
8+
#include "graphqlservice/introspection/IntrospectionSchema.h"
89

910
#ifdef _MSC_VER
1011
#pragma warning(push)
@@ -169,6 +170,66 @@ static_assert(graphql::internal::MinorVersion == )cpp"
169170
PendingBlankLine pendingSeparator { headerFile };
170171

171172
outputGetRequestDeclaration(headerFile);
173+
174+
const auto& variables = _requestLoader.getVariables();
175+
176+
if (!variables.empty())
177+
{
178+
// TODO: Recurse through the variable types and define all of the enums referenced in the variables.
179+
// std::map<std::string_view, std::shared_ptr<const schema::BaseType>> enumTypes;
180+
181+
// TODO: Recurse through the variable types and build a list of referenced input types to forward declare,
182+
// TODO: and output them in alphabetical order. Don't define them yet, since they might have interdependencies.
183+
// std::map<std::string_view, std::shared_ptr<const schema::BaseType>> inputTypes;
184+
185+
// TODO: After forward declaring all of the input type structs, emit the definitions in alphabetical order.
186+
187+
pendingSeparator.reset();
188+
189+
// Forward declare all of the input object structs.
190+
for (const auto& variable : variables)
191+
{
192+
if (variable.type->kind() == introspection::TypeKind::INPUT_OBJECT)
193+
{
194+
headerFile << R"cpp(struct )cpp" << _schemaLoader.getCppType(variable.type->name())
195+
<< R"cpp(;
196+
)cpp";
197+
pendingSeparator.add();
198+
}
199+
}
200+
201+
pendingSeparator.reset();
202+
203+
// Define all of the input object structs.
204+
for (const auto& variable : variables)
205+
{
206+
if (variable.type->kind() == introspection::TypeKind::INPUT_OBJECT)
207+
{
208+
headerFile << R"cpp(struct )cpp" << _schemaLoader.getCppType(variable.type->name())
209+
<< R"cpp( {};
210+
)cpp";
211+
pendingSeparator.add();
212+
}
213+
}
214+
215+
pendingSeparator.reset();
216+
217+
headerFile << R"cpp(struct Variables
218+
{
219+
)cpp";
220+
221+
for (const auto& variable : variables)
222+
{
223+
headerFile << R"cpp( )cpp" << _schemaLoader.getCppType(variable.type->name())
224+
<< R"cpp( )cpp" << variable.cppName << R"cpp(;
225+
)cpp";
226+
}
227+
228+
headerFile << R"cpp(};
229+
230+
)cpp";
231+
}
232+
172233
pendingSeparator.reset();
173234

174235
return true;

0 commit comments

Comments
 (0)