I am trying to implement login authentication with graphql in flutter not sure how to proceed, plus I keep getting an error: The body might complete normally, causing null to be returned but the return type 'future or bool' is potentially non-nullable.
*** here is the graphql service
class GraphQLService {
static GraphQLConfig graphQLConfig = GraphQLConfig();
GraphQLClient client = graphQLConfig.clientToQuery();
Future<bool> login(
{String? email,
String? phoneauth,
String? username,
required String password}) async {
assert(email != null);
QueryResult result = await client.mutate(
MutationOptions(
document: gql("""
mutation Mutation(\$loginInput) {login(loginInput: \$loginInput)}
"""),
variables: {
"loginInput": {
'password': password,
'email': email,
'authPhone': phoneauth,
'username': username,
}
},
),
);
if (result.hasException) {
print(result.exception.toString());
return true;
}
String token = result.data!['login']['token'];
print(token);
}
}
****here is the config
class GraphQLConfig {
static HttpLink httpLink =
HttpLink('https://fakelink.com/graphql'); ///fake link
//creating the client
GraphQLClient clientToQuery() =>
GraphQLClient(link: httpLink, cache: GraphQLCache());
}
***here is the login model
class LoginModel {
final String? email;
final String? username;
final String? phoneauth;
final String password;
LoginModel({
this.email,
required this.password,
this.username,
this.phoneauth,
});
Map<String, dynamic> toJson() => {
'password': password,
'email': email,
'authPhone': phoneauth,
'username': username,
};
}