Skip to content

Commit cbb9ab6

Browse files
committed
Test clientgen with forward declaration and fix indent
1 parent abfc225 commit cbb9ab6

File tree

8 files changed

+345
-1
lines changed

8 files changed

+345
-1
lines changed

samples/client/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cmake_minimum_required(VERSION 3.15)
66
add_subdirectory(query)
77
add_subdirectory(mutate)
88
add_subdirectory(subscribe)
9+
add_subdirectory(nestedinput)
910

1011
add_subdirectory(benchmark)
1112

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
cmake_minimum_required(VERSION 3.15)
5+
6+
# Normally this would be handled by find_package(cppgraphqlgen CONFIG).
7+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake)
8+
9+
if(GRAPHQL_UPDATE_SAMPLES AND GRAPHQL_BUILD_CLIENTGEN)
10+
update_graphql_client_files(nestedinput schema.graphql query.graphql NestedInput nestedinput)
11+
endif()
12+
13+
add_graphql_client_target(nestedinput)
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// WARNING! Do not edit this file manually, your changes will be overwritten.
5+
6+
#include "NestedInputClient.h"
7+
8+
#include <algorithm>
9+
#include <array>
10+
#include <sstream>
11+
#include <stdexcept>
12+
#include <string_view>
13+
14+
using namespace std::literals;
15+
16+
namespace graphql::client {
17+
18+
using namespace query::testQuery;
19+
20+
template <>
21+
constexpr bool isInputType<Variables::InputA>() noexcept
22+
{
23+
return true;
24+
}
25+
26+
template <>
27+
constexpr bool isInputType<Variables::InputB>() noexcept
28+
{
29+
return true;
30+
}
31+
32+
template <>
33+
constexpr bool isInputType<Variables::InputABCD>() noexcept
34+
{
35+
return true;
36+
}
37+
38+
template <>
39+
constexpr bool isInputType<Variables::InputBC>() noexcept
40+
{
41+
return true;
42+
}
43+
44+
template <>
45+
response::Value ModifiedVariable<Variables::InputA>::serialize(Variables::InputA&& inputValue)
46+
{
47+
response::Value result { response::Type::Map };
48+
49+
result.emplace_back(R"js(a)js"s, ModifiedVariable<bool>::serialize(std::move(inputValue.a)));
50+
51+
return result;
52+
}
53+
54+
template <>
55+
response::Value ModifiedVariable<Variables::InputB>::serialize(Variables::InputB&& inputValue)
56+
{
57+
response::Value result { response::Type::Map };
58+
59+
result.emplace_back(R"js(b)js"s, ModifiedVariable<double>::serialize(std::move(inputValue.b)));
60+
61+
return result;
62+
}
63+
64+
template <>
65+
response::Value ModifiedVariable<Variables::InputABCD>::serialize(Variables::InputABCD&& inputValue)
66+
{
67+
response::Value result { response::Type::Map };
68+
69+
result.emplace_back(R"js(d)js"s, ModifiedVariable<std::string>::serialize(std::move(inputValue.d)));
70+
result.emplace_back(R"js(a)js"s, ModifiedVariable<InputA>::serialize(std::move(inputValue.a)));
71+
result.emplace_back(R"js(b)js"s, ModifiedVariable<InputB>::serialize(std::move(inputValue.b)));
72+
result.emplace_back(R"js(bc)js"s, ModifiedVariable<InputBC>::serialize<TypeModifier::List>(std::move(inputValue.bc)));
73+
74+
return result;
75+
}
76+
77+
template <>
78+
response::Value ModifiedVariable<Variables::InputBC>::serialize(Variables::InputBC&& inputValue)
79+
{
80+
response::Value result { response::Type::Map };
81+
82+
result.emplace_back(R"js(c)js"s, ModifiedVariable<response::IdType>::serialize(std::move(inputValue.c)));
83+
result.emplace_back(R"js(b)js"s, ModifiedVariable<InputB>::serialize(std::move(inputValue.b)));
84+
85+
return result;
86+
}
87+
88+
template <>
89+
Response::control_Control::test_Output ModifiedResponse<Response::control_Control::test_Output>::parse(response::Value&& response)
90+
{
91+
Response::control_Control::test_Output result;
92+
93+
if (response.type() == response::Type::Map)
94+
{
95+
auto members = response.release<response::MapType>();
96+
97+
for (auto& member : members)
98+
{
99+
if (member.first == R"js(id)js"sv)
100+
{
101+
result.id = ModifiedResponse<bool>::parse<TypeModifier::Nullable>(std::move(member.second));
102+
continue;
103+
}
104+
}
105+
}
106+
107+
return result;
108+
}
109+
110+
template <>
111+
Response::control_Control ModifiedResponse<Response::control_Control>::parse(response::Value&& response)
112+
{
113+
Response::control_Control result;
114+
115+
if (response.type() == response::Type::Map)
116+
{
117+
auto members = response.release<response::MapType>();
118+
119+
for (auto& member : members)
120+
{
121+
if (member.first == R"js(test)js"sv)
122+
{
123+
result.test = ModifiedResponse<Response::control_Control::test_Output>::parse<TypeModifier::Nullable>(std::move(member.second));
124+
continue;
125+
}
126+
}
127+
}
128+
129+
return result;
130+
}
131+
132+
namespace query::testQuery {
133+
134+
const std::string& GetRequestText() noexcept
135+
{
136+
static const auto s_request = R"gql(
137+
query testQuery($stream: InputABCD!) {
138+
control {
139+
test(new: $stream) {
140+
id
141+
}
142+
}
143+
}
144+
)gql"s;
145+
146+
return s_request;
147+
}
148+
149+
const peg::ast& GetRequestObject() noexcept
150+
{
151+
static const auto s_request = []() noexcept {
152+
auto ast = peg::parseString(GetRequestText());
153+
154+
// This has already been validated against the schema by clientgen.
155+
ast.validated = true;
156+
157+
return ast;
158+
}();
159+
160+
return s_request;
161+
}
162+
163+
response::Value serializeVariables(Variables&& variables)
164+
{
165+
response::Value result { response::Type::Map };
166+
167+
result.emplace_back(R"js(stream)js"s, ModifiedVariable<Variables::InputABCD>::serialize(std::move(variables.stream)));
168+
169+
return result;
170+
}
171+
172+
Response parseResponse(response::Value&& response)
173+
{
174+
Response result;
175+
176+
if (response.type() == response::Type::Map)
177+
{
178+
auto members = response.release<response::MapType>();
179+
180+
for (auto& member : members)
181+
{
182+
if (member.first == R"js(control)js"sv)
183+
{
184+
result.control = ModifiedResponse<Response::control_Control>::parse(std::move(member.second));
185+
continue;
186+
}
187+
}
188+
}
189+
190+
return result;
191+
}
192+
193+
} // namespace query::testQuery
194+
} // namespace graphql::client
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// WARNING! Do not edit this file manually, your changes will be overwritten.
5+
6+
#pragma once
7+
8+
#ifndef NESTEDINPUTCLIENT_H
9+
#define NESTEDINPUTCLIENT_H
10+
11+
#include "graphqlservice/GraphQLClient.h"
12+
#include "graphqlservice/GraphQLParse.h"
13+
#include "graphqlservice/GraphQLResponse.h"
14+
15+
#include "graphqlservice/internal/Version.h"
16+
17+
// Check if the library version is compatible with clientgen 4.2.0
18+
static_assert(graphql::internal::MajorVersion == 4, "regenerate with clientgen: major version mismatch");
19+
static_assert(graphql::internal::MinorVersion == 2, "regenerate with clientgen: minor version mismatch");
20+
21+
#include <optional>
22+
#include <string>
23+
#include <vector>
24+
25+
/// <summary>
26+
/// Operation: query testQuery
27+
/// </summary>
28+
/// <code class="language-graphql">
29+
/// query testQuery($stream: InputABCD!) {
30+
/// control {
31+
/// test(new: $stream) {
32+
/// id
33+
/// }
34+
/// }
35+
/// }
36+
/// </code>
37+
namespace graphql::client::query::testQuery {
38+
39+
// Return the original text of the request document.
40+
const std::string& GetRequestText() noexcept;
41+
42+
// Return a pre-parsed, pre-validated request object.
43+
const peg::ast& GetRequestObject() noexcept;
44+
45+
struct Variables
46+
{
47+
struct InputA
48+
{
49+
bool a {};
50+
};
51+
52+
struct InputB
53+
{
54+
double b {};
55+
};
56+
57+
struct InputBC;
58+
59+
struct InputABCD
60+
{
61+
std::string d {};
62+
InputA a {};
63+
InputB b {};
64+
std::vector<InputBC> bc {};
65+
};
66+
67+
struct InputBC
68+
{
69+
response::IdType c {};
70+
InputB b {};
71+
};
72+
73+
InputABCD stream {};
74+
};
75+
76+
response::Value serializeVariables(Variables&& variables);
77+
78+
struct Response
79+
{
80+
struct control_Control
81+
{
82+
struct test_Output
83+
{
84+
std::optional<bool> id {};
85+
};
86+
87+
std::optional<test_Output> test {};
88+
};
89+
90+
control_Control control {};
91+
};
92+
93+
Response parseResponse(response::Value&& response);
94+
95+
} // namespace graphql::client::query::testQuery
96+
97+
#endif // NESTEDINPUTCLIENT_H
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NestedInputClient.cpp
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
query testQuery($stream: InputABCD!) {
2+
control {
3+
test(new: $stream) {
4+
id
5+
}
6+
}
7+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
input InputA {
2+
a: Boolean!
3+
}
4+
5+
input InputB {
6+
b: Float!
7+
}
8+
9+
input InputBC {
10+
c: ID!
11+
b: InputB!
12+
}
13+
14+
input InputABCD {
15+
d: String!
16+
a: InputA!
17+
b: InputB!
18+
bc: [InputBC!]!
19+
}
20+
21+
type Output {
22+
id:Boolean
23+
}
24+
25+
type Control {
26+
test(new: InputABCD!): Output
27+
}
28+
29+
type Query {
30+
control: Control!
31+
}

src/ClientGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static_assert(graphql::internal::MinorVersion == )cpp"
247247
{
248248
if (forwardDeclared.insert(declaration).second)
249249
{
250-
headerFile << R"cpp(struct )cpp" << declaration << R"cpp(;
250+
headerFile << R"cpp( struct )cpp" << declaration << R"cpp(;
251251
)cpp";
252252
pendingSeparator.add();
253253
}

0 commit comments

Comments
 (0)