I'm developing an android application that uses GraphQL as the back-end. I have the query and mutation part working perfectly. But I couln't find any documentations for authentication.
So how can I pass the username and password to the server and authenticate it?
LocalApolloClient.java :
public class LocalApolloClient {
private static final String URL = "http://192.168.1.100/graphql/";
private static ApolloClient apolloClient;
private static String authHeader = "";
public static ApolloClient getApolloClient(){
//HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
//loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(chain -> {
Request original = chain.request();
Request.Builder builder = original.newBuilder().method(original.method(), original.body());
builder.header("Authorization", authHeader);
return chain.proceed(builder.build());
})
.build();
apolloClient = ApolloClient.builder()
.serverUrl(URL)
.okHttpClient(okHttpClient)
.build();
return apolloClient;
}
}
Please note :
- This is not a duplicate question
- There is no proper documentation for graphQl
So kindly Justify if you negative vote.