menu

Apollo

A community of developers, designers and others who love Apollo and GraphQL. 🚀

Channels
# All channels
view-forward
# General
view-forward
# Apollo Angular
view-forward
# Announcements
view-forward
# Apollo Android
view-forward
# Apollo Client
view-forward
# Apollo iOS
view-forward
# Apollo Link
view-forward
# Apollo Link Rest
view-forward
# Local State
view-forward
# Apollo Studio
view-forward
# Apollo Server
view-forward
# Apollo Tooling
view-forward
# Contributing
view-forward
# Docs
view-forward
# Events
view-forward
# GraphQL Tools
view-forward
# Jobs
view-forward
# Random
view-forward
# React Apollo
view-forward
# Showcase
view-forward
# Subscriptions
view-forward
# Testing
view-forward
# Vue Apollo
view-forward
Team

ApolloHttpException: HTTP 500 Internal Server Error

February 25, 2021 at 7:56am

ApolloHttpException: HTTP 500 Internal Server Error

February 25, 2021 at 7:56am
I'm fairly new to apollo for android, I keep getting this error when trying make a loginQuery
I keep getting the HTTP 500 Internal Server Error in my android studio trying to call a loginQuery with apollo client for android, following this tutorial : link to apollo docs
Yet when i run the same query in graphiQL in my browser, it succeeds. And when I run other mutations and queries, it works making me to think that there's something I'm doing wrong on this one.
here's my code:
String userNumber = numberInput.getText().toString();
String password = passwordInput.getText().toString();
Intent intent;
LogInQuery logInQuery = LogInQuery.builder().nationalID(userNumber)
.password(password).build();
apolloClient.query(logInQuery).enqueue(new ApolloCall.Callback<LogInQuery.Data>() {
@Override
public void onResponse(@NotNull Response<LogInQuery.Data> response) {
LogInQuery.Data data = response.getData();
List<Error> error = response.getErrors();
assert error != null;
String errorMessage = error.get(0).getMessage();
assert data != null;
Log.d(TAG, "onResponse: " + data.login() + "-" + data.login());
if(data.login() == null){
Log.e("Apollo", "an Error occurred : " + errorMessage);
runOnUiThread(() -> {
// Stuff that updates the UI
loading.setVisibility(View.GONE);
Toast.makeText(LogInActivity.this,
errorMessage, Toast.LENGTH_LONG).show();
});
} else {
runOnUiThread(() -> {
// Stuff that updates the UI
loading.setVisibility(View.GONE);
Toast.makeText(LogInActivity.this,
"New User Created!", Toast.LENGTH_LONG).show();
//Intent intent = new Intent(LogInActivity.this, LogInActivity.class);
//startActivity(intent);
});
}
}
@Override
public void onFailure(@NotNull ApolloException e) {
runOnUiThread(() -> {
Log.e("Apollo", "Error", e);
Toast.makeText(LogInActivity.this,
"An error occurred : " + e.getMessage(), Toast.LENGTH_LONG).show();
loading.setVisibility(View.GONE);
});
}
});
}
and here's my query : query LogIn($nationalID: String!, $password: String!) { login(nationalID: $nationalID, password: $password){ id token tokenExpiration } }
What am I doing wrong? if any of you have ideas... please help.

February 25, 2021 at 10:34am
Hi (itwabi) 👋 ! In these cases, it's often useful to dump the actual network request and compare it to GraphiQL, then you can see what can make the server choke. I usually use Charles Proxy to do this (https://www.charlesproxy.com/). If proxying is not an option, you can also use the OkHttp loggin interceptor: https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor
  • reply
  • like

February 25, 2021 at 6:02pm
``` OkHttpClient httpClient = new OkHttpClient.Builder() .addInterceptor(chain -> { Request original = chain.request(); Request.Builder builder = original.newBuilder().method(original.method(), original.body()); return chain.proceed(builder.build()); }) .build();
apolloClient = ApolloClient.builder().okHttpClient(httpClient)
.serverUrl("https://waste-mgmt-api.herokuapp.com/graphql")
.callFactory(httpClient)
.build();``` , From this I don't get any logs except the one's I already had, is my code correct? or there's something I'm missing?
  • reply
  • like
Hi (itwabi) 👋 ! In these cases, it's often useful to dump the actual network request and compare it to GraphiQL, then you can see what can make the server choke. I usually use Charles Proxy to do this (https://www.charlesproxy.com/). If proxying is not an option, you can also use the OkHttp loggin interceptor: https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor
I tried to look at the interceptor like you said, but I can't quite get it to work, how to I get the log I'm looking for? I only get the logs I was already getting, so maybe my code is missing something? here's the code I have
OkHttpClient httpClient = new OkHttpClient.Builder() .addInterceptor(chain -> { Request original = chain.request(); Request.Builder builder = original.newBuilder().method(original.method(), original.body()); return chain.proceed(builder.build()); }) .build(); apolloClient = ApolloClient.builder().okHttpClient(httpClient) .serverUrl("https://waste-mgmt-api.herokuapp.com/graphql") .callFactory(httpClient) .build();
  • reply
  • like
You'll need to use the actual HttpLoggingInterceptor:
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(HttpLoggingInterceptor().apply {
level = BODY
})
.build()
val apolloClient = ApolloClient.builder()
.okHttpClient(okHttpClient)
.serverUrl("https://")
.build()
  • reply
  • like