Skip to content

Commit 2379843

Browse files
authored
Merge pull request #86 from wravery/master
Make introspection type ordering consistent and add include guards
2 parents 97f05af + 7ab7d7f commit 2379843

29 files changed

+190
-22
lines changed

include/SchemaGenerator.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#pragma once
55

6+
#ifndef SCHEMAGENERATOR_H
7+
#define SCHEMAGENERATOR_H
8+
69
#include <graphqlservice/GraphQLService.h>
710
#include <graphqlservice/GraphQLGrammar.h>
811

@@ -21,7 +24,7 @@ enum class BuiltinType
2124
ID,
2225
};
2326

24-
using BuiltinTypeMap = std::unordered_map<std::string, BuiltinType>;
27+
using BuiltinTypeMap = std::map<std::string, BuiltinType>;
2528

2629
// These are the C++ types we'll use for them.
2730
using CppTypeMap = std::array<std::string, static_cast<size_t>(BuiltinType::ID) + 1>;
@@ -38,7 +41,7 @@ enum class SchemaType
3841
Operation,
3942
};
4043

41-
using SchemaTypeMap = std::unordered_map<std::string, SchemaType>;
44+
using SchemaTypeMap = std::map<std::string, SchemaType>;
4245

4346
// Keep track of the positions of each type declaration in the file.
4447
using PositionMap = std::unordered_map<std::string, tao::graphqlpeg::position>;
@@ -235,6 +238,18 @@ struct GeneratorOptions
235238
const bool noStubs = false;
236239
};
237240

241+
// RAII object to help with emitting matching include guard begin and end statements
242+
class IncludeGuardScope
243+
{
244+
public:
245+
explicit IncludeGuardScope(std::ostream& outputFile, std::string_view headerFileName) noexcept;
246+
~IncludeGuardScope() noexcept;
247+
248+
private:
249+
std::ostream& _outputFile;
250+
std::string _includeGuardName;
251+
};
252+
238253
// RAII object to help with emitting matching namespace begin and end statements
239254
class NamespaceScope
240255
{
@@ -399,3 +414,5 @@ class Generator
399414
};
400415

401416
} /* namespace graphql::schema */
417+
418+
#endif // SCHEMAGENERATOR_H

include/graphqlservice/GraphQLGrammar.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
#pragma once
88

9+
#ifndef GRAPHQLGRAMMAR_H
10+
#define GRAPHQLGRAMMAR_H
11+
912
#include <graphqlservice/GraphQLTree.h>
1013

1114
#define TAO_PEGTL_NAMESPACE tao::graphqlpeg
@@ -1316,3 +1319,5 @@ struct document
13161319
};
13171320

13181321
} /* namespace graphql::peg */
1322+
1323+
#endif // GRAPHQLGRAMMAR_H

include/graphqlservice/GraphQLParse.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#pragma once
55

6+
#ifndef GRAPHQLPARSE_H
7+
#define GRAPHQLPARSE_H
8+
69
#include <memory>
710
#include <string_view>
811

@@ -26,3 +29,5 @@ ast parseFile(std::string_view filename);
2629
peg::ast operator "" _graphql(const char* text, size_t size);
2730

2831
} /* namespace graphql */
32+
33+
#endif // GRAPHQLPARSE_H

include/graphqlservice/GraphQLResponse.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#pragma once
55

6+
#ifndef GRAPHQLRESPONSE_H
7+
#define GRAPHQLRESPONSE_H
8+
69
#include <memory>
710
#include <string>
811
#include <vector>
@@ -176,3 +179,5 @@ struct Value
176179
};
177180

178181
} /* namespace graphql::response */
182+
183+
#endif // GRAPHQLRESPONSE_H

include/graphqlservice/GraphQLService.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#pragma once
55

6+
#ifndef GRAPHQLSERVICE_H
7+
#define GRAPHQLSERVICE_H
8+
69
#include <graphqlservice/GraphQLParse.h>
710
#include <graphqlservice/GraphQLResponse.h>
811

@@ -736,3 +739,5 @@ class Request : public std::enable_shared_from_this<Request>
736739
};
737740

738741
} /* namespace graphql::service */
742+
743+
#endif // GRAPHQLSERVICE_H

include/graphqlservice/GraphQLTree.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#pragma once
55

6+
#ifndef GRAPHQLTREE_H
7+
#define GRAPHQLTREE_H
8+
69
#define TAO_PEGTL_NAMESPACE tao::graphqlpeg
710

811
#include <tao/pegtl.hpp>
@@ -27,3 +30,5 @@ struct ast_input
2730
};
2831

2932
} /* namespace graphql::peg */
33+
34+
#endif // GRAPHQLTREE_H

include/graphqlservice/Introspection.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#pragma once
55

6+
#ifndef INTROSPECTION_H
7+
#define INTROSPECTION_H
8+
69
#include <graphqlservice/IntrospectionSchema.h>
710

811
namespace graphql::introspection {
@@ -273,3 +276,5 @@ class Directive : public object::Directive
273276
};
274277

275278
} /* namespace graphql::introspection */
279+
280+
#endif // INTROSPECTION_H

include/graphqlservice/JSONResponse.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#pragma once
55

6+
#ifndef JSONRESPONSE_H
7+
#define JSONRESPONSE_H
8+
69
#include <graphqlservice/GraphQLResponse.h>
710

811
namespace graphql::response {
@@ -12,3 +15,5 @@ std::string toJSON(Value&& response);
1215
Value parseJSON(const std::string& json);
1316

1417
} /* namespace graphql::response */
18+
19+
#endif // JSONRESPONSE_H

samples/introspection/IntrospectionSchema.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,11 @@ std::future<response::Value> Directive::resolve_typename(service::ResolverParams
488488

489489
void AddTypesToSchema(std::shared_ptr<introspection::Schema> schema)
490490
{
491-
schema->AddType("Int", std::make_shared<introspection::ScalarType>("Int", R"md(Built-in type)md"));
491+
schema->AddType("Boolean", std::make_shared<introspection::ScalarType>("Boolean", R"md(Built-in type)md"));
492492
schema->AddType("Float", std::make_shared<introspection::ScalarType>("Float", R"md(Built-in type)md"));
493493
schema->AddType("ID", std::make_shared<introspection::ScalarType>("ID", R"md(Built-in type)md"));
494+
schema->AddType("Int", std::make_shared<introspection::ScalarType>("Int", R"md(Built-in type)md"));
494495
schema->AddType("String", std::make_shared<introspection::ScalarType>("String", R"md(Built-in type)md"));
495-
schema->AddType("Boolean", std::make_shared<introspection::ScalarType>("Boolean", R"md(Built-in type)md"));
496496
auto typeTypeKind = std::make_shared<introspection::EnumType>("__TypeKind", R"md()md");
497497
schema->AddType("__TypeKind", typeTypeKind);
498498
auto typeDirectiveLocation = std::make_shared<introspection::EnumType>("__DirectiveLocation", R"md()md");

samples/introspection/IntrospectionSchema.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#pragma once
55

6+
#ifndef INTROSPECTIONSCHEMA_H
7+
#define INTROSPECTIONSCHEMA_H
8+
69
#include <graphqlservice/GraphQLService.h>
710

811
#include <memory>
@@ -205,3 +208,5 @@ void AddTypesToSchema(std::shared_ptr<introspection::Schema> schema);
205208

206209
} /* namespace introspection */
207210
} /* namespace graphql */
211+
212+
#endif // INTROSPECTIONSCHEMA_H

0 commit comments

Comments
 (0)