-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathQueryObject.h
185 lines (150 loc) · 6.4 KB
/
QueryObject.h
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// WARNING! Do not edit this file manually, your changes will be overwritten.
#pragma once
#ifndef QUERYOBJECT_H
#define QUERYOBJECT_H
#include "StarWarsSchema.h"
namespace graphql::learn::object {
namespace methods::QueryHas {
template <class TImpl>
concept getHeroWithParams = requires (TImpl impl, service::FieldParams params, std::optional<Episode> episodeArg)
{
{ service::AwaitableObject<std::shared_ptr<Character>> { impl.getHero(std::move(params), std::move(episodeArg)) } };
};
template <class TImpl>
concept getHero = requires (TImpl impl, std::optional<Episode> episodeArg)
{
{ service::AwaitableObject<std::shared_ptr<Character>> { impl.getHero(std::move(episodeArg)) } };
};
template <class TImpl>
concept getHumanWithParams = requires (TImpl impl, service::FieldParams params, response::IdType idArg)
{
{ service::AwaitableObject<std::shared_ptr<Human>> { impl.getHuman(std::move(params), std::move(idArg)) } };
};
template <class TImpl>
concept getHuman = requires (TImpl impl, response::IdType idArg)
{
{ service::AwaitableObject<std::shared_ptr<Human>> { impl.getHuman(std::move(idArg)) } };
};
template <class TImpl>
concept getDroidWithParams = requires (TImpl impl, service::FieldParams params, response::IdType idArg)
{
{ service::AwaitableObject<std::shared_ptr<Droid>> { impl.getDroid(std::move(params), std::move(idArg)) } };
};
template <class TImpl>
concept getDroid = requires (TImpl impl, response::IdType idArg)
{
{ service::AwaitableObject<std::shared_ptr<Droid>> { impl.getDroid(std::move(idArg)) } };
};
template <class TImpl>
concept beginSelectionSet = requires (TImpl impl, const service::SelectionSetParams params)
{
{ impl.beginSelectionSet(params) };
};
template <class TImpl>
concept endSelectionSet = requires (TImpl impl, const service::SelectionSetParams params)
{
{ impl.endSelectionSet(params) };
};
} // namespace methods::QueryHas
class [[nodiscard("unnecessary construction")]] Query final
: public service::Object
{
private:
[[nodiscard("unnecessary call")]] service::AwaitableResolver resolveHero(service::ResolverParams&& params) const;
[[nodiscard("unnecessary call")]] service::AwaitableResolver resolveHuman(service::ResolverParams&& params) const;
[[nodiscard("unnecessary call")]] service::AwaitableResolver resolveDroid(service::ResolverParams&& params) const;
[[nodiscard("unnecessary call")]] service::AwaitableResolver resolve_typename(service::ResolverParams&& params) const;
[[nodiscard("unnecessary call")]] service::AwaitableResolver resolve_schema(service::ResolverParams&& params) const;
[[nodiscard("unnecessary call")]] service::AwaitableResolver resolve_type(service::ResolverParams&& params) const;
std::shared_ptr<schema::Schema> _schema;
struct [[nodiscard("unnecessary construction")]] Concept
{
virtual ~Concept() = default;
virtual void beginSelectionSet(const service::SelectionSetParams& params) const = 0;
virtual void endSelectionSet(const service::SelectionSetParams& params) const = 0;
[[nodiscard("unnecessary call")]] virtual service::AwaitableObject<std::shared_ptr<Character>> getHero(service::FieldParams&& params, std::optional<Episode>&& episodeArg) const = 0;
[[nodiscard("unnecessary call")]] virtual service::AwaitableObject<std::shared_ptr<Human>> getHuman(service::FieldParams&& params, response::IdType&& idArg) const = 0;
[[nodiscard("unnecessary call")]] virtual service::AwaitableObject<std::shared_ptr<Droid>> getDroid(service::FieldParams&& params, response::IdType&& idArg) const = 0;
};
template <class T>
struct [[nodiscard("unnecessary construction")]] Model final
: Concept
{
explicit Model(std::shared_ptr<T> pimpl) noexcept
: _pimpl { std::move(pimpl) }
{
}
[[nodiscard("unnecessary call")]] service::AwaitableObject<std::shared_ptr<Character>> getHero(service::FieldParams&& params, std::optional<Episode>&& episodeArg) const override
{
if constexpr (methods::QueryHas::getHeroWithParams<T>)
{
return { _pimpl->getHero(std::move(params), std::move(episodeArg)) };
}
else
{
static_assert(methods::QueryHas::getHero<T>, R"msg(Query::getHero is not implemented)msg");
return { _pimpl->getHero(std::move(episodeArg)) };
}
}
[[nodiscard("unnecessary call")]] service::AwaitableObject<std::shared_ptr<Human>> getHuman(service::FieldParams&& params, response::IdType&& idArg) const override
{
if constexpr (methods::QueryHas::getHumanWithParams<T>)
{
return { _pimpl->getHuman(std::move(params), std::move(idArg)) };
}
else
{
static_assert(methods::QueryHas::getHuman<T>, R"msg(Query::getHuman is not implemented)msg");
return { _pimpl->getHuman(std::move(idArg)) };
}
}
[[nodiscard("unnecessary call")]] service::AwaitableObject<std::shared_ptr<Droid>> getDroid(service::FieldParams&& params, response::IdType&& idArg) const override
{
if constexpr (methods::QueryHas::getDroidWithParams<T>)
{
return { _pimpl->getDroid(std::move(params), std::move(idArg)) };
}
else
{
static_assert(methods::QueryHas::getDroid<T>, R"msg(Query::getDroid is not implemented)msg");
return { _pimpl->getDroid(std::move(idArg)) };
}
}
void beginSelectionSet(const service::SelectionSetParams& params) const override
{
if constexpr (methods::QueryHas::beginSelectionSet<T>)
{
_pimpl->beginSelectionSet(params);
}
}
void endSelectionSet(const service::SelectionSetParams& params) const override
{
if constexpr (methods::QueryHas::endSelectionSet<T>)
{
_pimpl->endSelectionSet(params);
}
}
private:
const std::shared_ptr<T> _pimpl;
};
explicit Query(std::unique_ptr<const Concept> pimpl) noexcept;
[[nodiscard("unnecessary call")]] service::TypeNames getTypeNames() const noexcept;
[[nodiscard("unnecessary call")]] service::ResolverMap getResolvers() const noexcept;
void beginSelectionSet(const service::SelectionSetParams& params) const override;
void endSelectionSet(const service::SelectionSetParams& params) const override;
const std::unique_ptr<const Concept> _pimpl;
public:
template <class T>
explicit Query(std::shared_ptr<T> pimpl) noexcept
: Query { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}
[[nodiscard("unnecessary call")]] static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Query)gql" };
}
};
} // namespace graphql::learn::object
#endif // QUERYOBJECT_H