Skip to content

Commit 8a1604f

Browse files
committed
Fix same list value visitor bug in schemagen
1 parent 6695330 commit 8a1604f

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

SchemaGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ void Generator::DefaultValueVisitor::visitListValue(const peg::ast_node& listVal
10231023
{
10241024
DefaultValueVisitor visitor;
10251025

1026-
visitor.visit(*child->children.back());
1026+
visitor.visit(*child);
10271027
_value.emplace_back(visitor.getValue());
10281028
}
10291029
}

samples/TodaySchema.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,29 @@ std::future<response::Value> Query::resolveUnreadCounts(service::ResolverParams&
155155

156156
std::future<response::Value> Query::resolveAppointmentsById(service::ResolverParams&& params)
157157
{
158-
auto argIds = service::ModifiedArgument<std::vector<uint8_t>>::require<service::TypeModifier::List>("ids", params.arguments);
158+
const auto defaultArguments = []()
159+
{
160+
response::Value values(response::Type::Map);
161+
response::Value entry;
162+
163+
entry = []()
164+
{
165+
response::Value elements(response::Type::List);
166+
response::Value entry;
167+
168+
entry = response::Value(R"gql(ZmFrZUFwcG9pbnRtZW50SWQ=)gql");
169+
elements.emplace_back(std::move(entry));
170+
return elements;
171+
}();
172+
values.emplace_back("ids", std::move(entry));
173+
174+
return values;
175+
}();
176+
177+
auto pairIds = service::ModifiedArgument<std::vector<uint8_t>>::find<service::TypeModifier::List>("ids", params.arguments);
178+
auto argIds = (pairIds.second
179+
? std::move(pairIds.first)
180+
: service::ModifiedArgument<std::vector<uint8_t>>::require<service::TypeModifier::List>("ids", defaultArguments));
159181
auto result = getAppointmentsById(service::FieldParams(params, std::move(params.fieldDirectives)), std::move(argIds));
160182

161183
return service::ModifiedResult<Appointment>::convert<service::TypeModifier::List, service::TypeModifier::Nullable>(std::move(result), std::move(params));
@@ -811,7 +833,7 @@ void AddTypesToSchema(std::shared_ptr<introspection::Schema> schema)
811833
std::make_shared<introspection::InputValue>("before", R"md()md", schema->LookupType("ItemCursor"), R"gql()gql")
812834
}), schema->WrapType(introspection::__TypeKind::NON_NULL, schema->LookupType("FolderConnection"))),
813835
std::make_shared<introspection::Field>("appointmentsById", R"md()md", std::unique_ptr<std::string>(nullptr), std::vector<std::shared_ptr<introspection::InputValue>>({
814-
std::make_shared<introspection::InputValue>("ids", R"md()md", schema->WrapType(introspection::__TypeKind::NON_NULL, schema->WrapType(introspection::__TypeKind::LIST, schema->WrapType(introspection::__TypeKind::NON_NULL, schema->LookupType("ID")))), R"gql()gql")
836+
std::make_shared<introspection::InputValue>("ids", R"md()md", schema->WrapType(introspection::__TypeKind::NON_NULL, schema->WrapType(introspection::__TypeKind::LIST, schema->WrapType(introspection::__TypeKind::NON_NULL, schema->LookupType("ID")))), R"gql(["ZmFrZUFwcG9pbnRtZW50SWQ="])gql")
815837
}), schema->WrapType(introspection::__TypeKind::NON_NULL, schema->WrapType(introspection::__TypeKind::LIST, schema->LookupType("Appointment")))),
816838
std::make_shared<introspection::Field>("tasksById", R"md()md", std::unique_ptr<std::string>(nullptr), std::vector<std::shared_ptr<introspection::InputValue>>({
817839
std::make_shared<introspection::InputValue>("ids", R"md()md", schema->WrapType(introspection::__TypeKind::NON_NULL, schema->WrapType(introspection::__TypeKind::LIST, schema->WrapType(introspection::__TypeKind::NON_NULL, schema->LookupType("ID")))), R"gql()gql")

samples/schema.today.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Query {
2121
"""Folder unread counts [Connection](https://facebook.github.io/relay/docs/en/graphql-server-specification.html#connections)"""
2222
unreadCounts(first: Int, after: ItemCursor, last: Int, before: ItemCursor): FolderConnection!
2323

24-
appointmentsById(ids: [ID!]!) : [Appointment]!
24+
appointmentsById(ids: [ID!]! = ["ZmFrZUFwcG9pbnRtZW50SWQ="]) : [Appointment]!
2525
tasksById(ids: [ID!]!): [Task]!
2626
unreadCountsById(ids: [ID!]!): [Folder]!
2727

0 commit comments

Comments
 (0)