|
5 | 5 | #include "GeneratorUtil.h" |
6 | 6 |
|
7 | 7 | #include "graphqlservice/internal/Version.h" |
| 8 | +#include "graphqlservice/introspection/IntrospectionSchema.h" |
8 | 9 |
|
9 | 10 | #ifdef _MSC_VER |
10 | 11 | #pragma warning(push) |
@@ -169,6 +170,66 @@ static_assert(graphql::internal::MinorVersion == )cpp" |
169 | 170 | PendingBlankLine pendingSeparator { headerFile }; |
170 | 171 |
|
171 | 172 | 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 | + |
172 | 233 | pendingSeparator.reset(); |
173 | 234 |
|
174 | 235 | return true; |
|
0 commit comments