Invalid class typecast in my GraphQL code...

Dear TMS,

I'm currently working on incorporating a mutation that includes a specific parameter defined as an INPUT item in the model. Unfortunately, I'm encountering issues with its proper functionality. I've added my programming attempt to the Bookshelf example (please refer to the attached file).

Upon running this code and applying the following query in the Playground, I encounter an "Invalid class typecast" error message.

mutation {
  testUpdate(input: {myInput: "this is a test"}) {

As a side note, when I omit the use of an INPUT item and instead use an integer or string parameter, the code works without any problems.

Could you please help me pinpoint where I might have gone wrong in this context?

Thank you in advance.

Kind Regards,
Stefan (10.0 KB)

Thank you very much for the sample project.

Currently the binder can't "deserialize" a real Delphi object from the generic input object. You should declare your method as receiving a IGraphQLMap (declared in unit GraphQL.Types):

    function TestUpdate(Input: IGraphQLMap): String;

Then implement it using its properties, rough example:

function TMutation.TestUpdate(Input: IGraphQLMap): String;
  Result := Input['myName'].AsString;
  // todo...some code will be added here later

Hi Wagner,

This works just fine like this. Thank you again for your help!

Kind Regards,

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.