All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.apollographql.apollo3.testing.MockQuery.kt Maven / Gradle / Ivy

There is a newer version: 4.0.0-beta.7
Show newest version
package com.apollographql.apollo3.testing

import com.apollographql.apollo3.api.ResponseAdapterCache
import com.apollographql.apollo3.api.Operation
import com.apollographql.apollo3.api.Query
import com.apollographql.apollo3.api.ResponseField
import com.apollographql.apollo3.api.ResponseAdapter
import com.apollographql.apollo3.api.json.JsonReader
import com.apollographql.apollo3.api.json.JsonWriter

@Deprecated("Tests using MockQuery are very fragile to codegen changes, use integration tests instead")
class MockQuery : Query {

  override fun queryDocument(): String = "query MockQuery { name }"

  override fun serializeVariables(writer: JsonWriter, responseAdapterCache: ResponseAdapterCache) {
  }

  override fun adapter(): ResponseAdapter {
    return object : ResponseAdapter {
      override fun fromResponse(reader: JsonReader, responseAdapterCache: ResponseAdapterCache): Data {
        reader.beginObject()
        // consume the json stream
        while (reader.hasNext()) {
          reader.nextName()
          reader.skipValue()
        }
        reader.endObject()
        return Data
      }

      override fun toResponse(writer: JsonWriter, responseAdapterCache: ResponseAdapterCache, value: Data) {
        TODO("Not yet implemented")
      }
    }
  }

  override fun name(): String = "MockQuery"

  override fun operationId(): String = "MockQuery".hashCode().toString()

  object Data : Query.Data

  override fun responseFields(): List {
    return emptyList()
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy