Skip to content

Invalid input type declaration order in client gen. #230

Closed
@gitmodimo

Description

@gitmodimo

Given schema.graphql:

input InputA{
 a: Boolean!
}

input InputB{
 b: Float!
}

input InputBC{
 c: ID!
 b: InputB!
}

input InputABCD{
 d: String!
 a: InputA!
 b: InputB!
 bc: [InputBC!]!
}

type Output{
	id:Boolean
}
type Control{
	test(new: InputABCD!): Output
}
type Query{
 control: Control!
}
type Mutation{
 control: Control!
}

type Subscription{
 control: Control!
}

schema{
 query: Query,
 mutation: Mutation,
 subscription: Subscription
}

and request.graphql

query testQuery($stream: InputABCD!) {
    control {
        test(new: $stream) {
          id
        }
      }
    
  }  

clientgen.exe --schema schema.graphql --request request.graphql --prefix GQL --namespace GQL
generates "GQLClient.h":

...
struct Variables
{
	struct InputABCD
	{
		response::StringType d {};
		InputA a {};
		InputB b {};
		std::vector<InputBC> bc {};
	};

	struct InputA
	{
		response::BooleanType a {};
	};

	struct InputB
	{
		response::FloatType b {};
	};

	struct InputBC
	{
		response::IdType c {};
		InputB b {};
	};

	InputABCD stream {};
};
...

Clearly order of Variables declaration is not correct since InputABCD depends on InputA and InputB.

I narrowed down the problem in RequestLoader::reorderInputTypeDependencies() to
_referencedInputTypes...->fields...->type().lock()->name() being "" (empty)
and
_referencedInputTypes...->fields...->type().lock()->kind() being NON_NULL.
for all types. I could not find root problem of this.

Additionally when I manually fix order of declaration in header file there are also errors in source file GQLClient.cpp:

template <>
response::Value ModifiedVariable<Variables::InputABCD>::serialize(Variables::InputABCD&& inputValue)
{
	response::Value result { response::Type::Map };

	result.emplace_back(R"js(d)js"s, ModifiedVariable<response::StringType>::serialize(std::move(inputValue.d)));
	result.emplace_back(R"js(a)js"s, ModifiedVariable<InputA>::serialize(std::move(inputValue.a)));
	result.emplace_back(R"js(b)js"s, ModifiedVariable<InputB>::serialize(std::move(inputValue.b)));
	result.emplace_back(R"js(bc)js"s, ModifiedVariable<InputBC>::serialize<TypeModifier::List>(std::move(inputValue.bc)));

	return result;
}

InputA, InputB and InputBC are not referred to using their namespace Variables::InputA etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions