Skip to content

Expose a Traits struct for each client operation for easier templating #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,18 @@ jobs:
uses: actions/cache@v2
id: cache-vcpkg
with:
path: vcpkg/
path: build/vcpkg_installed/
key: vcpkg-x64-osx

- name: Install Dependencies
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
shell: pwsh
run: |
git clone https://github.com/microsoft/vcpkg
cd vcpkg
./bootstrap-vcpkg.sh -allowAppleClang
./vcpkg integrate install
./vcpkg install boost-program-options rapidjson gtest

- name: Create Build Environment
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
run: cmake -E make_directory build

- name: Configure
shell: pwsh
working-directory: build/
run: |
$vcpkgToolchain = Join-Path '../vcpkg' './scripts/buildsystems/vcpkg.cmake' -Resolve
$vcpkgToolchain = Join-Path $env:VCPKG_ROOT './scripts/buildsystems/vcpkg.cmake' -Resolve
$cmakeBuildType = '${{ matrix.config }}'

cmake "-DCMAKE_TOOLCHAIN_FILE=$vcpkgToolchain" "-DCMAKE_BUILD_TYPE=$cmakeBuildType" ${{ github.workspace }}
Expand Down
15 changes: 3 additions & 12 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,18 @@ jobs:
uses: actions/cache@v2
id: cache-vcpkg
with:
path: vcpkg/
path: build/vcpkg_installed/
key: vcpkg-${{ steps.set-variables.outputs.vcpkg_triplet }}

- name: Install Dependencies
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
shell: pwsh
run: |
git clone https://github.com/microsoft/vcpkg
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg integrate install
.\vcpkg install boost-program-options rapidjson gtest --triplet ${{ steps.set-variables.outputs.vcpkg_triplet }}

- name: Create Build Environment
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
run: cmake -E make_directory build

- name: Configure
shell: pwsh
working-directory: build/
run: |
$vcpkgToolchain = Join-Path '..\vcpkg' '.\scripts\buildsystems\vcpkg.cmake' -Resolve
$vcpkgToolchain = Join-Path $env:VCPKG_ROOT '.\scripts\buildsystems\vcpkg.cmake' -Resolve
$vcpkgTriplet = '${{ steps.set-variables.outputs.vcpkg_triplet }}'
$cmakeSharedLibs = $(if ('${{ matrix.libs }}' -eq 'shared') { 'ON' } else { 'OFF' })
$msbuildArch = $(if ('${{ matrix.arch }}' -eq 'x64') { 'X64' } else { 'Win32' })
Expand Down
36 changes: 26 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
endif()
endif()

option(GRAPHQL_BUILD_SCHEMAGEN "Build the schemagen tool." ON)
option(GRAPHQL_BUILD_CLIENTGEN "Build the clientgen tool." ON)
option(GRAPHQL_BUILD_TESTS "Build the tests and sample schema library." ON)

if(GRAPHQL_BUILD_SCHEMAGEN)
list(APPEND VCPKG_MANIFEST_FEATURES "schemagen")
endif()

if(GRAPHQL_BUILD_CLIENTGEN)
list(APPEND VCPKG_MANIFEST_FEATURES "clientgen")
endif()

if(GRAPHQL_BUILD_TESTS)
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
endif()

if(GRAPHQL_BUILD_SCHEMAGEN AND GRAPHQL_BUILD_CLIENTGEN)
option(GRAPHQL_UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests." ON)

if(GRAPHQL_UPDATE_SAMPLES)
list(APPEND VCPKG_MANIFEST_FEATURES "update-samples")
endif()
else()
set(GRAPHQL_UPDATE_SAMPLES OFF CACHE BOOL "Disable regenerating samples." FORCE)
endif()

project(cppgraphqlgen VERSION ${LATEST_VERSION})

set(GRAPHQL_INSTALL_INCLUDE_DIR include CACHE PATH "Header file install directory")
Expand Down Expand Up @@ -81,16 +107,6 @@ if(NOT pegtl_FOUND)
add_subdirectory(PEGTL)
endif()

option(GRAPHQL_BUILD_SCHEMAGEN "Build the schemagen tool." ON)

if(GRAPHQL_BUILD_SCHEMAGEN)
option(GRAPHQL_UPDATE_SAMPLES "Regenerate the sample schema sources whether or not we're building the tests." ON)
else()
set(GRAPHQL_UPDATE_SAMPLES OFF CACHE BOOL "Disable regenerating samples." FORCE)
endif()

option(GRAPHQL_BUILD_CLIENTGEN "Build the clientgen tool." ON)

option(GRAPHQL_UPDATE_VERSION "Regenerate graphqlservice/internal/Version.h and all of the version info rc files for Windows." ON)

add_subdirectory(cmake)
Expand Down
20 changes: 20 additions & 0 deletions samples/client/benchmark/BenchmarkClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,25 @@ Response parseResponse(response::Value&& response)
return result;
}

[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
{
return benchmark::GetRequestText();
}

[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
{
return benchmark::GetRequestObject();
}

[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
{
return Query::GetOperationName();
}

[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
{
return Query::parseResponse(std::move(response));
}

} // namespace query::Query
} // namespace graphql::client
11 changes: 11 additions & 0 deletions samples/client/benchmark/BenchmarkClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ struct [[nodiscard]] Response

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

struct Traits
{
[[nodiscard]] static const std::string& GetRequestText() noexcept;
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
[[nodiscard]] static const std::string& GetOperationName() noexcept;

using Response = Query::Response;

[[nodiscard]] static Response parseResponse(response::Value&& response);
};

} // namespace query::Query
} // namespace graphql::client

Expand Down
105 changes: 105 additions & 0 deletions samples/client/multiple/MultipleQueriesClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,26 @@ Response parseResponse(response::Value&& response)
return result;
}

[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
{
return multiple::GetRequestText();
}

[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
{
return multiple::GetRequestObject();
}

[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
{
return Appointments::GetOperationName();
}

[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
{
return Appointments::parseResponse(std::move(response));
}

} // namespace query::Appointments

template <>
Expand Down Expand Up @@ -401,6 +421,26 @@ Response parseResponse(response::Value&& response)
return result;
}

[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
{
return multiple::GetRequestText();
}

[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
{
return multiple::GetRequestObject();
}

[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
{
return Tasks::GetOperationName();
}

[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
{
return Tasks::parseResponse(std::move(response));
}

} // namespace query::Tasks

template <>
Expand Down Expand Up @@ -514,6 +554,26 @@ Response parseResponse(response::Value&& response)
return result;
}

[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
{
return multiple::GetRequestText();
}

[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
{
return multiple::GetRequestObject();
}

[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
{
return UnreadCounts::GetOperationName();
}

[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
{
return UnreadCounts::parseResponse(std::move(response));
}

} // namespace query::UnreadCounts

template <>
Expand Down Expand Up @@ -635,6 +695,26 @@ Response parseResponse(response::Value&& response)
return result;
}

[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
{
return multiple::GetRequestText();
}

[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
{
return multiple::GetRequestObject();
}

[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
{
return Miscellaneous::GetOperationName();
}

[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
{
return Miscellaneous::parseResponse(std::move(response));
}

} // namespace query::Miscellaneous

template <>
Expand Down Expand Up @@ -766,5 +846,30 @@ Response parseResponse(response::Value&& response)
return result;
}

[[nodiscard]] const std::string& Traits::GetRequestText() noexcept
{
return multiple::GetRequestText();
}

[[nodiscard]] const peg::ast& Traits::GetRequestObject() noexcept
{
return multiple::GetRequestObject();
}

[[nodiscard]] const std::string& Traits::GetOperationName() noexcept
{
return CompleteTaskMutation::GetOperationName();
}

[[nodiscard]] response::Value Traits::serializeVariables(Traits::Variables&& variables)
{
return CompleteTaskMutation::serializeVariables(std::move(variables));
}

[[nodiscard]] Traits::Response Traits::parseResponse(response::Value&& response)
{
return CompleteTaskMutation::parseResponse(std::move(response));
}

} // namespace mutation::CompleteTaskMutation
} // namespace graphql::client
59 changes: 59 additions & 0 deletions samples/client/multiple/MultipleQueriesClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ struct [[nodiscard]] Response

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

struct Traits
{
[[nodiscard]] static const std::string& GetRequestText() noexcept;
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
[[nodiscard]] static const std::string& GetOperationName() noexcept;

using Response = Appointments::Response;

[[nodiscard]] static Response parseResponse(response::Value&& response);
};

} // namespace query::Appointments

namespace query::Tasks {
Expand Down Expand Up @@ -215,6 +226,17 @@ struct [[nodiscard]] Response

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

struct Traits
{
[[nodiscard]] static const std::string& GetRequestText() noexcept;
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
[[nodiscard]] static const std::string& GetOperationName() noexcept;

using Response = Tasks::Response;

[[nodiscard]] static Response parseResponse(response::Value&& response);
};

} // namespace query::Tasks

namespace query::UnreadCounts {
Expand Down Expand Up @@ -250,6 +272,17 @@ struct [[nodiscard]] Response

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

struct Traits
{
[[nodiscard]] static const std::string& GetRequestText() noexcept;
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
[[nodiscard]] static const std::string& GetOperationName() noexcept;

using Response = UnreadCounts::Response;

[[nodiscard]] static Response parseResponse(response::Value&& response);
};

} // namespace query::UnreadCounts

namespace query::Miscellaneous {
Expand Down Expand Up @@ -282,6 +315,17 @@ struct [[nodiscard]] Response

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

struct Traits
{
[[nodiscard]] static const std::string& GetRequestText() noexcept;
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
[[nodiscard]] static const std::string& GetOperationName() noexcept;

using Response = Miscellaneous::Response;

[[nodiscard]] static Response parseResponse(response::Value&& response);
};

} // namespace query::Miscellaneous

namespace mutation::CompleteTaskMutation {
Expand Down Expand Up @@ -324,6 +368,21 @@ struct [[nodiscard]] Response

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

struct Traits
{
[[nodiscard]] static const std::string& GetRequestText() noexcept;
[[nodiscard]] static const peg::ast& GetRequestObject() noexcept;
[[nodiscard]] static const std::string& GetOperationName() noexcept;

using Variables = CompleteTaskMutation::Variables;

[[nodiscard]] static response::Value serializeVariables(Variables&& variables);

using Response = CompleteTaskMutation::Response;

[[nodiscard]] static Response parseResponse(response::Value&& response);
};

} // namespace mutation::CompleteTaskMutation
} // namespace graphql::client

Expand Down
Loading