GraphQL - how to release objects

Hello,

unfortunately I'm not able to post directly to the graphql forum (the new topic button is disabled) so I try to post this without category. Maybe I do not understand Your "Create a new Topic"? I cannot select a "DEV GraphQL" Category.

Could You please provide an example how and when to release the objects that are delivered with graphql?

At the moment I try the following:

I declare an Aurelius entity TPerson

function TQuery.Person(id: Integer): TPerson;
var
  Manager: TObjectManager;
begin
  Manager := TObjectManager.Create(ConnectionModule.CreateConnection);
  try
    Result := Manager.Find<TPerson>(id);
  finally
    Manager.Free;
  end;
end;

This works in one way. So when I input the line

Codesite.Send(‘lastname’, Result.lastname);

it shows the correct result.lastname.

But with the query

query {
  person(id: 9) {
    lastname
  }
}

I do not get a lastname in the playground

{
  "data": {
    "person": {
      "lastname": ""
    }
  }
}

It also works like this

function TQuery.Person(id: Integer): TPerson;
begin
  Result := TPerson.Create;
  Result.lastname := ‘schmid’;
end;

Then the playground shows the correct lastname.
But then I get a memory leak with the created and not released object. Btw: How can I release this Object and when?

Regards
Harald

It's up to you to manage all the objects. In the 1.1 release of GraphQL for Delphi, you can now access the current executer using the property TGraphQLExecuter.Current.

This way you can use AddOwnership method to tell the executer which objects it must destroy after the execution is finished:

function TQuery.Person(id: Integer): TPerson;
var
  Manager: TObjectManager;
begin
  Manager := TObjectManager.Create(ConnectionModule.CreateConnection);
  TGraphQLExecuter.Current.AddOwnership(Manager);
  Result := Manager.Find<TPerson>(id);
end;