Skip to content

Commit 5c7a3a6

Browse files
authored
Merge pull request #177 from wravery/next
Remove the schemagen --merge-files option and make everything use separate files
2 parents e6f61a1 + 5c74269 commit 5c7a3a6

File tree

174 files changed

+6695
-14234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+6695
-14234
lines changed

cmake/cppgraphqlgen-functions.cmake

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,26 @@ function(add_graphql_schema_target SCHEMA_TARGET)
4242
add_custom_target(${SCHEMA_TARGET}_update_schema ALL
4343
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files)
4444

45-
file(STRINGS ${SCHEMA_TARGET}_schema_files SCHEMA_FILES)
46-
add_library(${SCHEMA_TARGET}_schema STATIC ${SCHEMA_FILES})
47-
add_dependencies(${SCHEMA_TARGET}_schema ${SCHEMA_TARGET}_update_schema)
48-
target_include_directories(${SCHEMA_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
49-
target_link_libraries(${SCHEMA_TARGET}_schema PUBLIC cppgraphqlgen::graphqlintrospection)
45+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files)
46+
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files SCHEMA_FILES)
47+
add_library(${SCHEMA_TARGET}_schema STATIC ${SCHEMA_FILES})
48+
add_dependencies(${SCHEMA_TARGET}_schema ${SCHEMA_TARGET}_update_schema)
49+
target_include_directories(${SCHEMA_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
50+
target_link_libraries(${SCHEMA_TARGET}_schema PUBLIC cppgraphqlgen::graphqlintrospection)
51+
endif()
5052
endfunction()
5153

5254
function(add_graphql_schema_no_introspection_target SCHEMA_NO_INTROSPECTION_TARGET)
5355
add_custom_target(${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema ALL
5456
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files)
5557

56-
file(STRINGS ${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files SCHEMA_FILES)
57-
add_library(${SCHEMA_NO_INTROSPECTION_TARGET}_schema STATIC ${SCHEMA_FILES})
58-
add_dependencies(${SCHEMA_NO_INTROSPECTION_TARGET}_schema ${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema)
59-
target_include_directories(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
60-
target_link_libraries(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC cppgraphqlgen::graphqlservice)
58+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files)
59+
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files SCHEMA_FILES)
60+
add_library(${SCHEMA_NO_INTROSPECTION_TARGET}_schema STATIC ${SCHEMA_FILES})
61+
add_dependencies(${SCHEMA_NO_INTROSPECTION_TARGET}_schema ${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema)
62+
target_include_directories(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
63+
target_link_libraries(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC cppgraphqlgen::graphqlservice)
64+
endif()
6165
endfunction()
6266

6367
function(update_graphql_client_files CLIENT_TARGET SCHEMA_GRAPHQL REQUEST_GRAPHQL CLIENT_PREFIX CLIENT_NAMESPACE)
@@ -93,9 +97,11 @@ function(add_graphql_client_target CLIENT_TARGET)
9397
add_custom_target(${CLIENT_TARGET}_update_client ALL
9498
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files)
9599

96-
file(STRINGS ${CLIENT_TARGET}_client_files CLIENT_FILES)
97-
add_library(${CLIENT_TARGET}_client STATIC ${CLIENT_FILES})
98-
add_dependencies(${CLIENT_TARGET}_client ${CLIENT_TARGET}_update_client)
99-
target_include_directories(${CLIENT_TARGET}_client PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
100-
target_link_libraries(${CLIENT_TARGET}_client PUBLIC cppgraphqlgen::graphqlclient)
100+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files)
101+
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files CLIENT_FILES)
102+
add_library(${CLIENT_TARGET}_client STATIC ${CLIENT_FILES})
103+
add_dependencies(${CLIENT_TARGET}_client ${CLIENT_TARGET}_update_client)
104+
target_include_directories(${CLIENT_TARGET}_client PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
105+
target_link_libraries(${CLIENT_TARGET}_client PUBLIC cppgraphqlgen::graphqlclient)
106+
endif()
101107
endfunction()

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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@ 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;
24-
const bool mergeFiles = false;
2524
const bool noIntrospection = false;
2625
};
2726

2827
class Generator
2928
{
3029
public:
3130
// Initialize the generator with the introspection schema or a custom GraphQL schema.
32-
explicit Generator(std::optional<SchemaOptions>&& customSchema, GeneratorOptions&& options);
31+
explicit Generator(SchemaOptions&& schemaOptions, GeneratorOptions&& options);
3332

3433
// Run the generator and return a list of filenames that were output.
3534
std::vector<std::string> Build() const noexcept;
@@ -38,7 +37,6 @@ class Generator
3837
std::string getHeaderDir() const noexcept;
3938
std::string getSourceDir() const noexcept;
4039
std::string getHeaderPath() const noexcept;
41-
std::string getObjectHeaderPath() const noexcept;
4240
std::string getSourcePath() const noexcept;
4341

4442
bool outputHeader() const noexcept;
@@ -80,7 +78,6 @@ class Generator
8078
const std::string _headerDir;
8179
const std::string _sourceDir;
8280
const std::string _headerPath;
83-
const std::string _objectHeaderPath;
8481
const std::string _sourcePath;
8582
};
8683

include/SchemaLoader.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,14 @@ struct SchemaOptions
209209
const std::string schemaFilename;
210210
const std::string filenamePrefix;
211211
const std::string schemaNamespace;
212+
const bool isIntrospection = false;
212213
};
213214

214215
class SchemaLoader
215216
{
216217
public:
217218
// Initialize the loader with the introspection schema or a custom GraphQL schema.
218-
explicit SchemaLoader(std::optional<SchemaOptions>&& customSchema);
219+
explicit SchemaLoader(SchemaOptions&& schemaOptions);
219220

220221
bool isIntrospection() const noexcept;
221222
std::string_view getFilenamePrefix() const noexcept;
@@ -291,7 +292,7 @@ class SchemaLoader
291292
static const CppTypeMap s_builtinCppTypes;
292293
static const std::string_view s_scalarCppType;
293294

294-
const std::optional<SchemaOptions> _customSchema;
295+
const SchemaOptions _schemaOptions;
295296
const bool _isIntrospection;
296297
std::string_view _schemaNamespace;
297298
peg::ast _ast;

include/graphqlservice/introspection/Introspection.h renamed to include/graphqlservice/internal/Introspection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#ifndef INTROSPECTION_H
77
#define INTROSPECTION_H
88

9-
#include "graphqlservice/internal/Schema.h"
10-
119
#include "graphqlservice/introspection/IntrospectionSchema.h"
1210

11+
#include "graphqlservice/internal/Schema.h"
12+
1313
namespace graphql::introspection {
1414

1515
class Schema;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// WARNING! Do not edit this file manually, your changes will be overwritten.
5+
6+
#pragma once
7+
8+
#ifndef DIRECTIVEOBJECT_H
9+
#define DIRECTIVEOBJECT_H
10+
11+
#include "IntrospectionSchema.h"
12+
13+
namespace graphql::introspection::object {
14+
15+
class Directive
16+
: public service::Object
17+
{
18+
private:
19+
service::AwaitableResolver resolveName(service::ResolverParams&& params) const;
20+
service::AwaitableResolver resolveDescription(service::ResolverParams&& params) const;
21+
service::AwaitableResolver resolveLocations(service::ResolverParams&& params) const;
22+
service::AwaitableResolver resolveArgs(service::ResolverParams&& params) const;
23+
24+
service::AwaitableResolver resolve_typename(service::ResolverParams&& params) const;
25+
26+
struct Concept
27+
{
28+
virtual ~Concept() = default;
29+
30+
virtual service::FieldResult<std::string> getName() const = 0;
31+
virtual service::FieldResult<std::optional<std::string>> getDescription() const = 0;
32+
virtual service::FieldResult<std::vector<DirectiveLocation>> getLocations() const = 0;
33+
virtual service::FieldResult<std::vector<std::shared_ptr<InputValue>>> getArgs() const = 0;
34+
};
35+
36+
template <class T>
37+
struct Model
38+
: Concept
39+
{
40+
Model(std::shared_ptr<T>&& pimpl) noexcept
41+
: _pimpl { std::move(pimpl) }
42+
{
43+
}
44+
45+
service::FieldResult<std::string> getName() const final
46+
{
47+
return { _pimpl->getName() };
48+
}
49+
50+
service::FieldResult<std::optional<std::string>> getDescription() const final
51+
{
52+
return { _pimpl->getDescription() };
53+
}
54+
55+
service::FieldResult<std::vector<DirectiveLocation>> getLocations() const final
56+
{
57+
return { _pimpl->getLocations() };
58+
}
59+
60+
service::FieldResult<std::vector<std::shared_ptr<InputValue>>> getArgs() const final
61+
{
62+
return { _pimpl->getArgs() };
63+
}
64+
65+
private:
66+
const std::shared_ptr<T> _pimpl;
67+
};
68+
69+
const std::unique_ptr<Concept> _pimpl;
70+
71+
service::TypeNames getTypeNames() const noexcept;
72+
service::ResolverMap getResolvers() const noexcept;
73+
74+
public:
75+
GRAPHQLINTROSPECTION_EXPORT Directive(std::shared_ptr<introspection::Directive> pimpl) noexcept;
76+
GRAPHQLINTROSPECTION_EXPORT ~Directive();
77+
};
78+
79+
} // namespace graphql::introspection::object
80+
81+
#endif // DIRECTIVEOBJECT_H
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// WARNING! Do not edit this file manually, your changes will be overwritten.
5+
6+
#pragma once
7+
8+
#ifndef ENUMVALUEOBJECT_H
9+
#define ENUMVALUEOBJECT_H
10+
11+
#include "IntrospectionSchema.h"
12+
13+
namespace graphql::introspection::object {
14+
15+
class EnumValue
16+
: public service::Object
17+
{
18+
private:
19+
service::AwaitableResolver resolveName(service::ResolverParams&& params) const;
20+
service::AwaitableResolver resolveDescription(service::ResolverParams&& params) const;
21+
service::AwaitableResolver resolveIsDeprecated(service::ResolverParams&& params) const;
22+
service::AwaitableResolver resolveDeprecationReason(service::ResolverParams&& params) const;
23+
24+
service::AwaitableResolver resolve_typename(service::ResolverParams&& params) const;
25+
26+
struct Concept
27+
{
28+
virtual ~Concept() = default;
29+
30+
virtual service::FieldResult<std::string> getName() const = 0;
31+
virtual service::FieldResult<std::optional<std::string>> getDescription() const = 0;
32+
virtual service::FieldResult<bool> getIsDeprecated() const = 0;
33+
virtual service::FieldResult<std::optional<std::string>> getDeprecationReason() const = 0;
34+
};
35+
36+
template <class T>
37+
struct Model
38+
: Concept
39+
{
40+
Model(std::shared_ptr<T>&& pimpl) noexcept
41+
: _pimpl { std::move(pimpl) }
42+
{
43+
}
44+
45+
service::FieldResult<std::string> getName() const final
46+
{
47+
return { _pimpl->getName() };
48+
}
49+
50+
service::FieldResult<std::optional<std::string>> getDescription() const final
51+
{
52+
return { _pimpl->getDescription() };
53+
}
54+
55+
service::FieldResult<bool> getIsDeprecated() const final
56+
{
57+
return { _pimpl->getIsDeprecated() };
58+
}
59+
60+
service::FieldResult<std::optional<std::string>> getDeprecationReason() const final
61+
{
62+
return { _pimpl->getDeprecationReason() };
63+
}
64+
65+
private:
66+
const std::shared_ptr<T> _pimpl;
67+
};
68+
69+
const std::unique_ptr<Concept> _pimpl;
70+
71+
service::TypeNames getTypeNames() const noexcept;
72+
service::ResolverMap getResolvers() const noexcept;
73+
74+
public:
75+
GRAPHQLINTROSPECTION_EXPORT EnumValue(std::shared_ptr<introspection::EnumValue> pimpl) noexcept;
76+
GRAPHQLINTROSPECTION_EXPORT ~EnumValue();
77+
};
78+
79+
} // namespace graphql::introspection::object
80+
81+
#endif // ENUMVALUEOBJECT_H
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// WARNING! Do not edit this file manually, your changes will be overwritten.
5+
6+
#pragma once
7+
8+
#ifndef FIELDOBJECT_H
9+
#define FIELDOBJECT_H
10+
11+
#include "IntrospectionSchema.h"
12+
13+
namespace graphql::introspection::object {
14+
15+
class Field
16+
: public service::Object
17+
{
18+
private:
19+
service::AwaitableResolver resolveName(service::ResolverParams&& params) const;
20+
service::AwaitableResolver resolveDescription(service::ResolverParams&& params) const;
21+
service::AwaitableResolver resolveArgs(service::ResolverParams&& params) const;
22+
service::AwaitableResolver resolveType(service::ResolverParams&& params) const;
23+
service::AwaitableResolver resolveIsDeprecated(service::ResolverParams&& params) const;
24+
service::AwaitableResolver resolveDeprecationReason(service::ResolverParams&& params) const;
25+
26+
service::AwaitableResolver resolve_typename(service::ResolverParams&& params) const;
27+
28+
struct Concept
29+
{
30+
virtual ~Concept() = default;
31+
32+
virtual service::FieldResult<std::string> getName() const = 0;
33+
virtual service::FieldResult<std::optional<std::string>> getDescription() const = 0;
34+
virtual service::FieldResult<std::vector<std::shared_ptr<InputValue>>> getArgs() const = 0;
35+
virtual service::FieldResult<std::shared_ptr<Type>> getType() const = 0;
36+
virtual service::FieldResult<bool> getIsDeprecated() const = 0;
37+
virtual service::FieldResult<std::optional<std::string>> getDeprecationReason() const = 0;
38+
};
39+
40+
template <class T>
41+
struct Model
42+
: Concept
43+
{
44+
Model(std::shared_ptr<T>&& pimpl) noexcept
45+
: _pimpl { std::move(pimpl) }
46+
{
47+
}
48+
49+
service::FieldResult<std::string> getName() const final
50+
{
51+
return { _pimpl->getName() };
52+
}
53+
54+
service::FieldResult<std::optional<std::string>> getDescription() const final
55+
{
56+
return { _pimpl->getDescription() };
57+
}
58+
59+
service::FieldResult<std::vector<std::shared_ptr<InputValue>>> getArgs() const final
60+
{
61+
return { _pimpl->getArgs() };
62+
}
63+
64+
service::FieldResult<std::shared_ptr<Type>> getType() const final
65+
{
66+
return { _pimpl->getType() };
67+
}
68+
69+
service::FieldResult<bool> getIsDeprecated() const final
70+
{
71+
return { _pimpl->getIsDeprecated() };
72+
}
73+
74+
service::FieldResult<std::optional<std::string>> getDeprecationReason() const final
75+
{
76+
return { _pimpl->getDeprecationReason() };
77+
}
78+
79+
private:
80+
const std::shared_ptr<T> _pimpl;
81+
};
82+
83+
const std::unique_ptr<Concept> _pimpl;
84+
85+
service::TypeNames getTypeNames() const noexcept;
86+
service::ResolverMap getResolvers() const noexcept;
87+
88+
public:
89+
GRAPHQLINTROSPECTION_EXPORT Field(std::shared_ptr<introspection::Field> pimpl) noexcept;
90+
GRAPHQLINTROSPECTION_EXPORT ~Field();
91+
};
92+
93+
} // namespace graphql::introspection::object
94+
95+
#endif // FIELDOBJECT_H

0 commit comments

Comments
 (0)