Back

Appwrite Cloud Functions listDocuments

  • 0
  • Self Hosted
  • Flutter
  • Functions
paulanerl
16 Jan, 2024, 14:40

Hi guys -

I struggle with the cloud functions - I need to get Documents from 2 collections and then send it to the client. But I cannot find any documentation about listDocuments or something. I already tried graphql, but there I always get an error

I think there is just a small Syntax, but I tried long time and I also cannot find anything helpful...

I use appwrite CLI to deploy the function.

this is the error:

TypeScript
[response], {errors: [{message: Syntax Error: Expected :, found Name "collectionId", extensions: {category: graphql}, locations: [{line: 4, column: 11}]}]}
```

this is the code:
```
import 'dart:async';
import 'package:http/http.dart' as http;
import 'package:dart_appwrite/dart_appwrite.dart';

Future<dynamic> main(final context) async {
  final client = Client()
      .setEndpoint(endpoint)
      .setProject(String.fromEnvironment(projectId))
      .setKey(String.fromEnvironment(SecretKey));

  final graphQL = Graphql(client);

  final response = await graphQL.query(
    query: {
      'query': ''' query GetHubsAndPosts {
        databasesListDocuments(
          databaseId: $db_id,
          collectionId: $collectionId
        ) {
          total
          documents {
            _id
            data
          }
        }
      }
    '''
    },
  );

  context.log('[response], $response');

  return response;
}

```
TL;DR
The developer is having trouble with a cloud function in their app and is looking for assistance. They are trying to get documents from two collections but are encountering errors. They have already tried using GraphQL but encountered a syntax error. The developer is using the Appwrite CLI to deploy the function. Solution: The developer is advised to use the Appwrite Dart SDK instead of GraphQL. They are provided with the relevant documentation for using the SDK.
Ernest
16 Jan, 2024, 14:47

Do you need to use GraphQL? Or you'd be willing to use the dart sdk? Also, I don't see an import for the dart graphql package in your snippet. If you're willing to use the sdk here's the relevant documentation https://appwrite.io/docs/references/cloud/server-dart/databases

paulanerl
16 Jan, 2024, 15:00

actually I do not really need to use graphql - so I tried this but I always get

TypeScript
Execution timed out.

just after 480ms

What is now the fault?

Thank you for your assistence

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