Skip to content

Commit f7fc628

Browse files
committed
Fix iterator for nested input object types
1 parent 601bf57 commit f7fc628

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/Validation.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,38 +362,45 @@ ValidateExecutableVisitor::ValidateExecutableVisitor(const std::shared_ptr<schem
362362
const auto& mutationType = _schema->mutationType();
363363
const auto& subscriptionType = _schema->subscriptionType();
364364

365-
if (queryType)
366-
{
367-
_operationTypes[strQuery] = getValidateType(queryType);
368-
}
365+
_operationTypes.reserve(3);
369366

370367
if (mutationType)
371368
{
372369
_operationTypes[strMutation] = getValidateType(mutationType);
373370
}
374371

372+
if (queryType)
373+
{
374+
_operationTypes[strQuery] = getValidateType(queryType);
375+
}
376+
375377
if (subscriptionType)
376378
{
377379
_operationTypes[strSubscription] = getValidateType(subscriptionType);
378380
}
379381

380382
const auto& types = _schema->types();
381383

384+
_types.reserve(types.size());
385+
382386
for (const auto& entry : types)
383387
{
384388
const auto name = entry.first;
385389
const auto kind = entry.second->kind();
386390

387391
if (!isScalarType(kind))
388392
{
393+
auto matchingTypes = std::move(_matchingTypes[name]);
394+
389395
if (kind == introspection::TypeKind::OBJECT)
390396
{
391-
_matchingTypes[name].emplace(name);
397+
matchingTypes.emplace(name);
392398
}
393399
else
394400
{
395401
const auto& possibleTypes = entry.second->possibleTypes();
396-
internal::sorted_set<std::string_view> matchingTypes;
402+
403+
matchingTypes.reserve(possibleTypes.size());
397404

398405
for (const auto& possibleType : possibleTypes)
399406
{
@@ -404,18 +411,20 @@ ValidateExecutableVisitor::ValidateExecutableVisitor(const std::shared_ptr<schem
404411
matchingTypes.emplace(spType->name());
405412
}
406413
}
414+
}
407415

408-
if (!matchingTypes.empty())
409-
{
410-
_matchingTypes[name] = std::move(matchingTypes);
411-
}
416+
if (!matchingTypes.empty())
417+
{
418+
_matchingTypes[name] = std::move(matchingTypes);
412419
}
413420
}
414421
else if (kind == introspection::TypeKind::ENUM)
415422
{
416423
const auto& enumValues = entry.second->enumValues();
417424
internal::sorted_set<std::string_view> values;
418425

426+
values.reserve(enumValues.size());
427+
419428
for (const auto& value : enumValues)
420429
{
421430
if (value)
@@ -439,6 +448,8 @@ ValidateExecutableVisitor::ValidateExecutableVisitor(const std::shared_ptr<schem
439448

440449
const auto& directives = _schema->directives();
441450

451+
_directives.reserve(directives.size());
452+
442453
for (const auto& directive : directives)
443454
{
444455
const auto name = directive->name();
@@ -1052,6 +1063,9 @@ bool ValidateExecutableVisitor::validateInputValue(
10521063
// result.
10531064
return false;
10541065
}
1066+
1067+
// The recursive call may invalidate the iterator, so reacquire it.
1068+
itrFields = getInputTypeFields(name);
10551069
}
10561070

10571071
subFields.emplace(entry.first);

0 commit comments

Comments
 (0)