Hi, I'm working on a simple Apollo Kotlin graphql ...
# android
r
Hi, I'm working on a simple Apollo Kotlin graphql and a bit of a beginner. I am just trying to get a request for my query but I keep getting 400 errors from Apollo. This is my code for FirstFragment.kt where I'm trying to execute the query in some way.
Copy code
package com.example.animod
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import com.apollographql.apollo3.api.Optional
import com.example.aniMod.CharacterQuery
import com.example.animod.databinding.FragmentFirstBinding



/**
 * A simple [Fragment] subclass as the default destination in the navigation.
 */
class FirstFragment : Fragment() {

  var _binding: FragmentFirstBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
     val binding get() = _binding!!


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentFirstBinding.inflate(inflater)
        return binding.root


    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        lifecycleScope.launchWhenResumed {
            val response = apolloClient.query(CharacterQuery(search =  Optional.Present<String>(""))).execute()
            Log.d("Anime Character Picture", "Success ${response.data}")
        }
    }


}
And this is my PictureQuery.kt file
Copy code
query Character($search: String) {
    person: Character(search: $search) {
        image {
            large
        }
    }
}
I appreciate any help . Thank you
b
The code looks OK to me. Have you tried running the Query on your service with GraphiQL or something like this? Guessing, but maybe
""
isn't a valid search term? 🙂