Skip to content

Commit 230f368

Browse files
committed
Emit separate files for each type by default
1 parent 78af84e commit 230f368

File tree

3 files changed

+35
-30
lines changed

3 files changed

+35
-30
lines changed

include/SchemaGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ struct GeneratorOptions
2020
{
2121
const std::optional<GeneratorPaths> paths;
2222
const bool verbose = false;
23-
const bool separateFiles = false;
2423
const bool stubs = false;
24+
const bool mergeFiles = false;
2525
const bool noIntrospection = false;
2626
};
2727

samples/CMakeLists.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ if(GRAPHQL_UPDATE_SAMPLES)
1111
OUTPUT
1212
${CMAKE_CURRENT_BINARY_DIR}/unified/TodaySchema.cpp
1313
${CMAKE_CURRENT_BINARY_DIR}/unified/TodaySchema.h
14-
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.today.graphql" --prefix="Today" --namespace="today" --stubs
14+
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.today.graphql" --prefix="Today" --namespace="today" --stubs --merge-files
1515
COMMAND ${CMAKE_COMMAND} -E copy_if_different
1616
TodaySchema.cpp
1717
TodaySchema.h
1818
${CMAKE_CURRENT_SOURCE_DIR}/unified
1919
DEPENDS schemagen graphqlpeg schema.today.graphql
2020
WORKING_DIRECTORY unified
21-
COMMENT "Generating mock TodaySchema files (--stubs)")
21+
COMMENT "Generating mock TodaySchema files (--stubs --merge-files)")
2222

2323
# unifiedschema_nointrospection
2424
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/unified_nointrospection)
@@ -27,14 +27,14 @@ if(GRAPHQL_UPDATE_SAMPLES)
2727
OUTPUT
2828
${CMAKE_CURRENT_BINARY_DIR}/unified_nointrospection/TodaySchema.cpp
2929
${CMAKE_CURRENT_BINARY_DIR}/unified_nointrospection/TodaySchema.h
30-
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.today.graphql" --prefix="Today" --namespace="today" --stubs --no-introspection
30+
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.today.graphql" --prefix="Today" --namespace="today" --stubs --merge-files --no-introspection
3131
COMMAND ${CMAKE_COMMAND} -E copy_if_different
3232
TodaySchema.cpp
3333
TodaySchema.h
3434
${CMAKE_CURRENT_SOURCE_DIR}/unified_nointrospection
3535
DEPENDS schemagen graphqlpeg schema.today.graphql
3636
WORKING_DIRECTORY unified_nointrospection
37-
COMMENT "Generating mock TodaySchema files without Introspection (--stubs --no-introspection)")
37+
COMMENT "Generating mock TodaySchema files without Introspection (--stubs --merge-files --no-introspection)")
3838

3939
# validationschema
4040
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/validation)
@@ -43,47 +43,47 @@ if(GRAPHQL_UPDATE_SAMPLES)
4343
OUTPUT
4444
${CMAKE_CURRENT_BINARY_DIR}/validation/ValidationSchema.cpp
4545
${CMAKE_CURRENT_BINARY_DIR}/validation/ValidationSchema.h
46-
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.validation.graphql" --prefix="Validation" --namespace="validation" --stubs
46+
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.validation.graphql" --prefix="Validation" --namespace="validation" --stubs --merge-files
4747
COMMAND ${CMAKE_COMMAND} -E copy_if_different
4848
ValidationSchema.cpp
4949
ValidationSchema.h
5050
${CMAKE_CURRENT_SOURCE_DIR}/validation
5151
DEPENDS schemagen graphqlpeg schema.validation.graphql
5252
WORKING_DIRECTORY validation
53-
COMMENT "Generating ValidationSchema files (--stubs)")
53+
COMMENT "Generating ValidationSchema files (--stubs --merge-files)")
5454

5555
# separateschema
5656
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/separate)
5757

5858
add_custom_command(
5959
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/separate/today_schema_files
60-
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.today.graphql" --prefix="Today" --namespace="today" --separate-files --stubs > today_schema_files
60+
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.today.graphql" --prefix="Today" --namespace="today" --stubs > today_schema_files
6161
COMMAND ${CMAKE_COMMAND} -E copy_if_different today_schema_files ${CMAKE_CURRENT_SOURCE_DIR}/separate
6262
DEPENDS schemagen graphqlpeg schema.today.graphql
6363
WORKING_DIRECTORY separate
64-
COMMENT "Generating mock TodaySchema (--stubs --separate-files)")
64+
COMMENT "Generating mock TodaySchema (--stubs)")
6565

6666
# separateschema_nointrospection
6767
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/separate_nointrospection)
6868

6969
add_custom_command(
7070
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/separate_nointrospection/today_schema_files
71-
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.today.graphql" --prefix="Today" --namespace="today" --no-introspection --separate-files --stubs > today_schema_files
71+
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.today.graphql" --prefix="Today" --namespace="today" --no-introspection --stubs > today_schema_files
7272
COMMAND ${CMAKE_COMMAND} -E copy_if_different today_schema_files ${CMAKE_CURRENT_SOURCE_DIR}/separate_nointrospection
7373
DEPENDS schemagen graphqlpeg schema.today.graphql
7474
WORKING_DIRECTORY separate_nointrospection
75-
COMMENT "Generating mock TodaySchema without Introspection (--stubs --separate-files --no-introspection)")
75+
COMMENT "Generating mock TodaySchema without Introspection (--stubs --no-introspection)")
7676

7777
# learn
7878
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/learn)
7979

8080
add_custom_command(
8181
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/learn/learn_schema_files
82-
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.learn.graphql" --prefix="StarWars" --namespace="learn" --separate-files > learn_schema_files
82+
COMMAND schemagen --schema="${CMAKE_CURRENT_SOURCE_DIR}/schema.learn.graphql" --prefix="StarWars" --namespace="learn" > learn_schema_files
8383
COMMAND ${CMAKE_COMMAND} -E copy_if_different learn_schema_files ${CMAKE_CURRENT_SOURCE_DIR}/learn
8484
DEPENDS schemagen graphqlpeg schema.learn.graphql
8585
WORKING_DIRECTORY learn
86-
COMMENT "Generating mock StarWarsSchema (--separate-files)")
86+
COMMENT "Generating mock StarWarsSchema")
8787

8888
add_custom_command(
8989
OUTPUT updated_samples

src/SchemaGenerator.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ std::string Generator::getHeaderPath() const noexcept
9191

9292
std::string Generator::getObjectHeaderPath() const noexcept
9393
{
94-
if (_options.separateFiles)
94+
if (!_options.mergeFiles)
9595
{
9696
fs::path fullPath { _headerDir };
9797

@@ -124,7 +124,7 @@ std::vector<std::string> Generator::Build() const noexcept
124124
builtFiles.push_back(_sourcePath);
125125
}
126126

127-
if (_options.separateFiles)
127+
if (!_options.mergeFiles)
128128
{
129129
auto separateFiles = outputSeparateFiles();
130130

@@ -306,7 +306,7 @@ static_assert(graphql::internal::MinorVersion == )cpp"
306306
}
307307
}
308308

309-
if (!_loader.getObjectTypes().empty() && !_options.separateFiles)
309+
if (!_loader.getObjectTypes().empty() && _options.mergeFiles)
310310
{
311311
if (_loader.isIntrospection())
312312
{
@@ -465,7 +465,7 @@ static_assert(graphql::internal::MinorVersion == )cpp"
465465
)cpp";
466466
}
467467

468-
if (!_loader.getObjectTypes().empty() && _options.separateFiles)
468+
if (!_loader.getObjectTypes().empty() && !_options.mergeFiles)
469469
{
470470
for (const auto& objectType : _loader.getObjectTypes())
471471
{
@@ -1181,7 +1181,7 @@ service::AwaitableResolver ModifiedResult<)cpp"
11811181
}
11821182
}
11831183

1184-
if (!_loader.getObjectTypes().empty() && !_options.separateFiles)
1184+
if (!_loader.getObjectTypes().empty() && _options.mergeFiles)
11851185
{
11861186
NamespaceScope objectNamespace { sourceFile, "object" };
11871187

@@ -1624,7 +1624,7 @@ Operations::Operations()cpp";
16241624

16251625
for (const auto& objectType : _loader.getObjectTypes())
16261626
{
1627-
if (_options.separateFiles)
1627+
if (!_options.mergeFiles)
16281628
{
16291629
sourceFile << R"cpp( Add)cpp" << objectType.cppType << R"cpp(Details(type)cpp"
16301630
<< objectType.cppType << R"cpp(, schema);
@@ -2057,7 +2057,7 @@ void Generator::outputObjectIntrospection(
20572057

20582058
firstInterface = false;
20592059

2060-
if (_options.separateFiles)
2060+
if (!_options.mergeFiles)
20612061
{
20622062
sourceFile
20632063
<< R"cpp( std::static_pointer_cast<const schema::InterfaceType>(schema->LookupType(R"gql()cpp"
@@ -2654,9 +2654,9 @@ int main(int argc, char** argv)
26542654
bool showVersion = false;
26552655
bool buildIntrospection = false;
26562656
bool buildCustom = false;
2657-
bool stubs = false;
26582657
bool verbose = false;
2659-
bool separateFiles = false;
2658+
bool stubs = false;
2659+
bool mergeFiles = false;
26602660
bool noIntrospection = false;
26612661
std::string schemaFileName;
26622662
std::string filenamePrefix;
@@ -2681,10 +2681,9 @@ int main(int argc, char** argv)
26812681
po::value(&headerDir),
26822682
"Target path for the <prefix>Schema.h header file")("stubs",
26832683
po::bool_switch(&stubs),
2684-
"Unimplemented fields throw runtime exceptions instead of compiler errors")(
2685-
"separate-files",
2686-
po::bool_switch(&separateFiles),
2687-
"Generate separate files for each of the types")("no-introspection",
2684+
"Unimplemented fields throw runtime exceptions instead of compiler errors")("merge-files",
2685+
po::bool_switch(&mergeFiles),
2686+
"Generate a single header and source file for the entire schema")("no-introspection",
26882687
po::bool_switch(&noIntrospection),
26892688
"Do not generate support for Introspection");
26902689
positional.add("schema", 1).add("prefix", 1).add("namespace", 1);
@@ -2744,9 +2743,15 @@ int main(int argc, char** argv)
27442743
{
27452744
if (buildIntrospection)
27462745
{
2747-
const auto files =
2748-
graphql::generator::schema::Generator(std::nullopt, { std::nullopt, verbose })
2749-
.Build();
2746+
const auto files = graphql::generator::schema::Generator(std::nullopt,
2747+
{
2748+
std::nullopt,
2749+
verbose,
2750+
false, // stubs
2751+
true, // mergeFiles
2752+
false, // noIntrospection
2753+
})
2754+
.Build();
27502755

27512756
for (const auto& file : files)
27522757
{
@@ -2764,8 +2769,8 @@ int main(int argc, char** argv)
27642769
graphql::generator::schema::GeneratorPaths { std::move(headerDir),
27652770
std::move(sourceDir) },
27662771
verbose,
2767-
separateFiles,
27682772
stubs,
2773+
mergeFiles,
27692774
noIntrospection,
27702775
})
27712776
.Build();

0 commit comments

Comments
 (0)