Skip to content

Commit

Permalink
Move visitors back to GraphQLService because of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
wravery committed May 20, 2021
1 parent d6b6e97 commit f0dde15
Show file tree
Hide file tree
Showing 6 changed files with 344 additions and 328 deletions.
1 change: 1 addition & 0 deletions include/ClientGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define CLIENTGENERATOR_H

#include "SchemaLoader.h"
#include "RequestLoader.h"

#include "graphqlservice/GraphQLSchema.h"

Expand Down
60 changes: 5 additions & 55 deletions include/RequestLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,19 @@
#include "graphqlservice/GraphQLParse.h"
#include "graphqlservice/GraphQLService.h"

namespace graphql::runtime {
namespace graphql::generator {

// ValueVisitor visits the AST and builds a response::Value representation of any value
// hardcoded or referencing a variable in an operation.
class ValueVisitor
class RequestLoader
{
public:
GRAPHQLSERVICE_EXPORT ValueVisitor(const response::Value& variables);
explicit RequestLoader();

GRAPHQLSERVICE_EXPORT void visit(const peg::ast_node& value);

GRAPHQLSERVICE_EXPORT response::Value getValue();

private:
void visitVariable(const peg::ast_node& variable);
void visitIntValue(const peg::ast_node& intValue);
void visitFloatValue(const peg::ast_node& floatValue);
void visitStringValue(const peg::ast_node& stringValue);
void visitBooleanValue(const peg::ast_node& booleanValue);
void visitNullValue(const peg::ast_node& nullValue);
void visitEnumValue(const peg::ast_node& enumValue);
void visitListValue(const peg::ast_node& listValue);
void visitObjectValue(const peg::ast_node& objectValue);

const response::Value& _variables;
response::Value _value;
};

// DirectiveVisitor visits the AST and builds a 2-level map of directive names to argument
// name/value pairs.
class DirectiveVisitor
{
public:
GRAPHQLSERVICE_EXPORT explicit DirectiveVisitor(const response::Value& variables);

GRAPHQLSERVICE_EXPORT void visit(const peg::ast_node& directives);

GRAPHQLSERVICE_EXPORT bool shouldSkip() const;
GRAPHQLSERVICE_EXPORT response::Value getDirectives();

private:
const response::Value& _variables;

response::Value _directives;
};

// FragmentDefinitionVisitor visits the AST and collects all of the fragment
// definitions in the document.
class FragmentDefinitionVisitor
{
public:
GRAPHQLSERVICE_EXPORT FragmentDefinitionVisitor(const response::Value& variables);

GRAPHQLSERVICE_EXPORT service::FragmentMap getFragments();

GRAPHQLSERVICE_EXPORT void visit(const peg::ast_node& fragmentDefinition);
void visit(const peg::ast& request, std::string_view operationName);

private:
const response::Value& _variables;

service::FragmentMap _fragments;
};

} /* namespace graphql::runtime */
} /* namespace graphql::generator */

#endif // REQUESTLOADER_H
2 changes: 1 addition & 1 deletion include/SchemaLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ struct SchemaOptions
class SchemaLoader
{
public:
// Initialize the generator with the introspection schema or a custom GraphQL schema.
// Initialize the loader with the introspection schema or a custom GraphQL schema.
explicit SchemaLoader(std::optional<SchemaOptions>&& customSchema);

bool isIntrospection() const noexcept;
Expand Down
5 changes: 3 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ endif()

# clientgen
if(GRAPHQL_BUILD_CLIENTGEN)
add_executable(clientgen ClientGenerator.cpp)
add_executable(clientgen
ClientGenerator.cpp
RequestLoader.cpp)
add_executable(cppgraphqlgen::clientgen ALIAS clientgen)
target_link_libraries(clientgen PRIVATE generator_util)
add_bigobj_flag(clientgen)
Expand Down Expand Up @@ -292,7 +294,6 @@ endif()
add_library(graphqlservice
GraphQLService.cpp
GraphQLSchema.cpp
RequestLoader.cpp
Validation.cpp)
add_library(cppgraphqlgen::graphqlservice ALIAS graphqlservice)
target_link_libraries(graphqlservice PUBLIC
Expand Down
Loading

0 comments on commit f0dde15

Please sign in to comment.