|
3 | 3 |
|
4 | 4 | // WARNING! Do not edit this file manually, your changes will be overwritten. |
5 | 5 |
|
6 | | -#include "graphqlservice/introspection/Introspection.h" |
7 | | - |
8 | | -#include "graphqlservice/GraphQLParse.h" |
| 6 | +#include "MutateClient.h" |
9 | 7 |
|
10 | 8 | #include <algorithm> |
11 | 9 | #include <array> |
12 | 10 | #include <functional> |
13 | 11 | #include <sstream> |
14 | 12 | #include <stdexcept> |
15 | 13 | #include <string_view> |
16 | | -#include <tuple> |
17 | | -#include <vector> |
18 | 14 |
|
19 | 15 | using namespace std::literals; |
20 | 16 |
|
21 | | -namespace graphql { |
22 | | -namespace service { |
23 | | - |
24 | | -static const std::array<std::string_view, 4> s_namesTaskState = { |
25 | | - "New", |
26 | | - "Started", |
27 | | - "Complete", |
28 | | - "Unassigned" |
29 | | -}; |
| 17 | +namespace graphql::mutation::CompleteTaskMutation { |
30 | 18 |
|
31 | | -template <> |
32 | | -mutate::TaskState ModifiedArgument<mutate::TaskState>::convert(const response::Value& value) |
| 19 | +const std::string& GetRequestText() noexcept |
33 | 20 | { |
34 | | - if (!value.maybe_enum()) |
35 | | - { |
36 | | - throw service::schema_exception { { "not a valid TaskState value" } }; |
37 | | - } |
38 | | - |
39 | | - auto itr = std::find(s_namesTaskState.cbegin(), s_namesTaskState.cend(), value.get<response::StringType>()); |
40 | | - |
41 | | - if (itr == s_namesTaskState.cend()) |
42 | | - { |
43 | | - throw service::schema_exception { { "not a valid TaskState value" } }; |
44 | | - } |
45 | | - |
46 | | - return static_cast<mutate::TaskState>(itr - s_namesTaskState.cbegin()); |
| 21 | + static const auto s_request = R"gql( |
| 22 | + # Copyright (c) Microsoft Corporation. All rights reserved. |
| 23 | + # Licensed under the MIT License. |
| 24 | + |
| 25 | + mutation CompleteTaskMutation($input: CompleteTaskInput! = {id: "ZmFrZVRhc2tJZA==", isComplete: true, clientMutationId: "Hi There!"}) { |
| 26 | + completedTask: completeTask(input: $input) { |
| 27 | + completedTask: task { |
| 28 | + completedTaskId: id |
| 29 | + title |
| 30 | + isComplete |
| 31 | + } |
| 32 | + clientMutationId |
| 33 | + } |
| 34 | + } |
| 35 | + )gql"s; |
| 36 | + |
| 37 | + return s_request; |
47 | 38 | } |
48 | 39 |
|
49 | | -template <> |
50 | | -std::future<service::ResolverResult> ModifiedResult<mutate::TaskState>::convert(service::FieldResult<mutate::TaskState>&& result, ResolverParams&& params) |
| 40 | +const peg::ast& GetRequestObject() noexcept |
51 | 41 | { |
52 | | - return resolve(std::move(result), std::move(params), |
53 | | - [](mutate::TaskState&& value, const ResolverParams&) |
54 | | - { |
55 | | - response::Value result(response::Type::EnumValue); |
56 | | - |
57 | | - result.set<response::StringType>(std::string(s_namesTaskState[static_cast<size_t>(value)])); |
| 42 | + static const auto s_request = []() noexcept { |
| 43 | + auto ast = peg::parseString(GetRequestText()); |
58 | 44 |
|
59 | | - return result; |
60 | | - }); |
61 | | -} |
| 45 | + // This has already been validated against the schema by clientgen. |
| 46 | + ast.validated = true; |
62 | 47 |
|
63 | | -template <> |
64 | | -mutate::CompleteTaskInput ModifiedArgument<mutate::CompleteTaskInput>::convert(const response::Value& value) |
65 | | -{ |
66 | | - const auto defaultValue = []() |
67 | | - { |
68 | | - response::Value values(response::Type::Map); |
69 | | - response::Value entry; |
70 | | - |
71 | | - |
72 | | - return values; |
| 48 | + return ast; |
73 | 49 | }(); |
74 | 50 |
|
75 | | - |
76 | | - return { |
77 | | - std::move(valueId), |
78 | | - std::move(valueIsComplete), |
79 | | - std::move(valueClientMutationId) |
80 | | - }; |
81 | | -} |
82 | | - |
83 | | -} /* namespace service */ |
84 | | - |
85 | | -namespace mutate { |
86 | | - |
87 | | -std::string_view GetRequestText() noexcept |
88 | | -{ |
89 | | - return R"gql(# Copyright (c) Microsoft Corporation. All rights reserved. |
90 | | -# Licensed under the MIT License. |
91 | | -
|
92 | | -mutation CompleteTaskMutation($input: CompleteTaskInput! = {id: "ZmFrZVRhc2tJZA==", isComplete: true, clientMutationId: "Hi There!"}) { |
93 | | - completedTask: completeTask(input: $input) { |
94 | | - completedTask: task { |
95 | | - completedTaskId: id |
96 | | - title |
97 | | - isComplete |
98 | | - } |
99 | | - clientMutationId |
100 | | - } |
101 | | -})gql"sv; |
102 | | -} |
103 | | -namespace object { |
104 | | - |
105 | | -} /* namespace object */ |
106 | | - |
107 | | -Operations::Operations(std::shared_ptr<object::Query> query, std::shared_ptr<object::Mutation> mutation, std::shared_ptr<object::Subscription> subscription) |
108 | | - : service::Request({ |
109 | | - { "query", query }, |
110 | | - { "mutation", mutation }, |
111 | | - { "subscription", subscription } |
112 | | - }, GetClient()) |
113 | | - , _query(std::move(query)) |
114 | | - , _mutation(std::move(mutation)) |
115 | | - , _subscription(std::move(subscription)) |
116 | | -{ |
117 | | -} |
118 | | - |
119 | | -std::shared_ptr<client::Client> GetClient() |
120 | | -{ |
121 | | - static std::weak_ptr<client::Client> s_wpClient; |
122 | | - auto client = s_wpClient.lock(); |
123 | | - |
124 | | - if (!client) |
125 | | - { |
126 | | - client = std::make_shared<client::Client>(false); |
127 | | - AddTypesToClient(client); |
128 | | - s_wpClient = client; |
129 | | - } |
130 | | - |
131 | | - return client; |
| 51 | + return s_request; |
132 | 52 | } |
133 | 53 |
|
134 | | -} /* namespace mutate */ |
135 | | -} /* namespace graphql */ |
| 54 | +} /* namespace graphql::mutation::CompleteTaskMutation */ |
0 commit comments