Skip to content

Commit 62cada5

Browse files
committed
Convert the learn sample to use non-Base64 ID instead of String for id fields
1 parent c5b563d commit 62cada5

15 files changed

+48
-48
lines changed

samples/learn/DroidData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void Droid::addFriends(
3535
});
3636
}
3737

38-
const std::string& Droid::getId() const noexcept
38+
const response::IdType& Droid::getId() const noexcept
3939
{
4040
return id_;
4141
}

samples/learn/DroidData.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class Droid
2222

2323
void addFriends(std::vector<SharedHero> friends) noexcept;
2424

25-
const std::string& getId() const noexcept;
25+
const response::IdType& getId() const noexcept;
2626
const std::optional<std::string>& getName() const noexcept;
2727
std::optional<std::vector<std::shared_ptr<object::Character>>> getFriends() const noexcept;
2828
std::optional<std::vector<std::optional<Episode>>> getAppearsIn() const noexcept;
2929
const std::optional<std::string>& getPrimaryFunction() const noexcept;
3030

3131
private:
32-
const std::string id_;
32+
const response::IdType id_;
3333
const std::optional<std::string> name_;
3434
const std::vector<Episode> appearsIn_;
3535
const std::optional<std::string> primaryFunction_;

samples/learn/HumanData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void Human::addFriends(std::vector<SharedHero> friends) noexcept
3434
});
3535
}
3636

37-
const std::string& Human::getId() const noexcept
37+
const response::IdType& Human::getId() const noexcept
3838
{
3939
return id_;
4040
}

samples/learn/HumanData.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ class Human
2020

2121
void addFriends(std::vector<SharedHero> friends) noexcept;
2222

23-
const std::string& getId() const noexcept;
23+
const response::IdType& getId() const noexcept;
2424
const std::optional<std::string>& getName() const noexcept;
2525
std::optional<std::vector<std::shared_ptr<object::Character>>> getFriends() const noexcept;
2626
std::optional<std::vector<std::optional<Episode>>> getAppearsIn() const noexcept;
2727
const std::optional<std::string>& getHomePlanet() const noexcept;
2828

2929
private:
30-
const std::string id_;
30+
const response::IdType id_;
3131
const std::optional<std::string> name_;
3232
const std::vector<Episode> appearsIn_;
3333
const std::optional<std::string> homePlanet_;

samples/learn/QueryData.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
namespace graphql::learn {
99

1010
Query::Query(std::map<Episode, SharedHero>&& heroes,
11-
std::map<std::string, std::shared_ptr<Human>>&& humans,
12-
std::map<std::string, std::shared_ptr<Droid>>&& droids) noexcept
11+
std::map<response::IdType, std::shared_ptr<Human>>&& humans,
12+
std::map<response::IdType, std::shared_ptr<Droid>>&& droids) noexcept
1313
: heroes_ { std::move(heroes) }
1414
, humans_ { std::move(humans) }
1515
, droids_ { std::move(droids) }
@@ -29,7 +29,7 @@ std::shared_ptr<object::Character> Query::getHero(std::optional<Episode> episode
2929
return result;
3030
}
3131

32-
std::shared_ptr<object::Human> Query::getHuman(const std::string& idArg) const noexcept
32+
std::shared_ptr<object::Human> Query::getHuman(const response::IdType& idArg) const noexcept
3333
{
3434
std::shared_ptr<Human> result;
3535

@@ -41,7 +41,7 @@ std::shared_ptr<object::Human> Query::getHuman(const std::string& idArg) const n
4141
return std::make_shared<object::Human>(std::move(result));
4242
}
4343

44-
std::shared_ptr<object::Droid> Query::getDroid(const std::string& idArg) const noexcept
44+
std::shared_ptr<object::Droid> Query::getDroid(const response::IdType& idArg) const noexcept
4545
{
4646
std::shared_ptr<Droid> result;
4747

samples/learn/QueryData.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ class Query
1717
{
1818
public:
1919
explicit Query(std::map<Episode, SharedHero>&& heroes,
20-
std::map<std::string, std::shared_ptr<Human>>&& humans,
21-
std::map<std::string, std::shared_ptr<Droid>>&& droids) noexcept;
20+
std::map<response::IdType, std::shared_ptr<Human>>&& humans,
21+
std::map<response::IdType, std::shared_ptr<Droid>>&& droids) noexcept;
2222

2323
std::shared_ptr<object::Character> getHero(std::optional<Episode> episodeArg) const noexcept;
24-
std::shared_ptr<object::Human> getHuman(const std::string& idArg) const noexcept;
25-
std::shared_ptr<object::Droid> getDroid(const std::string& idArg) const noexcept;
24+
std::shared_ptr<object::Human> getHuman(const response::IdType& idArg) const noexcept;
25+
std::shared_ptr<object::Droid> getDroid(const response::IdType& idArg) const noexcept;
2626

2727
private:
2828
const std::map<Episode, SharedHero> heroes_;
29-
const std::map<std::string, std::shared_ptr<Human>> humans_;
30-
const std::map<std::string, std::shared_ptr<Droid>> droids_;
29+
const std::map<response::IdType, std::shared_ptr<Human>> humans_;
30+
const std::map<response::IdType, std::shared_ptr<Droid>> droids_;
3131
};
3232

3333
} // namespace graphql::learn

samples/learn/StarWarsData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ std::shared_ptr<service::Request> GetService() noexcept
9797
{ learn::Episode::JEDI, { artoo } },
9898
};
9999

100-
std::map<std::string, std::shared_ptr<learn::Human>> humans {
100+
std::map<response::IdType, std::shared_ptr<learn::Human>> humans {
101101
{ luke->getId(), luke },
102102
{ vader->getId(), vader },
103103
{ han->getId(), han },
104104
{ leia->getId(), leia },
105105
{ tarkin->getId(), tarkin },
106106
};
107107

108-
std::map<std::string, std::shared_ptr<learn::Droid>> droids {
108+
std::map<response::IdType, std::shared_ptr<learn::Droid>> droids {
109109
{ threepio->getId(), threepio },
110110
{ artoo->getId(), artoo },
111111
};

samples/learn/schema/CharacterObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void Character::endSelectionSet(const service::SelectionSetParams& params) const
3535
void AddCharacterDetails(const std::shared_ptr<schema::InterfaceType>& typeCharacter, const std::shared_ptr<schema::Schema>& schema)
3636
{
3737
typeCharacter->AddFields({
38-
schema::Field::Make(R"gql(id)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(String)gql"sv))),
38+
schema::Field::Make(R"gql(id)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(ID)gql"sv))),
3939
schema::Field::Make(R"gql(name)gql"sv, R"md()md"sv, std::nullopt, schema->LookupType(R"gql(String)gql"sv)),
4040
schema::Field::Make(R"gql(friends)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::LIST, schema->LookupType(R"gql(Character)gql"sv))),
4141
schema::Field::Make(R"gql(appearsIn)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::LIST, schema->LookupType(R"gql(Episode)gql"sv)))

samples/learn/schema/DroidObject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ service::AwaitableResolver Droid::resolveId(service::ResolverParams&& params) co
6464
auto result = _pimpl->getId(service::FieldParams(service::SelectionSetParams{ params }, std::move(directives)));
6565
resolverLock.unlock();
6666

67-
return service::ModifiedResult<std::string>::convert(std::move(result), std::move(params));
67+
return service::ModifiedResult<response::IdType>::convert(std::move(result), std::move(params));
6868
}
6969

7070
service::AwaitableResolver Droid::resolveName(service::ResolverParams&& params) const
@@ -120,7 +120,7 @@ void AddDroidDetails(const std::shared_ptr<schema::ObjectType>& typeDroid, const
120120
std::static_pointer_cast<const schema::InterfaceType>(schema->LookupType(R"gql(Character)gql"sv))
121121
});
122122
typeDroid->AddFields({
123-
schema::Field::Make(R"gql(id)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(String)gql"sv))),
123+
schema::Field::Make(R"gql(id)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(ID)gql"sv))),
124124
schema::Field::Make(R"gql(name)gql"sv, R"md()md"sv, std::nullopt, schema->LookupType(R"gql(String)gql"sv)),
125125
schema::Field::Make(R"gql(friends)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::LIST, schema->LookupType(R"gql(Character)gql"sv))),
126126
schema::Field::Make(R"gql(appearsIn)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::LIST, schema->LookupType(R"gql(Episode)gql"sv))),

samples/learn/schema/DroidObject.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ namespace methods::DroidHas {
2323
template <class TImpl>
2424
concept getIdWithParams = requires (TImpl impl, service::FieldParams params)
2525
{
26-
{ service::AwaitableScalar<std::string> { impl.getId(std::move(params)) } };
26+
{ service::AwaitableScalar<response::IdType> { impl.getId(std::move(params)) } };
2727
};
2828

2929
template <class TImpl>
3030
concept getId = requires (TImpl impl)
3131
{
32-
{ service::AwaitableScalar<std::string> { impl.getId() } };
32+
{ service::AwaitableScalar<response::IdType> { impl.getId() } };
3333
};
3434

3535
template <class TImpl>
@@ -113,7 +113,7 @@ class Droid final
113113
virtual void beginSelectionSet(const service::SelectionSetParams& params) const = 0;
114114
virtual void endSelectionSet(const service::SelectionSetParams& params) const = 0;
115115

116-
virtual service::AwaitableScalar<std::string> getId(service::FieldParams&& params) const = 0;
116+
virtual service::AwaitableScalar<response::IdType> getId(service::FieldParams&& params) const = 0;
117117
virtual service::AwaitableScalar<std::optional<std::string>> getName(service::FieldParams&& params) const = 0;
118118
virtual service::AwaitableObject<std::optional<std::vector<std::shared_ptr<Character>>>> getFriends(service::FieldParams&& params) const = 0;
119119
virtual service::AwaitableScalar<std::optional<std::vector<std::optional<Episode>>>> getAppearsIn(service::FieldParams&& params) const = 0;
@@ -129,7 +129,7 @@ class Droid final
129129
{
130130
}
131131

132-
service::AwaitableScalar<std::string> getId(service::FieldParams&& params) const final
132+
service::AwaitableScalar<response::IdType> getId(service::FieldParams&& params) const final
133133
{
134134
if constexpr (methods::DroidHas::getIdWithParams<T>)
135135
{

0 commit comments

Comments
 (0)