FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppgraphqlgen/samples/learn/schema/QueryObject.cpp at main · wravery/cppgraphqlgen · GitHub
wravery
cppgraphqlgen
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppgraphqlgen
/
samples
/
learn
/
schema
/
QueryObject.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
135 lines (110 loc) · 5.87 KB
Breadcrumbs
cppgraphqlgen
/
samples
/
learn
/
schema
/
QueryObject.cpp
Copy path
File metadata and controls
135 lines (110 loc) · 5.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
Copyright (c) Microsoft Corporation. All rights reserved.
//
Licensed under the MIT License.
//
WARNING! Do not edit this file manually, your changes will be overwritten.
#
include
"
QueryObject.h
"
#
include
"
CharacterObject.h
"
#
include
"
HumanObject.h
"
#
include
"
DroidObject.h
"
#
include
"
graphqlservice/internal/Introspection.h
"
#
include
"
graphqlservice/introspection/SchemaObject.h
"
#
include
"
graphqlservice/introspection/TypeObject.h
"
#
include
<
algorithm
>
#
include
<
functional
>
#
include
<
sstream
>
#
include
<
stdexcept
>
#
include
<
unordered_map
>
using
namespace
std
::literals
;
namespace
graphql
::learn {
namespace
object
{
Query::Query
(std::unique_ptr<
const
Concept> pimpl)
noexcept
: service::Object{
getTypeNames
(),
getResolvers
() }
, _schema {
GetSchema
() }
, _pimpl {
std::move
(pimpl) }
{
}
service::TypeNames
Query::getTypeNames
()
const
noexcept
{
return
{
R"gql(
Query
)gql"
sv
};
}
service::ResolverMap
Query::getResolvers
()
const
noexcept
{
return
{
{
R"gql(
hero
)gql"
sv, [
this
](service::ResolverParams&& params) {
return
resolveHero
(
std::move
(params)); } },
{
R"gql(
droid
)gql"
sv, [
this
](service::ResolverParams&& params) {
return
resolveDroid
(
std::move
(params)); } },
{
R"gql(
human
)gql"
sv, [
this
](service::ResolverParams&& params) {
return
resolveHuman
(
std::move
(params)); } },
{
R"gql(
__type
)gql"
sv, [
this
](service::ResolverParams&& params) {
return
resolve_type
(
std::move
(params)); } },
{
R"gql(
__schema
)gql"
sv, [
this
](service::ResolverParams&& params) {
return
resolve_schema
(
std::move
(params)); } },
{
R"gql(
__typename
)gql"
sv, [
this
](service::ResolverParams&& params) {
return
resolve_typename
(
std::move
(params)); } }
};
}
void
Query::beginSelectionSet
(
const
service::SelectionSetParams& params)
const
{
_pimpl->
beginSelectionSet
(params);
}
void
Query::endSelectionSet
(
const
service::SelectionSetParams& params)
const
{
_pimpl->
endSelectionSet
(params);
}
service::AwaitableResolver
Query::resolveHero
(service::ResolverParams&& params)
const
{
auto
argEpisode = service::ModifiedArgument<learn::Episode>::require<service::TypeModifier::Nullable>(
"
episode
"
, params.
arguments
);
std::unique_lock
resolverLock
(_resolverMutex);
service::SelectionSetParams selectionSetParams {
static_cast
<
const
service::SelectionSetParams&>(params) };
auto
directives =
std::move
(params.
fieldDirectives
);
auto
result = _pimpl->
getHero
(service::FieldParams {
std::move
(selectionSetParams),
std::move
(directives) },
std::move
(argEpisode));
resolverLock.
unlock
();
return
service::ModifiedResult<Character>::convert<service::TypeModifier::Nullable>(
std::move
(result),
std::move
(params));
}
service::AwaitableResolver
Query::resolveHuman
(service::ResolverParams&& params)
const
{
auto
argId = service::ModifiedArgument<response::IdType>::
require
(
"
id
"
, params.
arguments
);
std::unique_lock
resolverLock
(_resolverMutex);
service::SelectionSetParams selectionSetParams {
static_cast
<
const
service::SelectionSetParams&>(params) };
auto
directives =
std::move
(params.
fieldDirectives
);
auto
result = _pimpl->
getHuman
(service::FieldParams {
std::move
(selectionSetParams),
std::move
(directives) },
std::move
(argId));
resolverLock.
unlock
();
return
service::ModifiedResult<Human>::convert<service::TypeModifier::Nullable>(
std::move
(result),
std::move
(params));
}
service::AwaitableResolver
Query::resolveDroid
(service::ResolverParams&& params)
const
{
auto
argId = service::ModifiedArgument<response::IdType>::
require
(
"
id
"
, params.
arguments
);
std::unique_lock
resolverLock
(_resolverMutex);
service::SelectionSetParams selectionSetParams {
static_cast
<
const
service::SelectionSetParams&>(params) };
auto
directives =
std::move
(params.
fieldDirectives
);
auto
result = _pimpl->
getDroid
(service::FieldParams {
std::move
(selectionSetParams),
std::move
(directives) },
std::move
(argId));
resolverLock.
unlock
();
return
service::ModifiedResult<Droid>::convert<service::TypeModifier::Nullable>(
std::move
(result),
std::move
(params));
}
service::AwaitableResolver
Query::resolve_typename
(service::ResolverParams&& params)
const
{
return
service::Result<std::string>::
convert
(std::string{
R"gql(
Query
)gql"
},
std::move
(params));
}
service::AwaitableResolver
Query::resolve_schema
(service::ResolverParams&& params)
const
{
return
service::Result<service::Object>::
convert
(std::static_pointer_cast<service::Object>(std::make_shared<introspection::object::Schema>(std::make_shared<introspection::Schema>(_schema))),
std::move
(params));
}
service::AwaitableResolver
Query::resolve_type
(service::ResolverParams&& params)
const
{
auto
argName = service::ModifiedArgument<std::string>::
require
(
"
name
"
, params.
arguments
);
const
auto
& baseType = _schema->
LookupType
(argName);
std::shared_ptr<introspection::object::Type> result { baseType ? std::make_shared<introspection::object::Type>(std::make_shared<introspection::Type>(baseType)) :
nullptr
};
return
service::ModifiedResult<introspection::object::Type>::convert<service::TypeModifier::Nullable>(result,
std::move
(params));
}
}
//
namespace object
void
AddQueryDetails
(
const
std::shared_ptr<schema::ObjectType>& typeQuery,
const
std::shared_ptr<schema::Schema>& schema)
{
typeQuery->
AddFields
({
schema::Field::Make
(
R"gql(
hero
)gql"
sv,
R"md(
)md"
sv, std::
nullopt
, schema->
LookupType
(
R"gql(
Character
)gql"
sv), {
schema::InputValue::Make
(
R"gql(
episode
)gql"
sv,
R"md(
)md"
sv, schema->
LookupType
(
R"gql(
Episode
)gql"
sv),
R"gql(
)gql"
sv)
}),
schema::Field::Make
(
R"gql(
human
)gql"
sv,
R"md(
)md"
sv, std::
nullopt
, schema->
LookupType
(
R"gql(
Human
)gql"
sv), {
schema::InputValue::Make
(
R"gql(
id
)gql"
sv,
R"md(
)md"
sv, schema->
WrapType
(introspection::TypeKind::
NON_NULL
, schema->
LookupType
(
R"gql(
ID
)gql"
sv)),
R"gql(
)gql"
sv)
}),
schema::Field::Make
(
R"gql(
droid
)gql"
sv,
R"md(
)md"
sv, std::
nullopt
, schema->
LookupType
(
R"gql(
Droid
)gql"
sv), {
schema::InputValue::Make
(
R"gql(
id
)gql"
sv,
R"md(
)md"
sv, schema->
WrapType
(introspection::TypeKind::
NON_NULL
, schema->
LookupType
(
R"gql(
ID
)gql"
sv)),
R"gql(
)gql"
sv)
})
});
}
}
//
namespace graphql::learn
Back
|
FazBrowse Home
|
New Git URL