Skip to content

Instantly share code, notes, and snippets.

@danahartweg
Created July 4, 2022 19:31
Show Gist options
  • Save danahartweg/09239a7b52fad75d23083b76bb925c5c to your computer and use it in GitHub Desktop.
Save danahartweg/09239a7b52fad75d23083b76bb925c5c to your computer and use it in GitHub Desktop.
User repository - Unit testing Flutter GraphQL
class UserRepository {
late final GraphQLClient _graphQLClient;
UserRepository({
GraphQLClient? graphQLClient,
}) {
_graphQLClient = graphQLClient ?? locator<GraphQLClient>();
}
Future<String?> create(String id, String? email) async {
final result = await _graphQLClient.mutate$CreateUser(
Options$Mutation$CreateUser(
variables: Variables$Mutation$CreateUser(
id: id,
email: email,
),
),
);
final userId = result.parsedData?.addUser?.user?.first?.xid;
if (userId == null || result.hasException) {
// TODO handle errors better
throw Exception(result.exception?.graphqlErrors);
}
return userId;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment