Skip to content

How to pass JSON paramter in mutation query in android ? When i pass error FATAL EXCEPTION: Apollo Dispatcher and JSON to: class java.lang.Object. Did you forget to add custom type adapter? #890

Closed
@Ali-zain-javed

Description

@Ali-zain-javed

mutation new_mutation($email:JSON!,$password:JSON!)
{
Account
{
AccountLogin(input:{credentials:{email:$email,password:$password}})
{
obj
}
}
}

and this is function:

private void mutation()
{
try {
JSONObject jsonBody1 = new JSONObject();
JSONObject jsonBody2 = new JSONObject();
jsonBody1.put("email", "orient@blueeast.com");
jsonBody2.put("password", "Ori@1");
Myapolloclient.getmyapolloclient().mutate(
New_mutationMutation.builder().email(jsonBody1).password(jsonBody2).build()).enqueue(new ApolloCall.Callback<New_mutationMutation.Data>(){

            @Override
            public void onResponse(@Nonnull Response<New_mutationMutation.Data> dataResponse)   {

                Log.d("response", dataResponse.data().Account().__typename());
            }

            @Override
            public void onFailure(@Nonnull ApolloException e) {

            }
        });
    } catch (Throwable t) {
        Log.d("exception", t.toString());
    }
}

Activity

Ali-zain-javed

Ali-zain-javed commented on Apr 19, 2018

@Ali-zain-javed
Author

@digitalbuddha @sav007 please sir review this ,thanks

digitalbuddha

digitalbuddha commented on Apr 19, 2018

@digitalbuddha
Contributor

Why would need to make json instead of passing strings?

Ali-zain-javed

Ali-zain-javed commented on Apr 19, 2018

@Ali-zain-javed
Author

@digitalbuddha Sir when i use this same error occur
mutation new_mutation($email:JSON!,$password:JSON!)
{
Account
{
AccountLogin(input:{credentials:{email:$email,password:$password}})
{
obj
}
}
}

//////////////////////////////////////////////////calll

        Myapolloclient.getmyapolloclient().mutate(
                New_mutationMutation.builder().email("ali@gmail.com").password("password").build()).enqueue(new ApolloCall.Callback<New_mutationMutation.Data>(){

            @Override
            public void onResponse(@Nonnull Response<New_mutationMutation.Data> dataResponse) {

                Log.d("response", dataResponse.data().Account().__typename());
            }

            @Override
            public void onFailure(@Nonnull ApolloException e) {

            }
        });
    } catch (Throwable t) {
        Log.d("exception", t.toString());
    }
Ali-zain-javed

Ali-zain-javed commented on Apr 19, 2018

@Ali-zain-javed
Author

04-19 11:52:36.469 13430-13451/com.sourcey.materialloginexample E/AndroidRuntime: FATAL EXCEPTION: Apollo Dispatcher
Process: com.sourcey.materialloginexample, PID: 13430
java.lang.IllegalArgumentException: Can't map GraphQL type: JSON to: class java.lang.Object. Did you forget to add custom type adapter?
at com.apollographql.apollo.response.ScalarTypeAdapters.adapterFor(ScalarTypeAdapters.java:30)
at com.apollographql.apollo.internal.json.InputFieldJsonWriter.writeCustom(InputFieldJsonWriter.java:72)
at com.example.alizain.new_apollo_example.New_mutationMutation$Variables$1.marshal(New_mutationMutation.java:149)
at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor.httpRequestBody(ApolloServerInterceptor.java:147)
at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor.httpCall(ApolloServerInterceptor.java:112)
at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$1.run(ApolloServerInterceptor.java:78)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

Ali-zain-javed

Ali-zain-javed commented on Apr 19, 2018

@Ali-zain-javed
Author

Sir server side accept object but from there data passing through string ,so error is creating

sav007

sav007 commented on Apr 23, 2018

@sav007
Contributor

You should pass email argument as a String or create a separate GraphQL type for it.

sav007

sav007 commented on May 1, 2018

@sav007
Contributor

With this PR you can now pass JSON as argument: #897

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sav007@digitalbuddha@Ali-zain-javed

        Issue actions

          How to pass JSON paramter in mutation query in android ? When i pass error FATAL EXCEPTION: Apollo Dispatcher and JSON to: class java.lang.Object. Did you forget to add custom type adapter? · Issue #890 · apollographql/apollo-kotlin