|
| 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 "StarWarsObjects.h" |
| 7 | + |
| 8 | +#include "graphqlservice/introspection/Introspection.h" |
| 9 | + |
| 10 | +#include <algorithm> |
| 11 | +#include <functional> |
| 12 | +#include <sstream> |
| 13 | +#include <stdexcept> |
| 14 | +#include <unordered_map> |
| 15 | + |
| 16 | +using namespace std::literals; |
| 17 | + |
| 18 | +namespace graphql::learn { |
| 19 | +namespace object { |
| 20 | + |
| 21 | +Droid::Droid() |
| 22 | + : service::Object({ |
| 23 | + "Character", |
| 24 | + "Droid" |
| 25 | + }, { |
| 26 | + { R"gql(id)gql"sv, [this](service::ResolverParams&& params) { return resolveId(std::move(params)); } }, |
| 27 | + { R"gql(name)gql"sv, [this](service::ResolverParams&& params) { return resolveName(std::move(params)); } }, |
| 28 | + { R"gql(friends)gql"sv, [this](service::ResolverParams&& params) { return resolveFriends(std::move(params)); } }, |
| 29 | + { R"gql(appearsIn)gql"sv, [this](service::ResolverParams&& params) { return resolveAppearsIn(std::move(params)); } }, |
| 30 | + { R"gql(__typename)gql"sv, [this](service::ResolverParams&& params) { return resolve_typename(std::move(params)); } }, |
| 31 | + { R"gql(primaryFunction)gql"sv, [this](service::ResolverParams&& params) { return resolvePrimaryFunction(std::move(params)); } } |
| 32 | + }) |
| 33 | +{ |
| 34 | +} |
| 35 | + |
| 36 | +service::FieldResult<response::StringType> Droid::getId(service::FieldParams&&) const |
| 37 | +{ |
| 38 | + throw std::runtime_error(R"ex(Droid::getId is not implemented)ex"); |
| 39 | +} |
| 40 | + |
| 41 | +std::future<service::ResolverResult> Droid::resolveId(service::ResolverParams&& params) |
| 42 | +{ |
| 43 | + std::unique_lock resolverLock(_resolverMutex); |
| 44 | + auto directives = std::move(params.fieldDirectives); |
| 45 | + auto result = getId(service::FieldParams(service::SelectionSetParams{ params }, std::move(directives))); |
| 46 | + resolverLock.unlock(); |
| 47 | + |
| 48 | + return service::ModifiedResult<response::StringType>::convert(std::move(result), std::move(params)); |
| 49 | +} |
| 50 | + |
| 51 | +service::FieldResult<std::optional<response::StringType>> Droid::getName(service::FieldParams&&) const |
| 52 | +{ |
| 53 | + throw std::runtime_error(R"ex(Droid::getName is not implemented)ex"); |
| 54 | +} |
| 55 | + |
| 56 | +std::future<service::ResolverResult> Droid::resolveName(service::ResolverParams&& params) |
| 57 | +{ |
| 58 | + std::unique_lock resolverLock(_resolverMutex); |
| 59 | + auto directives = std::move(params.fieldDirectives); |
| 60 | + auto result = getName(service::FieldParams(service::SelectionSetParams{ params }, std::move(directives))); |
| 61 | + resolverLock.unlock(); |
| 62 | + |
| 63 | + return service::ModifiedResult<response::StringType>::convert<service::TypeModifier::Nullable>(std::move(result), std::move(params)); |
| 64 | +} |
| 65 | + |
| 66 | +service::FieldResult<std::optional<std::vector<std::shared_ptr<service::Object>>>> Droid::getFriends(service::FieldParams&&) const |
| 67 | +{ |
| 68 | + throw std::runtime_error(R"ex(Droid::getFriends is not implemented)ex"); |
| 69 | +} |
| 70 | + |
| 71 | +std::future<service::ResolverResult> Droid::resolveFriends(service::ResolverParams&& params) |
| 72 | +{ |
| 73 | + std::unique_lock resolverLock(_resolverMutex); |
| 74 | + auto directives = std::move(params.fieldDirectives); |
| 75 | + auto result = getFriends(service::FieldParams(service::SelectionSetParams{ params }, std::move(directives))); |
| 76 | + resolverLock.unlock(); |
| 77 | + |
| 78 | + return service::ModifiedResult<service::Object>::convert<service::TypeModifier::Nullable, service::TypeModifier::List, service::TypeModifier::Nullable>(std::move(result), std::move(params)); |
| 79 | +} |
| 80 | + |
| 81 | +service::FieldResult<std::optional<std::vector<std::optional<Episode>>>> Droid::getAppearsIn(service::FieldParams&&) const |
| 82 | +{ |
| 83 | + throw std::runtime_error(R"ex(Droid::getAppearsIn is not implemented)ex"); |
| 84 | +} |
| 85 | + |
| 86 | +std::future<service::ResolverResult> Droid::resolveAppearsIn(service::ResolverParams&& params) |
| 87 | +{ |
| 88 | + std::unique_lock resolverLock(_resolverMutex); |
| 89 | + auto directives = std::move(params.fieldDirectives); |
| 90 | + auto result = getAppearsIn(service::FieldParams(service::SelectionSetParams{ params }, std::move(directives))); |
| 91 | + resolverLock.unlock(); |
| 92 | + |
| 93 | + return service::ModifiedResult<Episode>::convert<service::TypeModifier::Nullable, service::TypeModifier::List, service::TypeModifier::Nullable>(std::move(result), std::move(params)); |
| 94 | +} |
| 95 | + |
| 96 | +service::FieldResult<std::optional<response::StringType>> Droid::getPrimaryFunction(service::FieldParams&&) const |
| 97 | +{ |
| 98 | + throw std::runtime_error(R"ex(Droid::getPrimaryFunction is not implemented)ex"); |
| 99 | +} |
| 100 | + |
| 101 | +std::future<service::ResolverResult> Droid::resolvePrimaryFunction(service::ResolverParams&& params) |
| 102 | +{ |
| 103 | + std::unique_lock resolverLock(_resolverMutex); |
| 104 | + auto directives = std::move(params.fieldDirectives); |
| 105 | + auto result = getPrimaryFunction(service::FieldParams(service::SelectionSetParams{ params }, std::move(directives))); |
| 106 | + resolverLock.unlock(); |
| 107 | + |
| 108 | + return service::ModifiedResult<response::StringType>::convert<service::TypeModifier::Nullable>(std::move(result), std::move(params)); |
| 109 | +} |
| 110 | + |
| 111 | +std::future<service::ResolverResult> Droid::resolve_typename(service::ResolverParams&& params) |
| 112 | +{ |
| 113 | + return service::ModifiedResult<response::StringType>::convert(response::StringType{ R"gql(Droid)gql" }, std::move(params)); |
| 114 | +} |
| 115 | + |
| 116 | +} // namespace object |
| 117 | + |
| 118 | +void AddDroidDetails(std::shared_ptr<schema::ObjectType> typeDroid, const std::shared_ptr<schema::Schema>& schema) |
| 119 | +{ |
| 120 | + typeDroid->AddInterfaces({ |
| 121 | + std::static_pointer_cast<const schema::InterfaceType>(schema->LookupType(R"gql(Character)gql"sv)) |
| 122 | + }); |
| 123 | + typeDroid->AddFields({ |
| 124 | + schema::Field::Make(R"gql(id)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType("String"))), |
| 125 | + schema::Field::Make(R"gql(name)gql"sv, R"md()md"sv, std::nullopt, schema->LookupType("String")), |
| 126 | + schema::Field::Make(R"gql(friends)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::LIST, schema->LookupType("Character"))), |
| 127 | + schema::Field::Make(R"gql(appearsIn)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::LIST, schema->LookupType("Episode"))), |
| 128 | + schema::Field::Make(R"gql(primaryFunction)gql"sv, R"md()md"sv, std::nullopt, schema->LookupType("String")) |
| 129 | + }); |
| 130 | +} |
| 131 | + |
| 132 | +} // namespace graphql::learn |
0 commit comments