Skip to content

Commit f6b09ee

Browse files
authored
Merge pull request #173 from wravery/type-erasure
Merge work in progress from personal fork to start working on 4.0
2 parents 615f800 + eadbea9 commit f6b09ee

File tree

145 files changed

+16339
-4275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+16339
-4275
lines changed

.github/workflows/linux.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Linux
33
on: [push, pull_request]
44

55
jobs:
6-
gcc7:
6+
gcc10:
77
strategy:
88
fail-fast: false
99
matrix:
@@ -19,7 +19,7 @@ jobs:
1919
- name: Install Dependencies
2020
run: |
2121
sudo apt-get update
22-
sudo apt-get install -yq libgtest-dev libboost-program-options-dev rapidjson-dev ninja-build
22+
sudo apt-get install -yq libgtest-dev libboost-program-options-dev rapidjson-dev ninja-build gcc-10 g++-10
2323
2424
- name: Build GTest
2525
run: |
@@ -34,6 +34,9 @@ jobs:
3434

3535
- name: Configure CMake
3636
shell: pwsh
37+
env:
38+
CC: gcc-10
39+
CXX: g++-10
3740
working-directory: build/
3841
run: |
3942
$cmakeBuildType = '${{ matrix.config }}'

.github/workflows/macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
matrix:
1010
config: [Debug, Release]
1111

12-
runs-on: macos-latest
12+
runs-on: macos-11
1313

1414
steps:
1515
- uses: actions/checkout@v2

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ endif()
3333

3434
project(cppgraphqlgen VERSION ${LATEST_VERSION})
3535

36-
set(CMAKE_CXX_STANDARD 17)
37-
3836
set(GRAPHQL_INSTALL_INCLUDE_DIR include CACHE PATH "Header file install directory")
3937
set(GRAPHQL_INSTALL_TOOLS_DIR bin CACHE PATH "schemagen install directory")
4038
set(GRAPHQL_INSTALL_CMAKE_DIR lib/cmake CACHE PATH "CMake config files install directory")

PEGTL

Submodule PEGTL updated 98 files

cmake/test_coroutine.cpp.in

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This is a dummy program that just needs to compile and link to tell us if
2+
// the C++20 coroutine API is available. Use CMake's configure_file command
3+
// to replace the COROUTINE_HEADER and COROUTINE_NAMESPACE tokens for each
4+
// combination of headers and namespaces which we want to pass to the CMake
5+
// try_compile command.
6+
7+
#include <@COROUTINE_HEADER@>
8+
#include <future>
9+
10+
struct task
11+
{
12+
struct promise_type
13+
{
14+
task get_return_object() noexcept
15+
{
16+
return {};
17+
}
18+
19+
@COROUTINE_NAMESPACE@::suspend_never initial_suspend() noexcept
20+
{
21+
return {};
22+
}
23+
24+
@COROUTINE_NAMESPACE@::suspend_never final_suspend() noexcept
25+
{
26+
return {};
27+
}
28+
29+
void return_void() noexcept
30+
{
31+
promise.set_value();
32+
}
33+
34+
void unhandled_exception()
35+
{
36+
promise.set_exception(std::current_exception());
37+
}
38+
39+
std::promise<void> promise;
40+
};
41+
42+
constexpr bool await_ready() const noexcept
43+
{
44+
return true;
45+
}
46+
47+
std::future<void> future;
48+
};
49+
50+
task test_co_return()
51+
{
52+
co_return;
53+
}
54+
55+
int main()
56+
{
57+
test_co_return().future.get();
58+
return 0;
59+
}

cmake/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.6.0
1+
4.0.0

doc/resolvers.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,16 @@ schema {
3434

3535
Executing a query or mutation starts by calling `Request::resolve` from [GraphQLService.h](../include/graphqlservice/GraphQLService.h):
3636
```cpp
37-
GRAPHQLSERVICE_EXPORT std::future<response::Value> resolve(
37+
GRAPHQLSERVICE_EXPORT response::AwaitableValue resolve(
3838
const std::shared_ptr<RequestState>& state, peg::ast& query,
3939
const std::string& operationName, response::Value&& variables) const;
4040
```
41-
By default, the `std::future` results are resolved on-demand but synchronously,
42-
using `std::launch::deferred` with the `std::async` function. You can also use
43-
an override of `Request::resolve` which lets you substitute the
44-
`std::launch::async` option to begin executing the query on multiple threads
45-
in parallel:
41+
By default, the `std::future` results are resolved on-demand but synchronously.
42+
You can also use an override of `Request::resolve` which lets you substitute
43+
the `std::launch::async` option to begin executing the query on multiple
44+
threads in parallel:
4645
```cpp
47-
GRAPHQLSERVICE_EXPORT std::future<response::Value> resolve(std::launch launch,
46+
GRAPHQLSERVICE_EXPORT response::AwaitableValue resolve(std::launch launch,
4847
const std::shared_ptr<RequestState>& state, peg::ast& query,
4948
const std::string& operationName, response::Value&& variables) const;
5049
```
@@ -70,7 +69,7 @@ recursively call the `resolvers` for each of the `fields` in the nested
7069
`graphql::today::object::Appointment` object from the `today` sample in
7170
[AppointmentObject.h](../samples/separate/AppointmentObject.h).
7271
```cpp
73-
std::future<service::ResolverResult> resolveId(service::ResolverParams&& params);
72+
service::AwaitableResolver resolveId(service::ResolverParams&& params);
7473
```
7574
In this example, the `resolveId` method invokes `getId`:
7675
```cpp

doc/subscriptions.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ and `Request::unsubscribe` methods in [GraphQLService.h](../include/graphqlservi
1515
```cpp
1616
GRAPHQLSERVICE_EXPORT SubscriptionKey subscribe(
1717
SubscriptionParams&& params, SubscriptionCallback&& callback);
18-
GRAPHQLSERVICE_EXPORT std::future<SubscriptionKey> subscribe(
18+
GRAPHQLSERVICE_EXPORT AwaitableSubscribe subscribe(
1919
std::launch launch, SubscriptionParams&& params, SubscriptionCallback&& callback);
2020

2121
GRAPHQLSERVICE_EXPORT void unsubscribe(SubscriptionKey key);
22-
GRAPHQLSERVICE_EXPORT std::future<void> unsubscribe(std::launch launch, SubscriptionKey key);
22+
GRAPHQLSERVICE_EXPORT AwaitableUnsubscribe unsubscribe(std::launch launch, SubscriptionKey key);
2323
```
2424
You need to fill in a `SubscriptionParams` struct with the [parsed](./parsing.md)
2525
query and any other relevant operation parameters:
@@ -39,7 +39,7 @@ The `SubscriptionCallback` signature is:
3939
```cpp
4040
// Subscription callbacks receive the response::Value representing the result of evaluating the
4141
// SelectionSet against the payload.
42-
using SubscriptionCallback = std::function<void(std::future<response::Value>)>;
42+
using SubscriptionCallback = std::function<void(response::Value&&)>;
4343
```
4444

4545
## `ResolverContext::NotifySubscribe` and `ResolverContext::NotifyUnsubscribe`
@@ -114,27 +114,25 @@ GRAPHQLSERVICE_EXPORT void deliver(const SubscriptionName& name,
114114
```
115115

116116
By default, `deliver` invokes all of the `SubscriptionCallback` listeners with
117-
`std::future` payloads which are resolved on-demand but synchronously, using
118-
`std::launch::deferred` with the `std::async` function. There's also a version
119-
of each overload which lets you substitute the `std::launch::async` option to
120-
begin executing the queries and invoke the callbacks on multiple threads in
121-
parallel:
117+
`std::future` payloads which are resolved on-demand but synchronously. You can
118+
also use an override of `Request::resolve` which lets you substitute the
119+
`std::launch::async` option to begin executing the queries and invoke the
120+
callbacks on multiple threads in parallel:
122121
```cpp
123-
GRAPHQLSERVICE_EXPORT void deliver(std::launch launch, const SubscriptionName& name,
124-
const std::shared_ptr<Object>& subscriptionObject) const;
125-
GRAPHQLSERVICE_EXPORT void deliver(std::launch launch, const SubscriptionName& name,
126-
const SubscriptionArguments& arguments,
127-
const std::shared_ptr<Object>& subscriptionObject) const;
128-
GRAPHQLSERVICE_EXPORT void deliver(std::launch launch, const SubscriptionName& name,
122+
GRAPHQLSERVICE_EXPORT AwaitableDeliver deliver(std::launch launch, const SubscriptionName& name,
123+
std::shared_ptr<Object> subscriptionObject) const;
124+
GRAPHQLSERVICE_EXPORT AwaitableDeliver deliver(std::launch launch, const SubscriptionName& name,
125+
const SubscriptionArguments& arguments, std::shared_ptr<Object> subscriptionObject) const;
126+
GRAPHQLSERVICE_EXPORT AwaitableDeliver deliver(std::launch launch, const SubscriptionName& name,
129127
const SubscriptionArguments& arguments, const SubscriptionArguments& directives,
130-
const std::shared_ptr<Object>& subscriptionObject) const;
131-
GRAPHQLSERVICE_EXPORT void deliver(std::launch launch, const SubscriptionName& name,
128+
std::shared_ptr<Object> subscriptionObject) const;
129+
GRAPHQLSERVICE_EXPORT AwaitableDeliver deliver(std::launch launch, const SubscriptionName& name,
132130
const SubscriptionFilterCallback& applyArguments,
133-
const std::shared_ptr<Object>& subscriptionObject) const;
134-
GRAPHQLSERVICE_EXPORT void deliver(std::launch launch, const SubscriptionName& name,
131+
std::shared_ptr<Object> subscriptionObject) const;
132+
GRAPHQLSERVICE_EXPORT AwaitableDeliver deliver(std::launch launch, const SubscriptionName& name,
135133
const SubscriptionFilterCallback& applyArguments,
136134
const SubscriptionFilterCallback& applyDirectives,
137-
const std::shared_ptr<Object>& subscriptionObject) const;
135+
std::shared_ptr<Object> subscriptionObject) const;
138136
```
139137
140138
## Handling Multiple Operation Types

include/SchemaGenerator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class Generator
4242
std::string getSourcePath() const noexcept;
4343

4444
bool outputHeader() const noexcept;
45+
void outputObjectStubs(
46+
std::ostream& headerFile, const ObjectType& objectType) const;
4547
void outputObjectDeclaration(
4648
std::ostream& headerFile, const ObjectType& objectType, bool isQueryType) const;
4749
std::string getFieldDeclaration(const InputField& inputField) const noexcept;

include/Validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class ValidateVariableTypeVisitor
170170
class ValidateExecutableVisitor
171171
{
172172
public:
173-
GRAPHQLSERVICE_EXPORT ValidateExecutableVisitor(const std::shared_ptr<schema::Schema>& schema);
173+
GRAPHQLSERVICE_EXPORT ValidateExecutableVisitor(std::shared_ptr<schema::Schema> schema);
174174

175175
GRAPHQLSERVICE_EXPORT void visit(const peg::ast_node& root);
176176

0 commit comments

Comments
 (0)