sorry, it’s me again ;-) But I couldn’t find an answer for this question:
How can I put an argument in a field like described in GraphQL
{
user(id: 4) {
id
name
profilePic(size: 100)
}
}
It does not work with an object like this:
Tuser = class
private
Fid: Integer;
Fname: string;
public
property id: Integer read Fid write Fid;
property name: string read Fname write Fname;
function profilePic(size: Integer): string; // for simplicity the result type is string - could be some TprofilePic-Object
end;
GraphQL seems to request a property and not a function. But how could I put parameters / arguments to an property. It seems not to work with indexed properties either.
Actually that's how it's supposed to work. Yes, GraphQL schema fields can be mapped to properties and methods, especially because they can receive several parameters, not only one.
What is the exact error message you are receiving? Can you share your test project so we know better what's going on?
It seems that the resolver does not accept the function/method as a property. Or is the schema definition wrong and I have to write something else there?
Do I miss an attribute for profilePic?
Probably you didn't previously bind the class to the schema. In this case, GraphQL engine tries to get the field value dynamically, on the fly, and indeed in this case it only looks for fields.
But you can simply bind it in advance and it will properly use the method: