Skip to content

Commit 7e962a2

Browse files
authored
Merge pull request #273 from wravery/client-api-structs
Expose a Traits struct for each client operation for easier templating
2 parents e652672 + 06e0c5a commit 7e962a2

18 files changed

+475
-37
lines changed

.github/workflows/macos.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,18 @@ jobs:
2020
uses: actions/cache@v2
2121
id: cache-vcpkg
2222
with:
23-
path: vcpkg/
23+
path: build/vcpkg_installed/
2424
key: vcpkg-x64-osx
2525

26-
- name: Install Dependencies
27-
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
28-
shell: pwsh
29-
run: |
30-
git clone https://github.com/microsoft/vcpkg
31-
cd vcpkg
32-
./bootstrap-vcpkg.sh -allowAppleClang
33-
./vcpkg integrate install
34-
./vcpkg install boost-program-options rapidjson gtest
35-
3626
- name: Create Build Environment
27+
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
3728
run: cmake -E make_directory build
3829

3930
- name: Configure
4031
shell: pwsh
4132
working-directory: build/
4233
run: |
43-
$vcpkgToolchain = Join-Path '../vcpkg' './scripts/buildsystems/vcpkg.cmake' -Resolve
34+
$vcpkgToolchain = Join-Path $env:VCPKG_ROOT './scripts/buildsystems/vcpkg.cmake' -Resolve
4435
$cmakeBuildType = '${{ matrix.config }}'
4536
4637
cmake "-DCMAKE_TOOLCHAIN_FILE=$vcpkgToolchain" "-DCMAKE_BUILD_TYPE=$cmakeBuildType" ${{ github.workspace }}

.github/workflows/windows.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,18 @@ jobs:
2727
uses: actions/cache@v2
2828
id: cache-vcpkg
2929
with:
30-
path: vcpkg/
30+
path: build/vcpkg_installed/
3131
key: vcpkg-${{ steps.set-variables.outputs.vcpkg_triplet }}
3232

33-
- name: Install Dependencies
34-
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
35-
shell: pwsh
36-
run: |
37-
git clone https://github.com/microsoft/vcpkg
38-
cd vcpkg
39-
.\bootstrap-vcpkg.bat
40-
.\vcpkg integrate install
41-
.\vcpkg install boost-program-options rapidjson gtest --triplet ${{ steps.set-variables.outputs.vcpkg_triplet }}
42-
4333
- name: Create Build Environment
34+
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
4435
run: cmake -E make_directory build
4536

4637
- name: Configure
4738
shell: pwsh
4839
working-directory: build/
4940
run: |
50-
$vcpkgToolchain = Join-Path '..\vcpkg' '.\scripts\buildsystems\vcpkg.cmake' -Resolve
41+
$vcpkgToolchain = Join-Path $env:VCPKG_ROOT '.\scripts\buildsystems\vcpkg.cmake' -Resolve
5142
$vcpkgTriplet = '${{ steps.set-variables.outputs.vcpkg_triplet }}'
5243
$cmakeSharedLibs = $(if ('${{ matrix.libs }}' -eq 'shared') { 'ON' } else { 'OFF' })
5344
$msbuildArch = $(if ('${{ matrix.arch }}' -eq 'x64') { 'X64' } else { 'Win32' })

CMakeLists.txt

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,32 @@ if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
3131
endif()
3232
endif()
3333

34+
option(GRAPHQL_BUILD_SCHEMAGEN "Build the schemagen tool." ON)
35+
option(GRAPHQL_BUILD_CLIENTGEN "Build the clientgen tool." ON)
36+
option(GRAPHQL_BUILD_TESTS "Build the tests and sample schema library." ON)
37+
38+
if(GRAPHQL_BUILD_SCHEMAGEN)
39+
list(APPEND VCPKG_MANIFEST_FEATURES "schemagen")
40+
endif()
41+
42+
if(GRAPHQL_BUILD_CLIENTGEN)
43+
list(APPEND VCPKG_MANIFEST_FEATURES "clientgen")
44+
endif()
45+
46+
if(GRAPHQL_BUILD_TESTS)
47+
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
48+
endif()
49+
50+
if(GRAPHQL_BUILD_SCHEMAGEN AND GRAPHQL_BUILD_CLIENTGEN)
51+
option(GRAPHQL_UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests." ON)
52+
53+
if(GRAPHQL_UPDATE_SAMPLES)
54+
list(APPEND VCPKG_MANIFEST_FEATURES "update-samples")
55+
endif()
56+
else()
57+
set(GRAPHQL_UPDATE_SAMPLES OFF CACHE BOOL "Disable regenerating samples." FORCE)
58+
endif()
59+
3460
project(cppgraphqlgen VERSION ${LATEST_VERSION})
3561

3662
set(GRAPHQL_INSTALL_INCLUDE_DIR include CACHE PATH "Header file install directory")
@@ -81,16 +107,6 @@ if(NOT pegtl_FOUND)
81107
add_subdirectory(PEGTL)
82108
endif()
83109

84-
option(GRAPHQL_BUILD_SCHEMAGEN "Build the schemagen tool." ON)
85-
86-
if(GRAPHQL_BUILD_SCHEMAGEN)
87-
option(GRAPHQL_UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests." ON)
88-
else()
89-
set(GRAPHQL_UPDATE_SAMPLES OFF CACHE BOOL "Disable regenerating samples." FORCE)
90-
endif()
91-
92-
option(GRAPHQL_BUILD_CLIENTGEN "Build the clientgen tool." ON)
93-
94110
option(GRAPHQL_UPDATE_VERSION "Regenerate graphqlservice/internal/Version.h and all of the version info rc files for Windows." ON)
95111

96112
add_subdirectory(cmake)

samples/client/benchmark/BenchmarkClient.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,25 @@ Response parseResponse(response::Value&& response)
201201
return result;
202202
}
203203

204+
[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
205+
{
206+
return benchmark::GetRequestText();
207+
}
208+
209+
[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
210+
{
211+
return benchmark::GetRequestObject();
212+
}
213+
214+
[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
215+
{
216+
return Query::GetOperationName();
217+
}
218+
219+
[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
220+
{
221+
return Query::parseResponse(std::move(response));
222+
}
223+
204224
} // namespace query::Query
205225
} // namespace graphql::client

samples/client/benchmark/BenchmarkClient.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ struct [[nodiscard]] Response
9696

9797
[[nodiscard]] Response parseResponse(response::Value&& response);
9898

99+
struct Traits
100+
{
101+
[[nodiscard]] static const std::string& GetRequestText() noexcept;
102+
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
103+
[[nodiscard]] static const std::string& GetOperationName() noexcept;
104+
105+
using Response = Query::Response;
106+
107+
[[nodiscard]] static Response parseResponse(response::Value&& response);
108+
};
109+
99110
} // namespace query::Query
100111
} // namespace graphql::client
101112

samples/client/multiple/MultipleQueriesClient.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,26 @@ Response parseResponse(response::Value&& response)
288288
return result;
289289
}
290290

291+
[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
292+
{
293+
return multiple::GetRequestText();
294+
}
295+
296+
[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
297+
{
298+
return multiple::GetRequestObject();
299+
}
300+
301+
[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
302+
{
303+
return Appointments::GetOperationName();
304+
}
305+
306+
[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
307+
{
308+
return Appointments::parseResponse(std::move(response));
309+
}
310+
291311
} // namespace query::Appointments
292312

293313
template <>
@@ -401,6 +421,26 @@ Response parseResponse(response::Value&& response)
401421
return result;
402422
}
403423

424+
[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
425+
{
426+
return multiple::GetRequestText();
427+
}
428+
429+
[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
430+
{
431+
return multiple::GetRequestObject();
432+
}
433+
434+
[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
435+
{
436+
return Tasks::GetOperationName();
437+
}
438+
439+
[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
440+
{
441+
return Tasks::parseResponse(std::move(response));
442+
}
443+
404444
} // namespace query::Tasks
405445

406446
template <>
@@ -514,6 +554,26 @@ Response parseResponse(response::Value&& response)
514554
return result;
515555
}
516556

557+
[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
558+
{
559+
return multiple::GetRequestText();
560+
}
561+
562+
[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
563+
{
564+
return multiple::GetRequestObject();
565+
}
566+
567+
[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
568+
{
569+
return UnreadCounts::GetOperationName();
570+
}
571+
572+
[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
573+
{
574+
return UnreadCounts::parseResponse(std::move(response));
575+
}
576+
517577
} // namespace query::UnreadCounts
518578

519579
template <>
@@ -635,6 +695,26 @@ Response parseResponse(response::Value&& response)
635695
return result;
636696
}
637697

698+
[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
699+
{
700+
return multiple::GetRequestText();
701+
}
702+
703+
[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
704+
{
705+
return multiple::GetRequestObject();
706+
}
707+
708+
[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
709+
{
710+
return Miscellaneous::GetOperationName();
711+
}
712+
713+
[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
714+
{
715+
return Miscellaneous::parseResponse(std::move(response));
716+
}
717+
638718
} // namespace query::Miscellaneous
639719

640720
template <>
@@ -766,5 +846,30 @@ Response parseResponse(response::Value&& response)
766846
return result;
767847
}
768848

849+
[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
850+
{
851+
return multiple::GetRequestText();
852+
}
853+
854+
[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
855+
{
856+
return multiple::GetRequestObject();
857+
}
858+
859+
[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
860+
{
861+
return CompleteTaskMutation::GetOperationName();
862+
}
863+
864+
[[nodiscard]] response::Value Traits::serializeVariables(Traits::Variables&& variables)
865+
{
866+
return CompleteTaskMutation::serializeVariables(std::move(variables));
867+
}
868+
869+
[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
870+
{
871+
return CompleteTaskMutation::parseResponse(std::move(response));
872+
}
873+
769874
} // namespace mutation::CompleteTaskMutation
770875
} // namespace graphql::client

samples/client/multiple/MultipleQueriesClient.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ struct [[nodiscard]] Response
180180

181181
[[nodiscard]] Response parseResponse(response::Value&& response);
182182

183+
struct Traits
184+
{
185+
[[nodiscard]] static const std::string& GetRequestText() noexcept;
186+
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
187+
[[nodiscard]] static const std::string& GetOperationName() noexcept;
188+
189+
using Response = Appointments::Response;
190+
191+
[[nodiscard]] static Response parseResponse(response::Value&& response);
192+
};
193+
183194
} // namespace query::Appointments
184195

185196
namespace query::Tasks {
@@ -215,6 +226,17 @@ struct [[nodiscard]] Response
215226

216227
[[nodiscard]] Response parseResponse(response::Value&& response);
217228

229+
struct Traits
230+
{
231+
[[nodiscard]] static const std::string& GetRequestText() noexcept;
232+
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
233+
[[nodiscard]] static const std::string& GetOperationName() noexcept;
234+
235+
using Response = Tasks::Response;
236+
237+
[[nodiscard]] static Response parseResponse(response::Value&& response);
238+
};
239+
218240
} // namespace query::Tasks
219241

220242
namespace query::UnreadCounts {
@@ -250,6 +272,17 @@ struct [[nodiscard]] Response
250272

251273
[[nodiscard]] Response parseResponse(response::Value&& response);
252274

275+
struct Traits
276+
{
277+
[[nodiscard]] static const std::string& GetRequestText() noexcept;
278+
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
279+
[[nodiscard]] static const std::string& GetOperationName() noexcept;
280+
281+
using Response = UnreadCounts::Response;
282+
283+
[[nodiscard]] static Response parseResponse(response::Value&& response);
284+
};
285+
253286
} // namespace query::UnreadCounts
254287

255288
namespace query::Miscellaneous {
@@ -282,6 +315,17 @@ struct [[nodiscard]] Response
282315

283316
[[nodiscard]] Response parseResponse(response::Value&& response);
284317

318+
struct Traits
319+
{
320+
[[nodiscard]] static const std::string& GetRequestText() noexcept;
321+
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
322+
[[nodiscard]] static const std::string& GetOperationName() noexcept;
323+
324+
using Response = Miscellaneous::Response;
325+
326+
[[nodiscard]] static Response parseResponse(response::Value&& response);
327+
};
328+
285329
} // namespace query::Miscellaneous
286330

287331
namespace mutation::CompleteTaskMutation {
@@ -324,6 +368,21 @@ struct [[nodiscard]] Response
324368

325369
[[nodiscard]] Response parseResponse(response::Value&& response);
326370

371+
struct Traits
372+
{
373+
[[nodiscard]] static const std::string& GetRequestText() noexcept;
374+
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
375+
[[nodiscard]] static const std::string& GetOperationName() noexcept;
376+
377+
using Variables = CompleteTaskMutation::Variables;
378+
379+
[[nodiscard]] static response::Value serializeVariables(Variables&& variables);
380+
381+
using Response = CompleteTaskMutation::Response;
382+
383+
[[nodiscard]] static Response parseResponse(response::Value&& response);
384+
};
385+
327386
} // namespace mutation::CompleteTaskMutation
328387
} // namespace graphql::client
329388

0 commit comments

Comments
 (0)