@@ -99,7 +99,7 @@ std::string_view RequestLoader::getRequestText() const noexcept
9999 return trimWhitespace (_requestText);
100100}
101101
102- const ResponseFieldList & RequestLoader::getVariables () const noexcept
102+ const RequestVariableList & RequestLoader::getVariables () const noexcept
103103{
104104 return _variables;
105105}
@@ -581,7 +581,7 @@ void RequestLoader::collectVariables() noexcept
581581{
582582 peg::for_each_child<peg::variable>(*_operation,
583583 [this ](const peg::ast_node& variableDefinition) {
584- ResponseField variable;
584+ RequestVariable variable;
585585 TypeVisitor variableType;
586586 service::schema_location defaultValueLocation;
587587
@@ -613,22 +613,24 @@ void RequestLoader::collectVariables() noexcept
613613
614614 const auto [type, modifiers] = variableType.getType ();
615615
616- variable.type = getSchemaType (type, modifiers );
617- variable.position = variableDefinition. begin () ;
616+ variable.type = _schema-> LookupType (type);
617+ variable.modifiers = modifiers ;
618618
619619 if (!variable.defaultValueString .empty ()
620620 && variable.defaultValue .type () == response::Type::Null
621621 && (modifiers.empty () || modifiers.front () != service::TypeModifier::Nullable))
622622 {
623623 std::ostringstream error;
624624
625- error << " Expected Non-Null default value for variable name: " << variable.name
626- << " line: " << defaultValueLocation.line
627- << " column: " << defaultValueLocation.column ;
625+ error << " Expected Non-Null default value for variable name: " << variable.name ;
628626
629- throw std::runtime_error (error.str ());
627+ throw service::schema_exception {
628+ { service::schema_error { error.str (), std::move (defaultValueLocation) } }
629+ };
630630 }
631631
632+ variable.position = variableDefinition.begin ();
633+
632634 _variables.push_back (std::move (variable));
633635 });
634636}
@@ -742,6 +744,41 @@ void RequestLoader::SelectionVisitor::visitField(const peg::ast_node& field)
742744 responseField.type = (*itr)->type ().lock ();
743745 }
744746
747+ bool wrapped = true ;
748+ bool nonNull = false ;
749+
750+ while (wrapped)
751+ {
752+ switch (responseField.type ->kind ())
753+ {
754+ case introspection::TypeKind::NON_NULL:
755+ nonNull = true ;
756+ responseField.type = responseField.type ->ofType ().lock ();
757+ break ;
758+
759+ case introspection::TypeKind::LIST:
760+ if (!nonNull)
761+ {
762+ responseField.modifiers .push_back (service::TypeModifier::Nullable);
763+ }
764+
765+ nonNull = false ;
766+ responseField.modifiers .push_back (service::TypeModifier::List);
767+ responseField.type = responseField.type ->ofType ().lock ();
768+ break ;
769+
770+ default :
771+ if (!nonNull)
772+ {
773+ responseField.modifiers .push_back (service::TypeModifier::Nullable);
774+ }
775+
776+ nonNull = false ;
777+ wrapped = false ;
778+ break ;
779+ }
780+ }
781+
745782 const peg::ast_node* selection = nullptr ;
746783
747784 peg::on_first_child<peg::selection_set>(field, [&selection](const peg::ast_node& child) {
@@ -750,20 +787,12 @@ void RequestLoader::SelectionVisitor::visitField(const peg::ast_node& field)
750787
751788 if (selection)
752789 {
753- auto ofType = responseField.type ;
754-
755- while (ofType->kind () == introspection::TypeKind::NON_NULL
756- || ofType->kind () == introspection::TypeKind::LIST)
757- {
758- ofType = ofType->ofType ().lock ();
759- }
760-
761- switch (ofType->kind ())
790+ switch (responseField.type ->kind ())
762791 {
763792 case introspection::TypeKind::OBJECT:
764793 case introspection::TypeKind::INTERFACE:
765794 {
766- SelectionVisitor selectionVisitor { _fragments, _schema, ofType };
795+ SelectionVisitor selectionVisitor { _fragments, _schema, responseField. type };
767796
768797 selectionVisitor.visit (*selection);
769798
@@ -780,7 +809,7 @@ void RequestLoader::SelectionVisitor::visitField(const peg::ast_node& field)
780809 case introspection::TypeKind::UNION:
781810 {
782811 ResponseUnionOptions options;
783- const auto & possibleTypes = ofType ->possibleTypes ();
812+ const auto & possibleTypes = responseField. type ->possibleTypes ();
784813
785814 for (const auto & weakType : possibleTypes)
786815 {
0 commit comments