Created
July 4, 2022 19:31
-
-
Save danahartweg/09239a7b52fad75d23083b76bb925c5c to your computer and use it in GitHub Desktop.
User repository - Unit testing Flutter GraphQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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