forked from microsoft/cppgraphqlgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratorLoader.h
More file actions
75 lines (58 loc) · 2.21 KB
/
Copy pathGeneratorLoader.h
File metadata and controls
75 lines (58 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#ifndef GENERATORLOADER_H
#define GENERATORLOADER_H
#include "graphqlservice/GraphQLService.h"
namespace graphql::generator {
// Types that we understand and use to generate the skeleton of a service.
enum class [[nodiscard("unnecessary conversion")]] SchemaType {
Scalar,
Enum,
Input,
Union,
Interface,
Object,
Operation,
};
using SchemaTypeMap = std::map<std::string_view, SchemaType>;
// Any type can also have a list and/or non-nullable wrapper, and those can be nested.
// Since it's easier to express nullability than non-nullability in C++, we'll invert
// the presence of NonNull modifiers.
using TypeModifierStack = std::vector<service::TypeModifier>;
// Recursively visit a Type node until we reach a NamedType and we've
// taken stock of all of the modifier wrappers.
class [[nodiscard("unnecessary construction")]] TypeVisitor
{
public:
[[nodiscard("unnecessary construction")]] std::pair<std::string_view, TypeModifierStack>
getType();
void visit(const peg::ast_node& typeName);
private:
void visitNamedType(const peg::ast_node& namedType);
void visitListType(const peg::ast_node& listType);
void visitNonNullType(const peg::ast_node& nonNullType);
std::string_view _type;
TypeModifierStack _modifiers;
bool _nonNull = false;
};
// Recursively visit a Value node representing the default value on an input field
// and build a JSON representation of the hardcoded value.
class [[nodiscard("unnecessary construction")]] DefaultValueVisitor
{
public:
[[nodiscard("unnecessary construction")]] response::Value getValue();
void visit(const peg::ast_node& value);
private:
void visitIntValue(const peg::ast_node& intValue);
void visitFloatValue(const peg::ast_node& floatValue);
void visitStringValue(const peg::ast_node& stringValue);
void visitBooleanValue(const peg::ast_node& booleanValue);
void visitNullValue(const peg::ast_node& nullValue);
void visitEnumValue(const peg::ast_node& enumValue);
void visitListValue(const peg::ast_node& listValue);
void visitObjectValue(const peg::ast_node& objectValue);
response::Value _value;
};
} // namespace graphql::generator
#endif // GENERATORLOADER_H