tvf_flutter_graphql 1.1.0 copy "tvf_flutter_graphql: ^1.1.0" to clipboard
tvf_flutter_graphql: ^1.1.0 copied to clipboard

GraphQL Query and Mutation Examples for Flutter/Dart. Provides ready-to-use GraphQL query and mutation examples for mobile app development with AWS Amplify. This package contains GraphQL operation exa [...]

TVF Flutter GraphQL Examples #

GraphQL query and mutation examples package for Flutter/Dart. This package provides ready-to-use GraphQL operation examples. Contains GraphQL query/mutation strings only - no model classes, just examples you can copy and use.

📦 Installation #

Add to your pubspec.yaml:

dependencies:
  tvf_flutter_graphql:
    path: ../packages/flutter-schema  # Local development
    # or
    # git:
    #   url: https://github.com/your-org/tvf-flutter-graphql
    #   path: packages/flutter-schema

Then run:

flutter pub get

🚀 Usage #

This package provides GraphQL query and mutation examples. Copy the query/mutation strings and use them with your own GraphQL client.

Import #

import 'package:tvf_flutter_graphql/tvf_flutter_graphql.dart';

Example: Get User Query #

// Copy the query string from UserQueries.getUser
const getUserQuery = UserQueries.getUser;

// Use with your GraphQL client (e.g., Amplify, graphql_flutter, etc.)
final result = await Amplify.API.query(
  request: GraphQLRequest<String>(
    document: getUserQuery,
    variables: {'id': userId},
  ),
).response;

if (!result.hasErrors) {
  final user = result.data?['getUser'];
  print('User: ${user?['fullName']}');
  print('Email: ${user?['email']}');
}

Example: Get User Count Query #

// Copy the query string
const getUserCountQuery = '''
  query GetUserCount($active: Boolean, $newUsers: Boolean) {
    getUserCount(active: $active, newUsers: $newUsers) {
      count
    }
  }
''';

// Use with your GraphQL client
final result = await Amplify.API.query(
  request: GraphQLRequest<String>(
    document: getUserCountQuery,
    variables: {
      'active': true,
      'newUsers': false,
    },
  ),
).response;

Example: List Users Query #

// Copy the query string
const listUsersQuery = UserQueries.listUsers;

// Use with your GraphQL client
final result = await Amplify.API.query(
  request: GraphQLRequest<String>(
    document: listUsersQuery,
    variables: {
      'filter': {'status': {'eq': 'active'}},
      'limit': 20,
    },
  ),
).response;

Example: Update User Mutation #

// Copy the mutation string
const updateUserMutation = UserMutations.updateUser;

// Use with your GraphQL client
final result = await Amplify.API.mutate(
  request: GraphQLRequest<String>(
    document: updateUserMutation,
    variables: {
      'input': {
        'id': userId,
        'fullName': 'New Name',
        'phoneNumber': '+84123456789',
      },
    },
  ),
).response;

Example: Deactivate User Mutation #

// Copy the mutation string
const deactivateUserMutation = UserMutations.deactivateUser;

// Use with your GraphQL client
final result = await Amplify.API.mutate(
  request: GraphQLRequest<String>(
    document: deactivateUserMutation,
    variables: {
      'userId': userId,
      'useEmail': false,
    },
  ),
).response;

Example: List Devices Query #

// Copy the query string
const listDevicesQuery = DeviceQueries.listDevices;

// Use with your GraphQL client
final result = await Amplify.API.query(
  request: GraphQLRequest<String>(
    document: listDevicesQuery,
    variables: {
      'filter': {'userId': {'eq': userId}},
      'limit': 20,
    },
  ),
).response;

Example: Create Device Mutation #

// Copy the mutation string
const createDeviceMutation = DeviceMutations.createDevice;

// Use with your GraphQL client
final result = await Amplify.API.mutate(
  request: GraphQLRequest<String>(
    document: createDeviceMutation,
    variables: {
      'input': {
        'deviceId': 'ESP32-ABC123',
        'userId': currentUserId,
        'deviceName': 'Living Room Device',
        'deviceType': 'iot_device',
        'location': 'Living Room',
        'status': 'offline',
      },
    },
  ),
).response;

Example: Push Command Mutation #

// Copy the mutation string
const pushCommandMutation = DeviceMutations.pushCommand;

// Use with your GraphQL client
final result = await Amplify.API.mutate(
  request: GraphQLRequest<String>(
    document: pushCommandMutation,
    variables: {
      'topic': 'iot/device-id/down/command',
      'payload': jsonEncode({
        'command': 'setTemperature',
        'temperature': 75,
        'heater': 'f1',
      }),
    },
  ),
).response;

📚 Available GraphQL Examples #

Queries #

User

  • UserQueries.getUser - Get user by ID
  • UserQueries.listUsers - List users with pagination

Device

  • DeviceQueries.getDevice - Get device by ID
  • DeviceQueries.listDevices - List devices with filters

DeviceToken

  • DeviceTokenQueries.getDeviceToken - Get device token by ID
  • DeviceTokenQueries.listDeviceTokens - List device tokens
  • DeviceTokenQueries.tokensByUser - Query tokens by user

Notification

  • NotificationQueries.getNotification - Get notification by ID
  • NotificationQueries.listNotifications - List notifications
  • NotificationQueries.notificationsByUser - Query notifications by user (sorted by sentAt)

Mutations #

User

  • UserMutations.updateUser - Update user profile
  • UserMutations.deactivateUser - Deactivate user (custom mutation)
  • UserMutations.reactivateUser - Reactivate user (custom mutation)
  • UserMutations.removeUser - Remove user permanently (custom mutation)

Device

  • DeviceMutations.createDevice - Create new device
  • DeviceMutations.updateDevice - Update device (name, location, etc.)
  • DeviceMutations.pushCommand - Push command to AWS IoT Core topic

DeviceToken

  • DeviceTokenMutations.createDeviceToken - Register device token
  • DeviceTokenMutations.updateDeviceToken - Update device token
  • DeviceTokenMutations.deleteDeviceToken - Unregister device token

Notification

  • NotificationMutations.updateNotification - Update notification (mark as read)

💡 How to Use #

  1. Import the package:

    import 'package:tvf_flutter_graphql/tvf_flutter_graphql.dart';
    
  2. Copy the query/mutation string:

    const query = UserQueries.getUser;
    // or
    const mutation = UserMutations.updateUser;
    
  3. Use with your GraphQL client:

    // Example with Amplify
    final result = await Amplify.API.query(
      request: GraphQLRequest<String>(
        document: query,
        variables: {'id': userId},
      ),
    ).response;
    

Note: This package provides examples only. Copy the query/mutation strings and use them with your preferred GraphQL client (Amplify, graphql_flutter, etc.).

🔒 Authentication #

All GraphQL operations require authentication via AWS Cognito. Make sure to:

  1. Initialize Amplify with Cognito configuration
  2. Sign in user before making API calls
  3. Authentication headers are handled automatically by Amplify

📝 Notes #

Package Purpose #

This package provides GraphQL query and mutation examples only:

  • Contains ready-to-use GraphQL operation strings
  • Copy the query/mutation strings and use with your preferred GraphQL client
  • No model classes, no client implementation - just examples
  • Use with Amplify, graphql_flutter, or any other GraphQL client

Example Usage Pattern #

// 1. Import the package
import 'package:tvf_flutter_graphql/tvf_flutter_graphql.dart';

// 2. Copy the query/mutation string
const query = UserQueries.getUser;

// 3. Use with your GraphQL client
final result = await yourGraphQLClient.query(
  document: query,
  variables: {'id': userId},
);

🛠️ Development #

Build #

cd packages/flutter-schema
flutter pub get
flutter analyze

Format #

dart format lib/

📄 License #

See LICENSE file for details.

0
likes
0
points
7
downloads

Publisher

unverified uploader

Weekly Downloads

GraphQL Query and Mutation Examples for Flutter/Dart. Provides ready-to-use GraphQL query and mutation examples for mobile app development with AWS Amplify. This package contains GraphQL operation examples only - no model classes, just query/mutation strings.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

amplify_api, amplify_flutter, flutter, graphql

More

Packages that depend on tvf_flutter_graphql