Search in sources :

Example 16 with RealResponseReader

use of com.apollographql.apollo.internal.response.RealResponseReader in project apollo-android by apollographql.

the class OperationResponseParser method parse.

@SuppressWarnings("unchecked")
public Response<W> parse(@Nonnull Map<String, Object> payload) {
    checkNotNull(payload, "payload == null");
    D data = null;
    if (payload.containsKey("data")) {
        Map<String, Object> buffer = (Map<String, Object>) payload.get("data");
        RealResponseReader<Map<String, Object>> realResponseReader = new RealResponseReader<>(operation.variables(), buffer, new MapFieldValueResolver(), scalarTypeAdapters, responseNormalizer);
        data = (D) responseFieldMapper.map(realResponseReader);
    }
    List<Error> errors = null;
    if (payload.containsKey("errors")) {
        List<Map<String, Object>> errorPayloads = (List<Map<String, Object>>) payload.get("errors");
        if (errorPayloads != null) {
            errors = new ArrayList<>();
            for (Map<String, Object> errorPayload : errorPayloads) {
                errors.add(readError(errorPayload));
            }
        }
    }
    return Response.<W>builder(operation).data(operation.wrapData(data)).errors(errors).dependentKeys(responseNormalizer.dependentKeys()).build();
}
Also used : MapFieldValueResolver(com.apollographql.apollo.internal.field.MapFieldValueResolver) Error(com.apollographql.apollo.api.Error) RealResponseReader(com.apollographql.apollo.internal.response.RealResponseReader) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RealResponseReader (com.apollographql.apollo.internal.response.RealResponseReader)16 HashMap (java.util.HashMap)16 Map (java.util.Map)15 ResponseField (com.apollographql.apollo.api.ResponseField)13 ResponseReader (com.apollographql.apollo.api.ResponseReader)13 Test (org.junit.Test)13 List (java.util.List)4 MapFieldValueResolver (com.apollographql.apollo.internal.field.MapFieldValueResolver)3 Arrays.asList (java.util.Arrays.asList)3 Error (com.apollographql.apollo.api.Error)2 ScalarType (com.apollographql.apollo.api.ScalarType)1 UnmodifiableMapBuilder (com.apollographql.apollo.api.internal.UnmodifiableMapBuilder)1 BufferedSourceJsonReader (com.apollographql.apollo.internal.json.BufferedSourceJsonReader)1 ResponseJsonStreamReader (com.apollographql.apollo.internal.json.ResponseJsonStreamReader)1 CustomTypeAdapter (com.apollographql.apollo.response.CustomTypeAdapter)1 CustomTypeValue (com.apollographql.apollo.response.CustomTypeValue)1 ScalarTypeAdapters (com.apollographql.apollo.response.ScalarTypeAdapters)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1