Shared function is only allowed as a public field of an actor

Hi,

I’m trying to define a query function to call from within another actor using composite queries:

public composite query func getLeagues() : async Result.Result<[DTOs.FootballLeagueDTO], T.Error> {
      let data_canister = actor (NetworkEnvVars.DATA_CANISTER_ID) : actor {
        getLeagues : shared query () -> async Result.Result<[T.FootballLeague], T.Error>;
      };
      return await data_canister.getLeagues();
    };

But I get the error a shared function is only allowed as a public field of an actor.

I’m thinking it is because of how my file structure is, I have an actor that calls a module containing my data manager class:


module {

  public class DataManager() {

Full file here:

Yeah, unfortunately you really do have to define the shared functions in the main actor.

For update calls, you can abstract the bodies of those functions into local async or async* functions, but not for queries or composite queries.

Sorry about that.

1 Like

No worries, thanks for confirming.