|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +// WARNING! Do not edit this file manually, your changes will be overwritten. |
| 5 | + |
| 6 | +#include "SubscriptionObject.h" |
| 7 | +#include "CharacterObject.h" |
| 8 | + |
| 9 | +#include "graphqlservice/internal/Schema.h" |
| 10 | + |
| 11 | +#include "graphqlservice/introspection/IntrospectionSchema.h" |
| 12 | + |
| 13 | +#include <algorithm> |
| 14 | +#include <functional> |
| 15 | +#include <stdexcept> |
| 16 | +#include <unordered_map> |
| 17 | + |
| 18 | +using namespace std::literals; |
| 19 | + |
| 20 | +namespace graphql::learn { |
| 21 | +namespace object { |
| 22 | + |
| 23 | +Subscription::Subscription(std::unique_ptr<const Concept> pimpl) noexcept |
| 24 | + : service::Object{ getTypeNames(), getResolvers() } |
| 25 | + , _pimpl { std::move(pimpl) } |
| 26 | +{ |
| 27 | +} |
| 28 | + |
| 29 | +service::TypeNames Subscription::getTypeNames() const noexcept |
| 30 | +{ |
| 31 | + return { |
| 32 | + R"gql(Subscription)gql"sv |
| 33 | + }; |
| 34 | +} |
| 35 | + |
| 36 | +service::ResolverMap Subscription::getResolvers() const noexcept |
| 37 | +{ |
| 38 | + return { |
| 39 | + { R"gql(__typename)gql"sv, [this](service::ResolverParams&& params) { return resolve_typename(std::move(params)); } }, |
| 40 | + { R"gql(newEpisode)gql"sv, [this](service::ResolverParams&& params) { return resolveNewEpisode(std::move(params)); } }, |
| 41 | + { R"gql(characterChanged)gql"sv, [this](service::ResolverParams&& params) { return resolveCharacterChanged(std::move(params)); } } |
| 42 | + }; |
| 43 | +} |
| 44 | + |
| 45 | +void Subscription::beginSelectionSet(const service::SelectionSetParams& params) const |
| 46 | +{ |
| 47 | + _pimpl->beginSelectionSet(params); |
| 48 | +} |
| 49 | + |
| 50 | +void Subscription::endSelectionSet(const service::SelectionSetParams& params) const |
| 51 | +{ |
| 52 | + _pimpl->endSelectionSet(params); |
| 53 | +} |
| 54 | + |
| 55 | +service::AwaitableResolver Subscription::resolveCharacterChanged(service::ResolverParams&& params) const |
| 56 | +{ |
| 57 | + std::unique_lock resolverLock(_resolverMutex); |
| 58 | + service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) }; |
| 59 | + auto directives = std::move(params.fieldDirectives); |
| 60 | + auto result = _pimpl->getCharacterChanged(service::FieldParams { std::move(selectionSetParams), std::move(directives) }); |
| 61 | + resolverLock.unlock(); |
| 62 | + |
| 63 | + return service::ModifiedResult<Character>::convert(std::move(result), std::move(params)); |
| 64 | +} |
| 65 | + |
| 66 | +service::AwaitableResolver Subscription::resolveNewEpisode(service::ResolverParams&& params) const |
| 67 | +{ |
| 68 | + std::unique_lock resolverLock(_resolverMutex); |
| 69 | + service::SelectionSetParams selectionSetParams { static_cast<const service::SelectionSetParams&>(params) }; |
| 70 | + auto directives = std::move(params.fieldDirectives); |
| 71 | + auto result = _pimpl->getNewEpisode(service::FieldParams { std::move(selectionSetParams), std::move(directives) }); |
| 72 | + resolverLock.unlock(); |
| 73 | + |
| 74 | + return service::ModifiedResult<Episode>::convert(std::move(result), std::move(params)); |
| 75 | +} |
| 76 | + |
| 77 | +service::AwaitableResolver Subscription::resolve_typename(service::ResolverParams&& params) const |
| 78 | +{ |
| 79 | + return service::Result<std::string>::convert(std::string{ R"gql(Subscription)gql" }, std::move(params)); |
| 80 | +} |
| 81 | + |
| 82 | +} // namespace object |
| 83 | + |
| 84 | +void AddSubscriptionDetails(const std::shared_ptr<schema::ObjectType>& typeSubscription, const std::shared_ptr<schema::Schema>& schema) |
| 85 | +{ |
| 86 | + typeSubscription->AddFields({ |
| 87 | + schema::Field::Make(R"gql(characterChanged)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(Character)gql"sv))), |
| 88 | + schema::Field::Make(R"gql(newEpisode)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(Episode)gql"sv))) |
| 89 | + }); |
| 90 | +} |
| 91 | + |
| 92 | +} // namespace graphql::learn |
0 commit comments