Skip to content

Commit c28e9d1

Browse files
committed
Merge branch 'main' into multi-request
2 parents 0ff52a7 + c47cd51 commit c28e9d1

File tree

108 files changed

+2159
-1842
lines changed

Some content is hidden

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

108 files changed

+2159
-1842
lines changed

include/ClientGenerator.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,51 @@
1111

1212
namespace graphql::generator::client {
1313

14-
struct GeneratorPaths
14+
struct [[nodiscard]] GeneratorPaths
1515
{
1616
const std::string headerPath;
1717
const std::string sourcePath;
1818
};
1919

20-
struct GeneratorOptions
20+
struct [[nodiscard]] GeneratorOptions
2121
{
2222
const GeneratorPaths paths;
2323
const bool verbose = false;
2424
};
2525

26-
class Generator
26+
class [[nodiscard]] Generator
2727
{
2828
public:
2929
// Initialize the generator with the introspection client or a custom GraphQL client.
3030
explicit Generator(
3131
SchemaOptions&& schemaOptions, RequestOptions&& requestOptions, GeneratorOptions&& options);
3232

3333
// Run the generator and return a list of filenames that were output.
34-
std::vector<std::string> Build() const noexcept;
34+
[[nodiscard]] std::vector<std::string> Build() const noexcept;
3535

3636
private:
37-
std::string getHeaderDir() const noexcept;
38-
std::string getSourceDir() const noexcept;
39-
std::string getHeaderPath() const noexcept;
40-
std::string getSourcePath() const noexcept;
41-
const std::string& getClientNamespace() const noexcept;
42-
const std::string& getRequestNamespace() const noexcept;
43-
const std::string& getFullNamespace() const noexcept;
44-
std::string getResponseFieldCppType(
37+
[[nodiscard]] std::string getHeaderDir() const noexcept;
38+
[[nodiscard]] std::string getSourceDir() const noexcept;
39+
[[nodiscard]] std::string getHeaderPath() const noexcept;
40+
[[nodiscard]] std::string getSourcePath() const noexcept;
41+
[[nodiscard]] const std::string& getClientNamespace() const noexcept;
42+
[[nodiscard]] const std::string& getRequestNamespace() const noexcept;
43+
[[nodiscard]] const std::string& getFullNamespace() const noexcept;
44+
[[nodiscard]] std::string getResponseFieldCppType(
4545
const ResponseField& responseField, std::string_view currentScope = {}) const noexcept;
4646

47-
bool outputHeader() const noexcept;
47+
[[nodiscard]] bool outputHeader() const noexcept;
4848
void outputRequestComment(std::ostream& headerFile) const noexcept;
4949
void outputGetRequestDeclaration(std::ostream& headerFile) const noexcept;
50-
bool outputResponseFieldType(std::ostream& headerFile, const ResponseField& responseField,
51-
size_t indent = 0) const noexcept;
50+
[[nodiscard]] bool outputResponseFieldType(std::ostream& headerFile,
51+
const ResponseField& responseField, size_t indent = 0) const noexcept;
5252

53-
bool outputSource() const noexcept;
53+
[[nodiscard]] bool outputSource() const noexcept;
5454
void outputGetRequestImplementation(std::ostream& sourceFile) const noexcept;
5555
bool outputModifiedResponseImplementation(std::ostream& sourceFile,
5656
const std::string& outerScope, const ResponseField& responseField) const noexcept;
57-
static std::string getTypeModifierList(const TypeModifierStack& modifiers) noexcept;
57+
[[nodiscard]] static std::string getTypeModifierList(
58+
const TypeModifierStack& modifiers) noexcept;
5859

5960
const SchemaLoader _schemaLoader;
6061
const RequestLoader _requestLoader;

include/GeneratorLoader.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
namespace graphql::generator {
1212

1313
// Types that we understand and use to generate the skeleton of a service.
14-
enum class SchemaType
15-
{
14+
enum class [[nodiscard]] SchemaType {
1615
Scalar,
1716
Enum,
1817
Input,
@@ -31,10 +30,10 @@ using TypeModifierStack = std::vector<service::TypeModifier>;
3130

3231
// Recursively visit a Type node until we reach a NamedType and we've
3332
// taken stock of all of the modifier wrappers.
34-
class TypeVisitor
33+
class [[nodiscard]] TypeVisitor
3534
{
3635
public:
37-
std::pair<std::string_view, TypeModifierStack> getType();
36+
[[nodiscard]] std::pair<std::string_view, TypeModifierStack> getType();
3837

3938
void visit(const peg::ast_node& typeName);
4039

@@ -50,10 +49,10 @@ class TypeVisitor
5049

5150
// Recursively visit a Value node representing the default value on an input field
5251
// and build a JSON representation of the hardcoded value.
53-
class DefaultValueVisitor
52+
class [[nodiscard]] DefaultValueVisitor
5453
{
5554
public:
56-
response::Value getValue();
55+
[[nodiscard]] response::Value getValue();
5756

5857
void visit(const peg::ast_node& value);
5958

include/GeneratorUtil.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace graphql::generator {
1414

1515
// RAII object to help with emitting matching include guard begin and end statements
16-
class IncludeGuardScope
16+
class [[nodiscard]] IncludeGuardScope
1717
{
1818
public:
1919
explicit IncludeGuardScope(std::ostream& outputFile, std::string_view headerFileName) noexcept;
@@ -25,7 +25,7 @@ class IncludeGuardScope
2525
};
2626

2727
// RAII object to help with emitting matching namespace begin and end statements
28-
class NamespaceScope
28+
class [[nodiscard]] NamespaceScope
2929
{
3030
public:
3131
explicit NamespaceScope(
@@ -44,7 +44,7 @@ class NamespaceScope
4444

4545
// Keep track of whether we want to add a blank separator line once some additional content is about
4646
// to be output.
47-
class PendingBlankLine
47+
class [[nodiscard]] PendingBlankLine
4848
{
4949
public:
5050
explicit PendingBlankLine(std::ostream& outputFile) noexcept;

include/RequestLoader.h

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ struct ResponseField;
2525

2626
using ResponseFieldList = std::vector<ResponseField>;
2727

28-
struct ResponseType
28+
struct [[nodiscard]] ResponseType
2929
{
3030
RequestSchemaType type;
3131
std::string_view cppType;
3232
ResponseFieldList fields;
3333
};
3434

35-
struct ResponseField
35+
struct [[nodiscard]] ResponseField
3636
{
3737
RequestSchemaType type;
3838
TypeModifierStack modifiers;
@@ -42,7 +42,7 @@ struct ResponseField
4242
ResponseFieldList children;
4343
};
4444

45-
struct RequestInputType
45+
struct [[nodiscard]] RequestInputType
4646
{
4747
RequestSchemaType type;
4848
std::unordered_set<std::string_view> dependencies {};
@@ -51,7 +51,7 @@ struct RequestInputType
5151

5252
using RequestInputTypeList = std::vector<RequestInputType>;
5353

54-
struct RequestVariable
54+
struct [[nodiscard]] RequestVariable
5555
{
5656
RequestInputType inputType;
5757
TypeModifierStack modifiers;
@@ -64,7 +64,7 @@ struct RequestVariable
6464

6565
using RequestVariableList = std::vector<RequestVariable>;
6666

67-
struct RequestOptions
67+
struct [[nodiscard]] RequestOptions
6868
{
6969
const std::string requestFilename;
7070
const std::string operationName;
@@ -73,40 +73,41 @@ struct RequestOptions
7373

7474
class SchemaLoader;
7575

76-
class RequestLoader
76+
class [[nodiscard]] RequestLoader
7777
{
7878
public:
7979
explicit RequestLoader(RequestOptions&& requestOptions, const SchemaLoader& schemaLoader);
8080

81-
std::string_view getRequestFilename() const noexcept;
82-
std::string_view getOperationDisplayName() const noexcept;
83-
std::string getOperationNamespace() const noexcept;
84-
std::string_view getOperationType() const noexcept;
85-
std::string_view getRequestText() const noexcept;
81+
[[nodiscard]] std::string_view getRequestFilename() const noexcept;
82+
[[nodiscard]] std::string_view getOperationDisplayName() const noexcept;
83+
[[nodiscard]] std::string getOperationNamespace() const noexcept;
84+
[[nodiscard]] std::string_view getOperationType() const noexcept;
85+
[[nodiscard]] std::string_view getRequestText() const noexcept;
8686

87-
const ResponseType& getResponseType() const noexcept;
88-
const RequestVariableList& getVariables() const noexcept;
87+
[[nodiscard]] const ResponseType& getResponseType() const noexcept;
88+
[[nodiscard]] const RequestVariableList& getVariables() const noexcept;
8989

90-
const RequestInputTypeList& getReferencedInputTypes() const noexcept;
91-
const RequestSchemaTypeList& getReferencedEnums() const noexcept;
90+
[[nodiscard]] const RequestInputTypeList& getReferencedInputTypes() const noexcept;
91+
[[nodiscard]] const RequestSchemaTypeList& getReferencedEnums() const noexcept;
9292

93-
std::string getInputCppType(const RequestSchemaType& wrappedInputType) const noexcept;
94-
std::string getInputCppType(const RequestSchemaType& inputType,
95-
const TypeModifierStack& modifiers) const noexcept;
96-
static std::string getOutputCppType(
93+
[[nodiscard]] std::string getInputCppType(
94+
const RequestSchemaType& wrappedInputType) const noexcept;
95+
[[nodiscard]] std::string getInputCppType(
96+
const RequestSchemaType& inputType, const TypeModifierStack& modifiers) const noexcept;
97+
[[nodiscard]] static std::string getOutputCppType(
9798
std::string_view outputCppType, const TypeModifierStack& modifiers) noexcept;
9899

99-
static std::pair<RequestSchemaType, TypeModifierStack> unwrapSchemaType(
100+
[[nodiscard]] static std::pair<RequestSchemaType, TypeModifierStack> unwrapSchemaType(
100101
RequestSchemaType&& type) noexcept;
101102

102103
private:
103104
void buildSchema();
104105
void addTypesToSchema();
105-
RequestSchemaType getSchemaType(
106+
[[nodiscard]] RequestSchemaType getSchemaType(
106107
std::string_view type, const TypeModifierStack& modifiers) const noexcept;
107108
void validateRequest() const;
108109

109-
static std::string_view trimWhitespace(std::string_view content) noexcept;
110+
[[nodiscard]] static std::string_view trimWhitespace(std::string_view content) noexcept;
110111

111112
void findOperation();
112113
void collectFragments() noexcept;
@@ -119,7 +120,7 @@ class RequestLoader
119120
using FragmentDefinitionMap = std::map<std::string_view, const peg::ast_node*>;
120121

121122
// SelectionVisitor visits the AST and fills in the ResponseType for the request.
122-
class SelectionVisitor
123+
class [[nodiscard]] SelectionVisitor
123124
{
124125
public:
125126
explicit SelectionVisitor(const SchemaLoader& schemaLoader,
@@ -128,7 +129,7 @@ class RequestLoader
128129

129130
void visit(const peg::ast_node& selection);
130131

131-
ResponseFieldList getFields();
132+
[[nodiscard]] ResponseFieldList getFields();
132133

133134
private:
134135
void visitField(const peg::ast_node& field);

include/SchemaGenerator.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,46 @@
1010

1111
namespace graphql::generator::schema {
1212

13-
struct GeneratorPaths
13+
struct [[nodiscard]] GeneratorPaths
1414
{
1515
const std::string headerPath;
1616
const std::string sourcePath;
1717
};
1818

19-
struct GeneratorOptions
19+
struct [[nodiscard]] GeneratorOptions
2020
{
2121
const GeneratorPaths paths;
2222
const bool verbose = false;
2323
const bool stubs = false;
2424
const bool noIntrospection = false;
2525
};
2626

27-
class Generator
27+
class [[nodiscard]] Generator
2828
{
2929
public:
3030
// Initialize the generator with the introspection schema or a custom GraphQL schema.
3131
explicit Generator(SchemaOptions&& schemaOptions, GeneratorOptions&& options);
3232

3333
// Run the generator and return a list of filenames that were output.
34-
std::vector<std::string> Build() const noexcept;
34+
[[nodiscard]] std::vector<std::string> Build() const noexcept;
3535

3636
private:
37-
std::string getHeaderDir() const noexcept;
38-
std::string getSourceDir() const noexcept;
39-
std::string getHeaderPath() const noexcept;
40-
std::string getSourcePath() const noexcept;
37+
[[nodiscard]] std::string getHeaderDir() const noexcept;
38+
[[nodiscard]] std::string getSourceDir() const noexcept;
39+
[[nodiscard]] std::string getHeaderPath() const noexcept;
40+
[[nodiscard]] std::string getSourcePath() const noexcept;
4141

42-
bool outputHeader() const noexcept;
42+
[[nodiscard]] bool outputHeader() const noexcept;
4343
void outputInterfaceDeclaration(std::ostream& headerFile, std::string_view cppType) const;
4444
void outputObjectImplements(std::ostream& headerFile, const ObjectType& objectType) const;
4545
void outputObjectStubs(std::ostream& headerFile, const ObjectType& objectType) const;
4646
void outputObjectDeclaration(
4747
std::ostream& headerFile, const ObjectType& objectType, bool isQueryType) const;
48-
std::string getFieldDeclaration(const InputField& inputField) const noexcept;
49-
std::string getFieldDeclaration(const OutputField& outputField) const noexcept;
50-
std::string getResolverDeclaration(const OutputField& outputField) const noexcept;
48+
[[nodiscard]] std::string getFieldDeclaration(const InputField& inputField) const noexcept;
49+
[[nodiscard]] std::string getFieldDeclaration(const OutputField& outputField) const noexcept;
50+
[[nodiscard]] std::string getResolverDeclaration(const OutputField& outputField) const noexcept;
5151

52-
bool outputSource() const noexcept;
52+
[[nodiscard]] bool outputSource() const noexcept;
5353
void outputInterfaceImplementation(std::ostream& sourceFile, std::string_view cppType) const;
5454
void outputInterfaceIntrospection(
5555
std::ostream& sourceFile, const InterfaceType& interfaceType) const;
@@ -61,17 +61,18 @@ class Generator
6161
const std::vector<std::string_view>& interfaces) const;
6262
void outputIntrospectionFields(
6363
std::ostream& sourceFile, std::string_view cppType, const OutputFieldList& fields) const;
64-
std::string getArgumentDefaultValue(
64+
[[nodiscard]] std::string getArgumentDefaultValue(
6565
size_t level, const response::Value& defaultValue) const noexcept;
66-
std::string getArgumentDeclaration(const InputField& argument, const char* prefixToken,
67-
const char* argumentsToken, const char* defaultToken) const noexcept;
68-
std::string getArgumentAccessType(const InputField& argument) const noexcept;
69-
std::string getResultAccessType(const OutputField& result) const noexcept;
70-
std::string getTypeModifiers(const TypeModifierStack& modifiers) const noexcept;
71-
std::string getIntrospectionType(
66+
[[nodiscard]] std::string getArgumentDeclaration(const InputField& argument,
67+
const char* prefixToken, const char* argumentsToken,
68+
const char* defaultToken) const noexcept;
69+
[[nodiscard]] std::string getArgumentAccessType(const InputField& argument) const noexcept;
70+
[[nodiscard]] std::string getResultAccessType(const OutputField& result) const noexcept;
71+
[[nodiscard]] std::string getTypeModifiers(const TypeModifierStack& modifiers) const noexcept;
72+
[[nodiscard]] std::string getIntrospectionType(
7273
std::string_view type, const TypeModifierStack& modifiers) const noexcept;
7374

74-
std::vector<std::string> outputSeparateFiles() const noexcept;
75+
[[nodiscard]] std::vector<std::string> outputSeparateFiles() const noexcept;
7576

7677
static const std::string s_currentDirectory;
7778

0 commit comments

Comments
 (0)