Skip to content

Bring v4.0.0 to the main branch #188

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 136 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
43de621
Get latest release of PEGTL
wravery Oct 27, 2021
710052e
Enable C++20 with target_compile_features
wravery Oct 28, 2021
91949b9
Bump major version for breaking changes
wravery Oct 29, 2021
b79269d
Merge remote-tracking branch 'upstream/main' into cxx-20
wravery Oct 30, 2021
4aa162c
Pick up new version in new sample
wravery Oct 30, 2021
8c872b8
Remove deprecated methods
wravery Nov 1, 2021
0217ee8
Fix double std::move(variables) in tests
wravery Nov 1, 2021
1745a66
Make FieldResult awaitable for coroutine support
wravery Nov 2, 2021
4bfb1d8
Fallback to std::experimental for coroutines
wravery Nov 2, 2021
2a27aa5
Remove the fallback all the way to no coroutines
wravery Nov 2, 2021
9d1af8d
Move coroutine options to graphqlpeg target
wravery Nov 2, 2021
b314699
Use GCC 10 on Linux for coroutines
wravery Nov 2, 2021
f0e4a2d
Put coroutine detection in interface lib
wravery Nov 2, 2021
5468cc4
WIP coroutine support
wravery Nov 2, 2021
2a27b52
Simplify awaiters
wravery Nov 3, 2021
43d4ee3
Enable std::launch::async APIs
wravery Nov 3, 2021
2c87c1c
Move await_async from header to GraphQLService.*
wravery Nov 3, 2021
117a966
Explicitly construct a return value from the r-value reference
wravery Nov 3, 2021
66ac160
Add std::move for gcc
wravery Nov 3, 2021
2454d7b
Replace std::async with more straightforward std::thread usage
wravery Nov 3, 2021
50be8b3
Update docs
wravery Nov 3, 2021
5b66883
Make await_async test the launch flags instead of call sites
wravery Nov 3, 2021
5c11779
Pass by value instead of r-value ref to simplify
wravery Nov 4, 2021
ce8efd7
Drop redundant virtual with override in stub declarations
wravery Nov 4, 2021
bed6506
Alias internal::Awaitable return types in public interfaces
wravery Nov 20, 2021
8c6c918
WIP prototype using type erasure
wravery Nov 30, 2021
76428d1
Declare a default virtual destructor on Concepts
wravery Nov 30, 2021
0606595
Try explicit conversion to Concept unique_ptr
wravery Nov 30, 2021
de60045
Fix TodayTests
wravery Nov 30, 2021
a943f28
Reimplement stubs with concepts to test for fallback
wravery Dec 1, 2021
66b5f8d
Simple workaround for missing concepts header on macOS
wravery Dec 1, 2021
0780b4a
Switch macOS to macos-11 for newer Xcode support
wravery Dec 1, 2021
b0f5d48
Take advantage of type erasure to simplify + noexcept getters
wravery Dec 1, 2021
630c706
Add type-erased begin/endSelectionSet overrides
wravery Dec 1, 2021
24a7c98
Decouple TodayMock types from objects
wravery Dec 1, 2021
09d1704
Make the service::FieldParams argument optional
wravery Dec 1, 2021
ce83f71
Restore r-value reference parameters where it makes sense
wravery Dec 1, 2021
6233f75
Use references for large parameters
wravery Dec 1, 2021
65ed7b7
Update static_assert for missing methods without stubs
wravery Dec 1, 2021
d735105
Return by const reference where applicable
wravery Dec 1, 2021
006e46f
Put back error messages on missing getter static_asserts
wravery Dec 1, 2021
eadbea9
Simplify the Introspection implementation
wravery Dec 1, 2021
f6b09ee
Merge pull request #173 from wravery/type-erasure
wravery Dec 1, 2021
c623c00
Favor underlying non-template standard types
wravery Dec 1, 2021
78af84e
Reverse schemagen default to not generate stubs
wravery Dec 2, 2021
230f368
Emit separate files for each type by default
wravery Dec 2, 2021
b16f482
Encapsulate code gen in reusable cmake functions
wravery Dec 3, 2021
49d4ced
Extract clientgen cmake functions as well
wravery Dec 3, 2021
37756a1
Disambiguate copy_sample_dlls target names
wravery Dec 3, 2021
b7c7849
Remove out-of-date WORKING_DIRECTORY
wravery Dec 3, 2021
da66d77
Install update-client-files script
wravery Dec 3, 2021
5b88b3e
Add support for custom type-erased await_async
wravery Dec 3, 2021
d6c7aef
Merge pull request #174 from wravery/next
wravery Dec 3, 2021
1448d70
Validation schema does not require Introspection support
wravery Dec 3, 2021
c614893
Add comments indicating not to copy include statements
wravery Dec 3, 2021
733e100
CMake modernization/cleanup
wravery Dec 3, 2021
e9fc866
Merge branch 'microsoft:next' into next
wravery Dec 5, 2021
cb56e15
Fix mismatch in sentinel file names and cleanup targets
wravery Dec 6, 2021
0da6378
Move the concrete Introspection object declarations up
wravery Dec 7, 2021
2a58702
Codegen targets should depend on the generators
wravery Dec 7, 2021
7807c53
Implement type-erased interface object types
wravery Dec 8, 2021
b2afbaf
Add make_hero utility functions to learn sample
wravery Dec 8, 2021
c04d0d8
Remove unused headers from interface types and add sv literal
wravery Dec 8, 2021
a0b4553
Use R"gql(...)gql"sv for names in getTypeNames
wravery Dec 8, 2021
74e4068
Escape string literals with GraphQL tokens
wravery Dec 8, 2021
8d1a60f
Implement type-erased union object types
wravery Dec 8, 2021
b8904ed
Merge pull request #175 from wravery/next
wravery Dec 9, 2021
53dac34
Add forward declarations for union types
wravery Dec 9, 2021
57b259f
Merge branch 'next' of https://github.com/wravery/cppgraphqlgen into …
wravery Dec 9, 2021
fdb5c9f
Fix comment
wravery Dec 9, 2021
835f9a0
Include fewer headers and rely on forward declaration in ...Schema.h
wravery Dec 9, 2021
f603111
Fix #156
wravery Dec 9, 2021
9427a86
StarWarsData.cpp doesn't need the convenience header
wravery Dec 9, 2021
e6f61a1
Merge pull request #176 from wravery/next
wravery Dec 9, 2021
09a4e80
Convert validation schema to separate files
wravery Dec 9, 2021
4773439
Remove separate unified sample schemas
wravery Dec 9, 2021
9a7bf58
Rename separate... schemas to today...
wravery Dec 9, 2021
543ed52
Remove schemagen --merge-files option
wravery Dec 9, 2021
875843c
Remove convenience header from TodayMock
wravery Dec 9, 2021
218e7d9
Stop generating the convenience header
wravery Dec 9, 2021
d22231d
Switch IntrospectionSchema to separate files
wravery Dec 9, 2021
a771fed
Remove mergeFiles handling
wravery Dec 9, 2021
e0202d5
Remove Introspection handling without arguments
wravery Dec 9, 2021
d720bcb
Rename introspection/*.h copy target/sentinel
wravery Dec 9, 2021
93b7f10
Use file(GLOB) for copy_if_different
wravery Dec 9, 2021
044b7e0
Suppress Introspection implement and stub concepts
wravery Dec 9, 2021
5c74269
Simplify resolvers and keep default args in static
wravery Dec 9, 2021
5c7a3a6
Merge pull request #177 from wravery/next
wravery Dec 10, 2021
2344b35
Add support for new GraphQL grammar/Introspection
wravery Dec 10, 2021
a377114
Fix schema description
wravery Dec 10, 2021
78a8b80
Remove extra blank line from ...Schema.cpp
wravery Dec 10, 2021
7c91e3a
Update URLs in parser error messages
wravery Dec 10, 2021
2ef4bfc
Block reserved names in non-Introspection schemas
wravery Dec 10, 2021
69abcf9
Implement block quote whitespace normalization
wravery Dec 10, 2021
970375f
Parse interfaces implementing interfaces
wravery Dec 11, 2021
673a649
Validate implemented interfaces
wravery Dec 11, 2021
9d14621
Interface validation fixes
wravery Dec 11, 2021
d4a91a2
Update Validation tests and schema to latest GraphQL spec
wravery Dec 12, 2021
3bea5f4
Fix remaining URLs so they point to latest GraphQL spec
wravery Dec 12, 2021
d8edb04
Fix ValidationTests and possibleTypes logic
wravery Dec 12, 2021
c1d8f31
Fix inverted null check in getPossibleTypes
wravery Dec 12, 2021
5798230
Replace std::remove_if with simpler std::remove
wravery Dec 12, 2021
6ed1209
Simplify more std::remove_if calls just checking for null
wravery Dec 12, 2021
c29bcbf
Support repeatable directives and preserve fragment directives
wravery Dec 13, 2021
80dba3a
Merge pull request #179 from wravery/next
wravery Dec 13, 2021
172dff7
Export a type erased JSON writer object
wravery Dec 13, 2021
5291b0f
Default-init params structs in Request methods
wravery Dec 13, 2021
fd09323
Merge pull request #180 from wravery/next
wravery Dec 14, 2021
3b677d6
Let response::Value hold copy-on-write shared_ptr
wravery Dec 14, 2021
e181977
Check for shared_ptr to Value before awaiting
wravery Dec 14, 2021
91a5359
Add tests for shared_ptr<Value> field results
wravery Dec 14, 2021
5eeba63
Merge pull request #181 from wravery/next
wravery Dec 14, 2021
a33724a
Distinguish AwaitableScalar from AwaitableObject
wravery Dec 14, 2021
92e36af
Validate custom response::Value in ModifiedResult
wravery Dec 14, 2021
fd89495
Merge pull request #183 from wravery/next
wravery Dec 15, 2021
8c9f372
Only install new CMake files for install configs
wravery Dec 15, 2021
f05a238
Merge pull request #184 from wravery/next
wravery Dec 15, 2021
b324eb4
Output include statements for unions even if no interfaces
wravery Dec 15, 2021
29eeba4
Install Introspection.h under graphqlservice/internal/
wravery Dec 15, 2021
7952633
Use a static_assert for the None modifier in ModifiedArgument too
wravery Dec 15, 2021
9ffd6f0
Merge pull request #185 from wravery/next
wravery Dec 15, 2021
6c99aef
Update related projects
wravery Dec 15, 2021
f759e0e
Remove std::filesystem fallbacks from early versions of C++17
wravery Dec 16, 2021
9d3462a
Finish a pass through the root README
wravery Dec 16, 2021
af152e2
Document specifiedBy directive handling
wravery Dec 16, 2021
d62207e
Update documentation for service::FieldParams
wravery Dec 16, 2021
8d58e3a
Update JSON documentation to describe response::Writer
wravery Dec 16, 2021
e46b572
Minor correction to comment about parseSchema
wravery Dec 16, 2021
3e97396
Move RequestDeliverParams field name out of SubscriptionFilter
wravery Dec 16, 2021
3b42b47
Finish documentation pass
wravery Dec 16, 2021
59eb713
Update doc list to include awaitable.md
wravery Dec 16, 2021
777ef34
Merge pull request #186 from wravery/next
wravery Dec 16, 2021
0b47cf1
Default initialize input type struct members
wravery Dec 16, 2021
70e804f
Fix scope of headerPath and sourcePath variables
wravery Dec 16, 2021
734580e
Merge branch 'microsoft:next' into next
wravery Dec 16, 2021
def6081
Merge pull request #187 from wravery/next
wravery Dec 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 5 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Linux
on: [push, pull_request]

jobs:
gcc7:
gcc10:
strategy:
fail-fast: false
matrix:
Expand All @@ -19,7 +19,7 @@ jobs:
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -yq libgtest-dev libboost-program-options-dev rapidjson-dev ninja-build
sudo apt-get install -yq libgtest-dev libboost-program-options-dev rapidjson-dev ninja-build gcc-10 g++-10

- name: Build GTest
run: |
Expand All @@ -34,6 +34,9 @@ jobs:

- name: Configure CMake
shell: pwsh
env:
CC: gcc-10
CXX: g++-10
working-directory: build/
run: |
$cmakeBuildType = '${{ matrix.config }}'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
matrix:
config: [Debug, Release]

runs-on: macos-latest
runs-on: macos-11

steps:
- uses: actions/checkout@v2
Expand Down
13 changes: 4 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.15")
# Enable CMAKE_MSVC_RUNTIME_LIBRARY on Windows.
set(MSVC_MATCH_VCPKG_TRIPLET ON)
cmake_policy(SET CMP0091 NEW)
endif()
# Enable CMAKE_MSVC_RUNTIME_LIBRARY on Windows: https://cmake.org/cmake/help/latest/policy/CMP0091.html
cmake_policy(SET CMP0091 NEW)

# Default to the last updated version from version.txt.
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.txt" VERSION_FILE)
Expand All @@ -33,8 +30,6 @@ endif()

project(cppgraphqlgen VERSION ${LATEST_VERSION})

set(CMAKE_CXX_STANDARD 17)

set(GRAPHQL_INSTALL_INCLUDE_DIR include CACHE PATH "Header file install directory")
set(GRAPHQL_INSTALL_TOOLS_DIR bin CACHE PATH "schemagen install directory")
set(GRAPHQL_INSTALL_CMAKE_DIR lib/cmake CACHE PATH "CMake config files install directory")
Expand All @@ -45,7 +40,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries instead of static libs" OFF)
if(VCPKG_TARGET_TRIPLET)
message(STATUS "Using ${VCPKG_TARGET_TRIPLET} triplet with vcpkg")

if(MSVC AND MSVC_MATCH_VCPKG_TRIPLET)
if(MSVC)
# Match the MSVC runtime if we're using VCPKG with static libraries.
if(VCPKG_TARGET_TRIPLET MATCHES [[^.+-static$]])
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
Expand Down
2 changes: 1 addition & 1 deletion PEGTL
Submodule PEGTL updated 98 files
+9 −1 .github/workflows/android.yml
+12 −2 .github/workflows/clang-analyze.yml
+11 −3 .github/workflows/clang-format.yml
+12 −2 .github/workflows/clang-tidy.yml
+9 −1 .github/workflows/code-coverage.yml
+8 −2 .github/workflows/codeql-analysis.yml
+40 −30 .github/workflows/linux.yml
+9 −1 .github/workflows/macos.yml
+11 −3 .github/workflows/no-exceptions.yml
+10 −2 .github/workflows/sanitizer.yml
+9 −1 .github/workflows/windows.yml
+5 −0 CMakeLists.txt
+6 −2 README.md
+68 −2 doc/Actions-and-States.md
+19 −0 doc/Changelog.md
+11 −0 doc/Contrib-and-Examples.md
+1 −1 doc/Errors-and-Exceptions.md
+1 −1 doc/Grammar-Analysis.md
+2 −4 doc/Installing-and-Using.md
+7 −2 doc/Parse-Tree.md
+3 −0 doc/README.md
+10 −1 doc/Rule-Reference.md
+1 −0 include/tao/pegtl.hpp
+3 −3 include/tao/pegtl/argv_input.hpp
+1 −0 include/tao/pegtl/ascii.hpp
+5 −2 include/tao/pegtl/buffer_input.hpp
+24 −6 include/tao/pegtl/change_action_and_state.hpp
+25 −6 include/tao/pegtl/change_state.hpp
+69 −0 include/tao/pegtl/contrib/add_state.hpp
+3 −3 include/tao/pegtl/contrib/analyze.hpp
+55 −0 include/tao/pegtl/contrib/check_bytes.hpp
+0 −2 include/tao/pegtl/contrib/control_action.hpp
+4 −4 include/tao/pegtl/contrib/http.hpp
+1 −1 include/tao/pegtl/contrib/instantiate.hpp
+39 −7 include/tao/pegtl/contrib/integer.hpp
+3 −3 include/tao/pegtl/contrib/internal/set_stack_guard.hpp
+3 −3 include/tao/pegtl/contrib/internal/vector_stack_guard.hpp
+106 −0 include/tao/pegtl/contrib/iri.hpp
+88 −0 include/tao/pegtl/contrib/limit_bytes.hpp
+83 −0 include/tao/pegtl/contrib/limit_depth.hpp
+121 −0 include/tao/pegtl/contrib/peg.hpp
+142 −0 include/tao/pegtl/contrib/proto3.hpp
+45 −0 include/tao/pegtl/contrib/separated_seq.hpp
+8 −4 include/tao/pegtl/contrib/state_control.hpp
+1 −1 include/tao/pegtl/contrib/uri.hpp
+3 −3 include/tao/pegtl/internal/cstream_reader.hpp
+6 −6 include/tao/pegtl/internal/file_mapper_posix.hpp
+6 −6 include/tao/pegtl/internal/file_mapper_win32.hpp
+2 −2 include/tao/pegtl/internal/file_reader.hpp
+3 −2 include/tao/pegtl/internal/istream_reader.hpp
+6 −6 include/tao/pegtl/internal/marker.hpp
+20 −31 include/tao/pegtl/internal/ranges.hpp
+29 −13 include/tao/pegtl/internal/state.hpp
+21 −8 include/tao/pegtl/memory_input.hpp
+4 −4 include/tao/pegtl/mmap_input.hpp
+0 −2 include/tao/pegtl/must_if.hpp
+7 −6 include/tao/pegtl/normal.hpp
+20 −33 include/tao/pegtl/parse.hpp
+5 −0 include/tao/pegtl/parse_error.hpp
+3 −3 include/tao/pegtl/position.hpp
+2 −2 include/tao/pegtl/read_input.hpp
+4 −4 include/tao/pegtl/string_input.hpp
+2 −2 include/tao/pegtl/version.hpp
+37 −23 include/tao/pegtl/visit.hpp
+3 −2 src/example/pegtl/CMakeLists.txt
+15 −9 src/example/pegtl/abnf2pegtl.cpp
+520 −0 src/example/pegtl/expression.cpp
+0 −2 src/example/pegtl/indent_aware.cpp
+101 −0 src/example/pegtl/iri.cpp
+2 −2 src/example/pegtl/json_classes.hpp
+5 −3 src/example/pegtl/json_errors.hpp
+12 −2 src/example/pegtl/json_parse.cpp
+0 −25 src/example/pegtl/lua53_print_debug.cpp
+0 −25 src/example/pegtl/lua53_print_names.cpp
+37 −0 src/example/pegtl/peg.peg
+545 −0 src/example/pegtl/peg2pegtl.cpp
+1 −118 src/example/pegtl/proto3.cpp
+4 −4 src/example/pegtl/token_input.cpp
+6 −0 src/test/pegtl/CMakeLists.txt
+50 −0 src/test/pegtl/check_bytes.cpp
+24 −0 src/test/pegtl/contains.cpp
+1 −0 src/test/pegtl/contrib_analyze.cpp
+4 −4 src/test/pegtl/contrib_control_action.cpp
+1 −1 src/test/pegtl/contrib_if_then.cpp
+2 −2 src/test/pegtl/contrib_instantiate.cpp
+30 −29 src/test/pegtl/contrib_integer.cpp
+57 −0 src/test/pegtl/contrib_iri.cpp
+24 −0 src/test/pegtl/contrib_separated_seq.cpp
+19 −17 src/test/pegtl/contrib_uri.cpp
+9 −3 src/test/pegtl/error_message.cpp
+2 −2 src/test/pegtl/internal_file_mapper.cpp
+1 −1 src/test/pegtl/internal_file_opener.cpp
+50 −0 src/test/pegtl/limit_bytes.cpp
+50 −0 src/test/pegtl/limit_depth.cpp
+1 −1 src/test/pegtl/rule_apply.cpp
+1 −1 src/test/pegtl/rule_apply0.cpp
+1 −1 src/test/pegtl/rule_if_apply.cpp
+1 −1 src/test/pegtl/verify_impl.hpp
148 changes: 103 additions & 45 deletions README.md

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Enable version checks in find_package
include(CMakePackageConfigHelpers)
Expand All @@ -11,3 +11,10 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${GRAPHQL_INSTALL_CMAKE_DIR}/${PROJECT_NAME})

install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-functions.cmake
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-update-schema-files.cmake
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-update-client-files.cmake
CONFIGURATIONS ${GRAPHQL_INSTALL_CONFIGURATIONS}
DESTINATION ${GRAPHQL_INSTALL_CMAKE_DIR}/${PROJECT_NAME})
14 changes: 13 additions & 1 deletion cmake/cppgraphqlgen-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cppgraphqlgen
-------------

The following import targets are created
The following import targets are created:

::

Expand All @@ -15,8 +15,20 @@ The following import targets are created
cppgraphqlgen::graphqlintrospection
cppgraphqlgen::graphqljson
cppgraphqlgen::schemagen
cppgraphqlgen::clientgen

The following functions are defined to help with code generation and build targets:

::

update_graphql_schema_files
add_graphql_schema_target
add_graphql_schema_no_introspection_target
update_graphql_client_files
add_graphql_client_target
#]=======================================================================]

include(CMakeFindDependencyMacro)
find_package(Threads REQUIRED)
include("${CMAKE_CURRENT_LIST_DIR}/cppgraphqlgen-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cppgraphqlgen-functions.cmake")
107 changes: 107 additions & 0 deletions cmake/cppgraphqlgen-functions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

get_filename_component(GRAPHQL_UPDATE_SCHEMA_FILES_SCRIPT
"${CMAKE_CURRENT_LIST_DIR}/cppgraphqlgen-update-schema-files.cmake"
ABSOLUTE)

get_filename_component(GRAPHQL_UPDATE_CLIENT_FILES_SCRIPT
"${CMAKE_CURRENT_LIST_DIR}/cppgraphqlgen-update-client-files.cmake"
ABSOLUTE)

function(update_graphql_schema_files SCHEMA_TARGET SCHEMA_GRAPHQL SCHEMA_PREFIX SCHEMA_NAMESPACE)
set_property(DIRECTORY APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${SCHEMA_TARGET}_schema_files)

# Collect optional arguments
set(ADDITIONAL_SCHEMAGEN_ARGS "")
if(ARGC GREATER 4)
math(EXPR LAST_ARG "${ARGC} - 1")
foreach(ARGN RANGE 4 ${LAST_ARG})
set(NEXT_ARG "${ARGV${ARGN}}")
list(APPEND ADDITIONAL_SCHEMAGEN_ARGS "${NEXT_ARG}")
endforeach()
endif()

add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files
COMMAND
${CMAKE_COMMAND} "-DSCHEMA_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
"-DSCHEMA_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
"-DSCHEMAGEN_PROGRAM=$<TARGET_FILE:cppgraphqlgen::schemagen>"
"-DSCHEMA_TARGET=${SCHEMA_TARGET}" "-DSCHEMA_GRAPHQL=${SCHEMA_GRAPHQL}"
"-DSCHEMA_PREFIX=${SCHEMA_PREFIX}" "-DSCHEMA_NAMESPACE=${SCHEMA_NAMESPACE}"
"-DADDITIONAL_SCHEMAGEN_ARGS=${ADDITIONAL_SCHEMAGEN_ARGS}"
-P ${GRAPHQL_UPDATE_SCHEMA_FILES_SCRIPT}
DEPENDS ${SCHEMA_GRAPHQL} ${GRAPHQL_UPDATE_SCHEMA_FILES_SCRIPT} cppgraphqlgen::schemagen
COMMENT "Generating ${SCHEMA_TARGET} GraphQL schema"
VERBATIM)
endfunction()

function(add_graphql_schema_target SCHEMA_TARGET)
add_custom_target(${SCHEMA_TARGET}_update_schema ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files)

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files)
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files SCHEMA_FILES)
add_library(${SCHEMA_TARGET}_schema STATIC ${SCHEMA_FILES})
add_dependencies(${SCHEMA_TARGET}_schema ${SCHEMA_TARGET}_update_schema)
target_include_directories(${SCHEMA_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${SCHEMA_TARGET}_schema PUBLIC cppgraphqlgen::graphqlintrospection)
endif()
endfunction()

function(add_graphql_schema_no_introspection_target SCHEMA_NO_INTROSPECTION_TARGET)
add_custom_target(${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files)

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files)
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NO_INTROSPECTION_TARGET}_schema_files SCHEMA_FILES)
add_library(${SCHEMA_NO_INTROSPECTION_TARGET}_schema STATIC ${SCHEMA_FILES})
add_dependencies(${SCHEMA_NO_INTROSPECTION_TARGET}_schema ${SCHEMA_NO_INTROSPECTION_TARGET}_update_schema)
target_include_directories(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${SCHEMA_NO_INTROSPECTION_TARGET}_schema PUBLIC cppgraphqlgen::graphqlservice)
endif()
endfunction()

function(update_graphql_client_files CLIENT_TARGET SCHEMA_GRAPHQL REQUEST_GRAPHQL CLIENT_PREFIX CLIENT_NAMESPACE)
set_property(DIRECTORY APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${CLIENT_TARGET}_client_files)

# Collect optional arguments
set(ADDITIONAL_CLIENTGEN_ARGS "")
if(ARGC GREATER 5)
math(EXPR LAST_ARG "${ARGC} - 1")
foreach(ARGN RANGE 5 ${LAST_ARG})
set(NEXT_ARG "${ARGV${ARGN}}")
list(APPEND ADDITIONAL_CLIENTGEN_ARGS "${NEXT_ARG}")
endforeach()
endif()

add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files
COMMAND
${CMAKE_COMMAND} "-DCLIENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
"-DCLIENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
"-DCLIENTGEN_PROGRAM=$<TARGET_FILE:cppgraphqlgen::clientgen>" "-DCLIENT_TARGET=${CLIENT_TARGET}"
"-DSCHEMA_GRAPHQL=${SCHEMA_GRAPHQL}" "-DREQUEST_GRAPHQL=${REQUEST_GRAPHQL}"
"-DCLIENT_PREFIX=${CLIENT_PREFIX}" "-DCLIENT_NAMESPACE=${CLIENT_NAMESPACE}"
"-DADDITIONAL_CLIENTGEN_ARGS=${ADDITIONAL_CLIENTGEN_ARGS}"
-P ${GRAPHQL_UPDATE_CLIENT_FILES_SCRIPT}
DEPENDS ${SCHEMA_GRAPHQL} ${REQUEST_GRAPHQL} ${GRAPHQL_UPDATE_CLIENT_FILES_SCRIPT} cppgraphqlgen::clientgen
COMMENT "Generating ${CLIENT_TARGET} client"
VERBATIM)
endfunction()

function(add_graphql_client_target CLIENT_TARGET)
add_custom_target(${CLIENT_TARGET}_update_client ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files)

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files)
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files CLIENT_FILES)
add_library(${CLIENT_TARGET}_client STATIC ${CLIENT_FILES})
add_dependencies(${CLIENT_TARGET}_client ${CLIENT_TARGET}_update_client)
target_include_directories(${CLIENT_TARGET}_client PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${CLIENT_TARGET}_client PUBLIC cppgraphqlgen::graphqlclient)
endif()
endfunction()
60 changes: 60 additions & 0 deletions cmake/cppgraphqlgen-update-client-files.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# Normalize the filesystem paths
get_filename_component(CLIENT_SOURCE_DIR ${CLIENT_SOURCE_DIR} ABSOLUTE)
get_filename_component(CLIENT_BINARY_DIR ${CLIENT_BINARY_DIR} ABSOLUTE)
get_filename_component(CLIENTGEN_PROGRAM ${CLIENTGEN_PROGRAM} ABSOLUTE)
get_filename_component(SCHEMA_GRAPHQL "${CLIENT_SOURCE_DIR}/${SCHEMA_GRAPHQL}" ABSOLUTE)
get_filename_component(REQUEST_GRAPHQL "${CLIENT_SOURCE_DIR}/${REQUEST_GRAPHQL}" ABSOLUTE)

file(MAKE_DIRECTORY ${CLIENT_BINARY_DIR})

# Cleanup all of the stale files in the binary directory
file(GLOB PREVIOUS_FILES ${CLIENT_BINARY_DIR}/*.h ${CLIENT_BINARY_DIR}/*.cpp
${CLIENT_BINARY_DIR}/${CLIENT_TARGET}_client_files)
foreach(PREVIOUS_FILE ${PREVIOUS_FILES})
file(REMOVE ${PREVIOUS_FILE})
endforeach()

set(CLIENTGEN_ARGS "--schema=${SCHEMA_GRAPHQL}" "--request=${REQUEST_GRAPHQL}" "--prefix=${CLIENT_PREFIX}" "--namespace=${CLIENT_NAMESPACE}")
foreach(CLIENTGEN_ARG ${ADDITIONAL_CLIENTGEN_ARGS})
list(APPEND CLIENTGEN_ARGS ${CLIENTGEN_ARG})
endforeach()

# Regenerate the sources in the binary directory
execute_process(
COMMAND ${CLIENTGEN_PROGRAM} ${CLIENTGEN_ARGS}
OUTPUT_FILE ${CLIENT_TARGET}_client_files
WORKING_DIRECTORY ${CLIENT_BINARY_DIR})

# Get the up-to-date list of files in the binary directory
set(FILE_NAMES "")
file(GLOB NEW_FILES ${CLIENT_BINARY_DIR}/*.h ${CLIENT_BINARY_DIR}/*.cpp)
foreach(NEW_FILE ${NEW_FILES})
get_filename_component(NEW_FILE ${NEW_FILE} NAME)
list(APPEND FILE_NAMES "${NEW_FILE}")
endforeach()

# Don't update the files in the source directory if no files were generated in the binary directory.
if(NOT FILE_NAMES)
message(FATAL_ERROR "Schema generation failed!")
endif()

# Support if() IN_LIST operator: https://cmake.org/cmake/help/latest/policy/CMP0057.html
cmake_policy(SET CMP0057 NEW)

# Remove stale files in the source directory
file(GLOB OLD_FILES ${CLIENT_SOURCE_DIR}/*.h ${CLIENT_SOURCE_DIR}/*.cpp)
foreach(OLD_FILE ${OLD_FILES})
get_filename_component(OLD_FILE ${OLD_FILE} NAME)
if(NOT OLD_FILE IN_LIST FILE_NAMES)
file(REMOVE "${CLIENT_SOURCE_DIR}/${OLD_FILE}")
endif()
endforeach()

# Copy new and modified files from the binary directory to the source directory
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CLIENT_BINARY_DIR}/${CLIENT_TARGET}_client_files
${NEW_FILES}
${CLIENT_SOURCE_DIR})
59 changes: 59 additions & 0 deletions cmake/cppgraphqlgen-update-schema-files.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# Normalize the filesystem paths
get_filename_component(SCHEMA_SOURCE_DIR ${SCHEMA_SOURCE_DIR} ABSOLUTE)
get_filename_component(SCHEMA_BINARY_DIR ${SCHEMA_BINARY_DIR} ABSOLUTE)
get_filename_component(SCHEMAGEN_PROGRAM ${SCHEMAGEN_PROGRAM} ABSOLUTE)
get_filename_component(SCHEMA_GRAPHQL "${SCHEMA_SOURCE_DIR}/${SCHEMA_GRAPHQL}" ABSOLUTE)

file(MAKE_DIRECTORY ${SCHEMA_BINARY_DIR})

# Cleanup all of the stale files in the binary directory
file(GLOB PREVIOUS_FILES ${SCHEMA_BINARY_DIR}/*.h ${SCHEMA_BINARY_DIR}/*.cpp
${SCHEMA_BINARY_DIR}/${SCHEMA_TARGET}_schema_files)
foreach(PREVIOUS_FILE ${PREVIOUS_FILES})
file(REMOVE ${PREVIOUS_FILE})
endforeach()

set(SCHEMAGEN_ARGS "--schema=${SCHEMA_GRAPHQL}" "--prefix=${SCHEMA_PREFIX}" "--namespace=${SCHEMA_NAMESPACE}")
foreach(SCHEMAGEN_ARG ${ADDITIONAL_SCHEMAGEN_ARGS})
list(APPEND SCHEMAGEN_ARGS ${SCHEMAGEN_ARG})
endforeach()

# Regenerate the sources in the binary directory
execute_process(
COMMAND ${SCHEMAGEN_PROGRAM} ${SCHEMAGEN_ARGS}
OUTPUT_FILE ${SCHEMA_TARGET}_schema_files
WORKING_DIRECTORY ${SCHEMA_BINARY_DIR})

# Get the up-to-date list of files in the binary directory
set(FILE_NAMES "")
file(GLOB NEW_FILES ${SCHEMA_BINARY_DIR}/*.h ${SCHEMA_BINARY_DIR}/*.cpp)
foreach(NEW_FILE ${NEW_FILES})
get_filename_component(NEW_FILE ${NEW_FILE} NAME)
list(APPEND FILE_NAMES "${NEW_FILE}")
endforeach()

# Don't update the files in the source directory if no files were generated in the binary directory.
if(NOT FILE_NAMES)
message(FATAL_ERROR "Schema generation failed!")
endif()

# Support if() IN_LIST operator: https://cmake.org/cmake/help/latest/policy/CMP0057.html
cmake_policy(SET CMP0057 NEW)

# Remove stale files in the source directory
file(GLOB OLD_FILES ${SCHEMA_SOURCE_DIR}/*.h ${SCHEMA_SOURCE_DIR}/*.cpp)
foreach(OLD_FILE ${OLD_FILES})
get_filename_component(OLD_FILE ${OLD_FILE} NAME)
if(NOT OLD_FILE IN_LIST FILE_NAMES)
file(REMOVE "${SCHEMA_SOURCE_DIR}/${OLD_FILE}")
endif()
endforeach()

# Copy new and modified files from the binary directory to the source directory
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
${SCHEMA_BINARY_DIR}/${SCHEMA_TARGET}_schema_files
${NEW_FILES}
${SCHEMA_SOURCE_DIR})
Loading