Skip to content

Commit a7c90f6

Browse files
committed
Move request parsing and validation to RequestLoader
1 parent f0dde15 commit a7c90f6

File tree

5 files changed

+480
-468
lines changed

5 files changed

+480
-468
lines changed

include/ClientGenerator.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
#ifndef CLIENTGENERATOR_H
77
#define CLIENTGENERATOR_H
88

9-
#include "SchemaLoader.h"
109
#include "RequestLoader.h"
1110

12-
#include "graphqlservice/GraphQLSchema.h"
13-
1411
namespace graphql::generator::client {
1512

1613
struct GeneratorPaths
@@ -21,18 +18,15 @@ struct GeneratorPaths
2118

2219
struct GeneratorOptions
2320
{
24-
const std::string requestFilename;
25-
const std::string operationName;
2621
const std::optional<GeneratorPaths> paths;
2722
const bool verbose = false;
28-
const bool noIntrospection = false;
2923
};
3024

3125
class Generator
3226
{
3327
public:
3428
// Initialize the generator with the introspection client or a custom GraphQL client.
35-
explicit Generator(SchemaOptions&& schemaOptions, GeneratorOptions&& options);
29+
explicit Generator(SchemaOptions&& schemaOptions, RequestOptions&& requestOptions, GeneratorOptions&& options);
3630

3731
// Run the generator and return a list of filenames that were output.
3832
std::vector<std::string> Build() const noexcept;
@@ -43,10 +37,6 @@ class Generator
4337
std::string getHeaderPath() const noexcept;
4438
std::string getSourcePath() const noexcept;
4539

46-
void validateRequest() const;
47-
std::shared_ptr<schema::Schema> buildSchema() const;
48-
void addTypesToSchema(const std::shared_ptr<schema::Schema>& schema) const;
49-
5040
bool outputHeader() const noexcept;
5141
void outputObjectDeclaration(
5242
std::ostream& headerFile, const ObjectType& objectType, bool isQueryType) const;
@@ -65,17 +55,13 @@ class Generator
6555
std::string getResultAccessType(const OutputField& result) const noexcept;
6656
std::string getTypeModifiers(const TypeModifierStack& modifiers) const noexcept;
6757

68-
static std::shared_ptr<const schema::BaseType> getIntrospectionType(
69-
const std::shared_ptr<schema::Schema>& schema, std::string_view type,
70-
const TypeModifierStack& modifiers) noexcept;
71-
72-
SchemaLoader _loader;
58+
const SchemaLoader _schemaLoader;
59+
const RequestLoader _requestLoader;
7360
const GeneratorOptions _options;
7461
const std::string _headerDir;
7562
const std::string _sourceDir;
7663
const std::string _headerPath;
7764
const std::string _sourcePath;
78-
peg::ast _request;
7965
};
8066

8167
} /* namespace graphql::generator::client */

include/RequestLoader.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,36 @@
66
#ifndef REQUESTLOADER_H
77
#define REQUESTLOADER_H
88

9-
#include "graphqlservice/GraphQLParse.h"
10-
#include "graphqlservice/GraphQLService.h"
9+
#include "SchemaLoader.h"
10+
11+
#include "graphqlservice/GraphQLSchema.h"
1112

1213
namespace graphql::generator {
1314

15+
struct RequestOptions
16+
{
17+
const std::string requestFilename;
18+
const std::string operationName;
19+
const bool noIntrospection = false;
20+
};
21+
1422
class RequestLoader
1523
{
1624
public:
17-
explicit RequestLoader();
18-
19-
void visit(const peg::ast& request, std::string_view operationName);
25+
explicit RequestLoader(RequestOptions&& requestOptions, const SchemaLoader& schemaLoader);
2026

2127
private:
28+
std::shared_ptr<schema::Schema> buildSchema(const SchemaLoader& schemaLoader) const;
29+
void addTypesToSchema(const SchemaLoader& schemaLoader, const std::shared_ptr<schema::Schema>& schema) const;
30+
void validateRequest() const;
31+
32+
static std::shared_ptr<const schema::BaseType> getIntrospectionType(
33+
const std::shared_ptr<schema::Schema>& schema, std::string_view type,
34+
const TypeModifierStack& modifiers) noexcept;
2235

36+
const RequestOptions _requestOptions;
37+
peg::ast _ast;
38+
std::shared_ptr<schema::Schema> _schema;
2339
};
2440

2541
} /* namespace graphql::generator */

include/SchemaLoader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "graphqlservice/GraphQLService.h"
1212

1313
#include <array>
14-
#include <cstdio>
1514
#include <unordered_map>
1615
#include <unordered_set>
1716

0 commit comments

Comments
 (0)