Skip to content

Commit e0202d5

Browse files
committed
Remove Introspection handling without arguments
1 parent a771fed commit e0202d5

File tree

6 files changed

+36
-159
lines changed

6 files changed

+36
-159
lines changed

include/ClientGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct GeneratorPaths
1919

2020
struct GeneratorOptions
2121
{
22-
const std::optional<GeneratorPaths> paths;
22+
const GeneratorPaths paths;
2323
const bool verbose = false;
2424
};
2525

include/SchemaGenerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct GeneratorPaths
1818

1919
struct GeneratorOptions
2020
{
21-
const std::optional<GeneratorPaths> paths;
21+
const GeneratorPaths paths;
2222
const bool verbose = false;
2323
const bool stubs = false;
2424
const bool noIntrospection = false;
@@ -28,7 +28,7 @@ class Generator
2828
{
2929
public:
3030
// Initialize the generator with the introspection schema or a custom GraphQL schema.
31-
explicit Generator(std::optional<SchemaOptions>&& customSchema, GeneratorOptions&& options);
31+
explicit Generator(SchemaOptions&& schemaOptions, GeneratorOptions&& options);
3232

3333
// Run the generator and return a list of filenames that were output.
3434
std::vector<std::string> Build() const noexcept;

include/SchemaLoader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class SchemaLoader
216216
{
217217
public:
218218
// Initialize the loader with the introspection schema or a custom GraphQL schema.
219-
explicit SchemaLoader(std::optional<SchemaOptions>&& customSchema);
219+
explicit SchemaLoader(SchemaOptions&& schemaOptions);
220220

221221
bool isIntrospection() const noexcept;
222222
std::string_view getFilenamePrefix() const noexcept;
@@ -292,7 +292,7 @@ class SchemaLoader
292292
static const CppTypeMap s_builtinCppTypes;
293293
static const std::string_view s_scalarCppType;
294294

295-
const std::optional<SchemaOptions> _customSchema;
295+
const SchemaOptions _schemaOptions;
296296
const bool _isIntrospection;
297297
std::string_view _schemaNamespace;
298298
peg::ast _ast;

src/ClientGenerator.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace graphql::generator::client {
5252

5353
Generator::Generator(
5454
SchemaOptions&& schemaOptions, RequestOptions&& requestOptions, GeneratorOptions&& options)
55-
: _schemaLoader(std::make_optional(std::move(schemaOptions)))
55+
: _schemaLoader(std::move(schemaOptions))
5656
, _requestLoader(std::move(requestOptions), _schemaLoader)
5757
, _options(std::move(options))
5858
, _headerDir(getHeaderDir())
@@ -64,9 +64,9 @@ Generator::Generator(
6464

6565
std::string Generator::getHeaderDir() const noexcept
6666
{
67-
if (_options.paths)
67+
if (!_options.paths.headerPath.empty())
6868
{
69-
return fs::path { _options.paths->headerPath }.string();
69+
return fs::path { _options.paths.headerPath }.string();
7070
}
7171
else
7272
{
@@ -76,9 +76,9 @@ std::string Generator::getHeaderDir() const noexcept
7676

7777
std::string Generator::getSourceDir() const noexcept
7878
{
79-
if (_options.paths)
79+
if (!_options.paths.sourcePath.empty())
8080
{
81-
return fs::path(_options.paths->sourcePath).string();
81+
return fs::path(_options.paths.sourcePath).string();
8282
}
8383
else
8484
{
@@ -223,8 +223,7 @@ static_assert(graphql::internal::MinorVersion == )cpp"
223223
{
224224
pendingSeparator.reset();
225225

226-
headerFile << R"cpp(enum class )cpp" << _schemaLoader.getCppType(enumType->name())
227-
<< R"cpp(
226+
headerFile << R"cpp(enum class )cpp" << _schemaLoader.getCppType(enumType->name()) << R"cpp(
228227
{
229228
)cpp";
230229
for (const auto& enumValue : enumType->enumValues())
@@ -972,8 +971,7 @@ int main(int argc, char** argv)
972971
noIntrospection,
973972
},
974973
graphql::generator::client::GeneratorOptions {
975-
graphql::generator::client::GeneratorPaths { std::move(headerDir),
976-
std::move(sourceDir) },
974+
{ std::move(headerDir), std::move(sourceDir) },
977975
verbose,
978976
})
979977
.Build();

src/SchemaGenerator.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ using namespace std::literals;
4747

4848
namespace graphql::generator::schema {
4949

50-
Generator::Generator(std::optional<SchemaOptions>&& customSchema, GeneratorOptions&& options)
51-
: _loader(std::move(customSchema))
50+
Generator::Generator(SchemaOptions&& schemaOptions, GeneratorOptions&& options)
51+
: _loader(std::move(schemaOptions))
5252
, _options(std::move(options))
5353
, _headerDir(getHeaderDir())
5454
, _sourceDir(getSourceDir())
@@ -59,9 +59,9 @@ Generator::Generator(std::optional<SchemaOptions>&& customSchema, GeneratorOptio
5959

6060
std::string Generator::getHeaderDir() const noexcept
6161
{
62-
if (_options.paths)
62+
if (!_options.paths.headerPath.empty())
6363
{
64-
return fs::path { _options.paths->headerPath }.string();
64+
return fs::path { _options.paths.headerPath }.string();
6565
}
6666
else
6767
{
@@ -71,9 +71,9 @@ std::string Generator::getHeaderDir() const noexcept
7171

7272
std::string Generator::getSourceDir() const noexcept
7373
{
74-
if (_options.paths)
74+
if (!_options.paths.sourcePath.empty())
7575
{
76-
return fs::path(_options.paths->sourcePath).string();
76+
return fs::path(_options.paths.sourcePath).string();
7777
}
7878
else
7979
{
@@ -3009,28 +3009,23 @@ int main(int argc, char** argv)
30093009
outputVersion(std::cout);
30103010
return 0;
30113011
}
3012-
else if (showUsage || (!buildIntrospection && !buildCustom))
3012+
else if (showUsage || !buildCustom)
30133013
{
30143014
outputUsage(std::cout, options);
30153015
return 0;
30163016
}
30173017

30183018
try
30193019
{
3020-
auto schemaOptions = buildCustom
3021-
? std::make_optional(graphql::generator::SchemaOptions { std::move(schemaFileName),
3022-
std::move(filenamePrefix),
3023-
std::move(schemaNamespace),
3024-
buildIntrospection })
3025-
: std::nullopt;
3026-
3027-
const auto files = graphql::generator::schema::Generator(std::move(schemaOptions),
3020+
const auto files = graphql::generator::schema::Generator({ std::move(schemaFileName),
3021+
std::move(filenamePrefix),
3022+
std::move(schemaNamespace),
3023+
buildIntrospection },
30283024
{
3029-
graphql::generator::schema::GeneratorPaths { std::move(headerDir),
3030-
std::move(sourceDir) },
3031-
verbose,
3032-
stubs, // stubs
3033-
noIntrospection, // noIntrospection
3025+
{ std::move(headerDir), std::move(sourceDir) }, // paths
3026+
verbose, // verbose
3027+
stubs, // stubs
3028+
noIntrospection, // noIntrospection
30343029
})
30353030
.Build();
30363031

src/SchemaLoader.cpp

Lines changed: 9 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -34,133 +34,17 @@ const CppTypeMap SchemaLoader::s_builtinCppTypes = {
3434

3535
const std::string_view SchemaLoader::s_scalarCppType = R"cpp(response::Value)cpp"sv;
3636

37-
SchemaLoader::SchemaLoader(std::optional<SchemaOptions>&& customSchema)
38-
: _customSchema(std::move(customSchema))
39-
, _isIntrospection(!_customSchema || _customSchema->isIntrospection)
40-
, _schemaNamespace(_customSchema ? _customSchema->schemaNamespace : s_introspectionNamespace)
37+
SchemaLoader::SchemaLoader(SchemaOptions&& schemaOptions)
38+
: _schemaOptions(std::move(schemaOptions))
39+
, _isIntrospection(_schemaOptions.isIntrospection)
40+
, _schemaNamespace(_schemaOptions.schemaNamespace)
4141
{
42-
if (!_customSchema)
43-
{
44-
// Introspection Schema:
45-
// http://spec.graphql.org/June2018/#sec-Schema-Introspection
46-
_ast = peg::parseSchemaString(R"gql(
47-
type __Schema {
48-
types: [__Type!]!
49-
queryType: __Type!
50-
mutationType: __Type
51-
subscriptionType: __Type
52-
directives: [__Directive!]!
53-
}
54-
55-
type __Type {
56-
kind: __TypeKind!
57-
name: String
58-
description: String
59-
60-
# OBJECT and INTERFACE only
61-
fields(includeDeprecated: Boolean = false): [__Field!]
62-
63-
# OBJECT only
64-
interfaces: [__Type!]
65-
66-
# INTERFACE and UNION only
67-
possibleTypes: [__Type!]
68-
69-
# ENUM only
70-
enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
71-
72-
# INPUT_OBJECT only
73-
inputFields: [__InputValue!]
74-
75-
# NON_NULL and LIST only
76-
ofType: __Type
77-
}
78-
79-
type __Field {
80-
name: String!
81-
description: String
82-
args: [__InputValue!]!
83-
type: __Type!
84-
isDeprecated: Boolean!
85-
deprecationReason: String
86-
}
87-
88-
type __InputValue {
89-
name: String!
90-
description: String
91-
type: __Type!
92-
defaultValue: String
93-
}
94-
95-
type __EnumValue {
96-
name: String!
97-
description: String
98-
isDeprecated: Boolean!
99-
deprecationReason: String
100-
}
101-
102-
enum __TypeKind {
103-
SCALAR
104-
OBJECT
105-
INTERFACE
106-
UNION
107-
ENUM
108-
INPUT_OBJECT
109-
LIST
110-
NON_NULL
111-
}
112-
113-
type __Directive {
114-
name: String!
115-
description: String
116-
locations: [__DirectiveLocation!]!
117-
args: [__InputValue!]!
118-
}
119-
120-
enum __DirectiveLocation {
121-
QUERY
122-
MUTATION
123-
SUBSCRIPTION
124-
FIELD
125-
FRAGMENT_DEFINITION
126-
FRAGMENT_SPREAD
127-
INLINE_FRAGMENT
128-
SCHEMA
129-
SCALAR
130-
OBJECT
131-
FIELD_DEFINITION
132-
ARGUMENT_DEFINITION
133-
INTERFACE
134-
UNION
135-
ENUM
136-
ENUM_VALUE
137-
INPUT_OBJECT
138-
INPUT_FIELD_DEFINITION
139-
}
140-
141-
# These directives are always defined and should be included in the Introspection schema.
142-
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
143-
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
144-
directive @deprecated(
145-
reason: String = "No longer supported"
146-
) on FIELD_DEFINITION | ENUM_VALUE
147-
)gql"sv);
42+
_ast = peg::parseSchemaFile(_schemaOptions.schemaFilename);
14843

149-
if (!_ast.root)
150-
{
151-
throw std::logic_error("Unable to parse the introspection schema, but there was no "
152-
"error message from the parser!");
153-
}
154-
}
155-
else
44+
if (!_ast.root)
15645
{
157-
_ast = peg::parseSchemaFile(_customSchema->schemaFilename);
158-
159-
if (!_ast.root)
160-
{
161-
throw std::logic_error("Unable to parse the service schema, but there was no error "
162-
"message from the parser!");
163-
}
46+
throw std::logic_error("Unable to parse the service schema, but there was no error "
47+
"message from the parser!");
16448
}
16549

16650
for (const auto& child : _ast.root->children)
@@ -1215,7 +1099,7 @@ bool SchemaLoader::isIntrospection() const noexcept
12151099

12161100
std::string_view SchemaLoader::getFilenamePrefix() const noexcept
12171101
{
1218-
return _customSchema ? _customSchema->filenamePrefix : "Introspection"sv;
1102+
return _schemaOptions.filenamePrefix;
12191103
}
12201104

12211105
std::string_view SchemaLoader::getSchemaNamespace() const noexcept

0 commit comments

Comments
 (0)