66#ifndef SCHEMALOADER_H
77#define SCHEMALOADER_H
88
9+ #include " GeneratorLoader.h"
10+
911#include " graphqlservice/GraphQLGrammar.h"
1012#include " graphqlservice/GraphQLParse.h"
1113#include " graphqlservice/GraphQLService.h"
@@ -31,32 +33,13 @@ using BuiltinTypeMap = std::map<std::string_view, BuiltinType>;
3133// These are the C++ types we'll use for them.
3234using CppTypeMap = std::array<std::string_view, static_cast <size_t >(BuiltinType::ID) + 1 >;
3335
34- // Types that we understand and use to generate the skeleton of a service.
35- enum class SchemaType
36- {
37- Scalar,
38- Enum,
39- Input,
40- Union,
41- Interface,
42- Object,
43- Operation,
44- };
45-
46- using SchemaTypeMap = std::map<std::string_view, SchemaType>;
47-
4836// Keep track of the positions of each type declaration in the file.
4937using PositionMap = std::unordered_map<std::string_view, tao::graphqlpeg::position>;
5038
5139// For all of the named types we track, we want to keep them in order in a vector but
5240// be able to lookup their offset quickly by name.
5341using TypeNameMap = std::unordered_map<std::string_view, size_t >;
5442
55- // Any type can also have a list and/or non-nullable wrapper, and those can be nested.
56- // Since it's easier to express nullability than non-nullability in C++, we'll invert
57- // the presence of NonNull modifiers.
58- using TypeModifierStack = std::vector<service::TypeModifier>;
59-
6043// Scalar types are opaque to the generator, it's up to the service implementation
6144// to handle parsing, validating, and serializing them. We just need to track which
6245// scalar type names have been declared so we recognize the references.
@@ -241,7 +224,7 @@ class SchemaLoader
241224 static const CppTypeMap& getBuiltinCppTypes () noexcept ;
242225 static std::string_view getScalarCppType () noexcept ;
243226
244- const SchemaType& getSchemaType (std::string_view type) const ;
227+ SchemaType getSchemaType (std::string_view type) const ;
245228 const tao::graphqlpeg::position& getTypePosition (std::string_view type) const ;
246229
247230 size_t getScalarIndex (std::string_view type) const ;
@@ -291,47 +274,6 @@ class SchemaLoader
291274 void visitObjectTypeExtension (const peg::ast_node& objectTypeExtension);
292275 void visitDirectiveDefinition (const peg::ast_node& directiveDefinition);
293276
294- // Recursively visit a Type node until we reach a NamedType and we've
295- // taken stock of all of the modifier wrappers.
296- class TypeVisitor
297- {
298- public:
299- std::pair<std::string_view, TypeModifierStack> getType ();
300-
301- void visit (const peg::ast_node& typeName);
302-
303- private:
304- void visitNamedType (const peg::ast_node& namedType);
305- void visitListType (const peg::ast_node& listType);
306- void visitNonNullType (const peg::ast_node& nonNullType);
307-
308- std::string_view _type;
309- TypeModifierStack _modifiers;
310- bool _nonNull = false ;
311- };
312-
313- // Recursively visit a Value node representing the default value on an input field
314- // and build a JSON representation of the hardcoded value.
315- class DefaultValueVisitor
316- {
317- public:
318- response::Value getValue ();
319-
320- void visit (const peg::ast_node& value);
321-
322- private:
323- void visitIntValue (const peg::ast_node& intValue);
324- void visitFloatValue (const peg::ast_node& floatValue);
325- void visitStringValue (const peg::ast_node& stringValue);
326- void visitBooleanValue (const peg::ast_node& booleanValue);
327- void visitNullValue (const peg::ast_node& nullValue);
328- void visitEnumValue (const peg::ast_node& enumValue);
329- void visitListValue (const peg::ast_node& listValue);
330- void visitObjectValue (const peg::ast_node& objectValue);
331-
332- response::Value _value;
333- };
334-
335277 static OutputFieldList getOutputFields (const peg::ast_node::children_t & fields);
336278 static InputFieldList getInputFields (const peg::ast_node::children_t & fields);
337279
0 commit comments