Back

Functions in context of execution can access subfolders?

  • 0
  • Flutter
  • Functions
Nathanael Ferreira
23 Mar, 2024, 17:02

I'm starting to work with Appwrite and would like to better understand the execution context of Functions;

Could I make a shared folder between functions and place them in a single repository?

For example, in the following structure:

└── functions ├── make_dove_appear │ └── main.dart ├── make_rabbit_appear │ └── main.dart └── shared └── my_magic_hat.dart

The main.dart file from my make_rabbit_appear folder/function, could you import my_magic_hat.dart from a subfolder of the directory?

TypeScript
import '../shared/my_magic_hat.dart';

void main() {
   // Loaded from the shared sub-folder?
   final magicHat = MyMagicHat();

   magicHat.makeAnimalAppear(
     AnimalAvailable.rabbit,
   );
}
TL;DR
Developers can share code between functions by creating symlinks to a common folder and specifying the path in the pubspec. This allows for a shared folder structure between functions within a single repository. By using relative paths in imports, like `import '../shared/my_magic_hat.dart';`, the shared resources can be accessed from different function directories.
Nathanael Ferreira
23 Mar, 2024, 17:05

See that I will register two different functions. They will be called from different places and will have different functions.

But they used some common resource.

Steven
23 Mar, 2024, 17:14

If you deploy function and specify make_dove_appear as the folder, only that folder is added into the container for building

Steven
23 Mar, 2024, 17:16

That said, you can share code by using symlinks to make it as if the common folder was in the folder being deployed

Steven
23 Mar, 2024, 17:17

And then put an entry in your pub spec that points to that path

Steven
23 Mar, 2024, 17:23

So something like:

  • functions
    • dependencies
      • common <--- symlink
    • lib
      • main.dart
    • pubspec.yaml
Steven
23 Mar, 2024, 17:24

And pubspec has

TypeScript
dependencies: 
  common:
    path: dependencies/common
Nathanael Ferreira
23 Mar, 2024, 17:34

It's pretty clear now! Thank you for your time and tip!

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more