https://kotlinlang.org logo
#apollo-kotlin
Title
# apollo-kotlin
a

agrosner

02/25/2023, 7:18 PM
To that note ^ - we have new schema that won’t be in the graph for awhile and we want to mock out that query only. We were thinking of using the network transport apis to intercept the request and delegate it to the test network transport when it finds a match. The schema we will include as a separate file alongside the regular schema and extend the Query type to add its query . Is this a good approach?
m

mbonnin

02/25/2023, 7:24 PM
Sounds reasonnable. If you have a big diff between your 2 schemas, you need 2 different services. Another option is to "patch" your existing schema with client side extensions. Apollo Kotlin supports
extra.graphqls
so you could put such a file next to your schema and do something like so:
Copy code
# extra.graphqls
type MyNewType {
  aCoolField: String!
}

extend type Query {
  myNewType: MyNewType!
}
Or is this what you're suggesting already?
using the network transport apis to intercept the request and delegate it to the test network transport when it finds a match
If you're writing your own
NetworkTransport
implementation, you might as well skip
TestNetworkTransport
completely as it's very thin
a

agrosner

02/25/2023, 7:30 PM
Ah cool! Thanks for that. Yea exactly what I’m suggesting! I think I tried that 6 months ago and ran into issues but tried it again on latest version last week and it seemed to compile and work.
m

mbonnin

02/25/2023, 7:32 PM
Something like this:
Copy code
class MyNetworkTransport(val delegate: HttpNetworkTransport): NetworkTransport {
    override fun <D : Operation.Data> execute(request: ApolloRequest<D>): Flow<ApolloResponse<D>> {
      return if (request.operation is MyFakeOperation) {
        flowOf(
            ApolloResponse.Builder(
                operation = request.operation,
                data = request.operation.parseJsonResponse(myFakeJson).data,
                requestUuid = request.requestUuid
            ).build()
        )
      } else {
        delegate.execute(request)
      }
    }

    override fun dispose() {
      delegate.dispose()
    }
  }
Let us know how that goes!
a

agrosner

02/26/2023, 12:09 AM
Will do!
@mbonnin it worked great!
11 Views