Skip to content

Commit

Permalink
Update Apollo Execution
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Sep 4, 2024
1 parent 1808948 commit fbaaa74
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion gradle/libraries.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android-sdkversion-target = "30"
androidx-sqlite = "2.3.1"
# This is used by the gradle integration tests to get the artifacts locally
apollo = "4.0.1-SNAPSHOT"
apollo-execution = "0.0.2"
apollo-execution = "0.0.3"
apollo-normalizedcache-incubating-snapshot = "0.0.3-SNAPSHOT"
# Used by the apollo-tooling project which uses a published version of Apollo
apollo-published = "4.0.0-rc.1"
Expand Down
10 changes: 8 additions & 2 deletions libraries/apollo-debug-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ tasks.configureEach {

apolloExecution {
service("apolloDebugServer") {
packageName = "com.apollographql.apollo.debugserver.internal.graphql"
schemaPath.set("graphql/schema.graphqls")
packageName.set("com.apollographql.apollo.debugserver.internal.graphql")
}
}

/**
* apolloCheckSchema is registered as a dependent of build but the ci doesn't call the "build" task directly
*/
tasks.named("jvmTest") {
finalizedBy("apolloCheckSchema")
}
4 changes: 2 additions & 2 deletions libraries/apollo-debug-server/graphql/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ schema {
query: Query
}

scalar Fields

"""
The root query
"""
Expand Down Expand Up @@ -43,3 +41,5 @@ type Record {

sizeInBytes: Int!
}

scalar Fields
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,19 @@ import com.apollographql.apollo.cache.normalized.apolloStore
import com.apollographql.execution.Coercing
import com.apollographql.execution.ExecutableSchema
import com.apollographql.execution.StringCoercing
import com.apollographql.execution.annotation.GraphQLCoercing
import com.apollographql.execution.annotation.GraphQLName
import com.apollographql.execution.annotation.GraphQLQueryRoot
import com.apollographql.execution.annotation.GraphQLQuery
import com.apollographql.execution.annotation.GraphQLScalar
import com.apollographql.execution.internal.ExternalValue
import com.apollographql.execution.internal.InternalValue
import com.apollographql.execution.parsePostGraphQLRequest
import com.apollographql.execution.parseGraphQLRequest
import okio.Buffer
import java.util.concurrent.atomic.AtomicReference
import kotlin.reflect.KClass

@GraphQLScalar
@GraphQLScalar(StringCoercing::class)
internal typealias ID = String

@GraphQLCoercing
internal object IDCoercing: Coercing<ID> by StringCoercing

internal class GraphQL(
private val apolloClients: AtomicReference<Map<ApolloClient, String>>,
) {
Expand All @@ -37,7 +33,7 @@ internal class GraphQL(
}

fun executeGraphQL(jsonBody: String): String {
val graphQLRequestResult = Buffer().writeUtf8(jsonBody).parsePostGraphQLRequest()
val graphQLRequestResult = Buffer().writeUtf8(jsonBody).parseGraphQLRequest()
if (!graphQLRequestResult.isSuccess) {
return graphQLRequestResult.exceptionOrNull()!!.message!!
}
Expand All @@ -53,7 +49,7 @@ internal class GraphQL(
/**
* The root query
*/
@GraphQLQueryRoot
@GraphQLQuery
internal class Query(private val apolloClients: AtomicReference<Map<ApolloClient, String>>) {
private fun graphQLApolloClients() =
apolloClients.get().map { (apolloClient, apolloClientId) ->
Expand Down Expand Up @@ -111,7 +107,7 @@ internal class NormalizedCache(
fun records(): List<GraphQLRecord> = records.map { GraphQLRecord(it.value) }
}

@GraphQLScalar
@GraphQLScalar(FieldsCoercing::class)
typealias Fields = Map<String, Any?>

@GraphQLName("Record")
Expand All @@ -125,8 +121,7 @@ internal class GraphQLRecord(
fun sizeInBytes(): Int = record.sizeInBytes
}

@GraphQLCoercing
internal class FieldsCoercing : Coercing<Fields> {
internal object FieldsCoercing : Coercing<Fields> {
// Taken from JsonRecordSerializer
@Suppress("UNCHECKED_CAST")
private fun InternalValue.toExternal(): ExternalValue {
Expand Down
1 change: 0 additions & 1 deletion libraries/apollo-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ if (relocateJar) {
apiDependencies.remove(it)
}


configurations.named("compileOnly").configure {
extendsFrom(shadeConfiguration)
}
Expand Down
12 changes: 6 additions & 6 deletions tests/sample-server/graphql/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ type QueryRoot {
}

type MutationRoot {
closeAllWebSockets: ID!
closeAllWebSockets: String!
}

type SubscriptionRoot {
count(to: Int!, intervalMillis: Int!): Int!

countString(to: Int!, intervalMillis: Int!): ID!
countString(to: Int!, intervalMillis: Int!): String!

secondsSinceEpoch(intervalMillis: Int!): Float!

operationError: ID!
operationError: String!

graphqlAccessError(after: Int!): Int

closeWebSocket: ID!
closeWebSocket: String!

state(intervalMillis: Int!): State!

valueSharedWithSubscriptions: Int!
}

type State {
tag: ID!
tag: String!

subscriptionId: ID!
subscriptionId: String!
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.apollographql.apollo.sample.server
import com.apollographql.apollo.sample.server.graphql.SubscriptionRoot
import com.apollographql.apollo.api.ExecutionContext
import com.apollographql.execution.ExecutableSchema
import com.apollographql.execution.parseGetGraphQLRequest
import com.apollographql.execution.parsePostGraphQLRequest
import com.apollographql.execution.parseGraphQLRequest
import com.apollographql.execution.parseGraphQLRequest
import com.apollographql.execution.websocket.ConnectionInitAck
import com.apollographql.execution.websocket.ConnectionInitError
import com.apollographql.execution.websocket.ConnectionInitHandler
Expand Down Expand Up @@ -59,8 +59,8 @@ class GraphQLHttpHandler(private val executableSchema: ExecutableSchema, private
override fun invoke(request: Request): Response {

val graphQLRequestResult = when (request.method) {
Method.GET -> request.uri.toString().parseGetGraphQLRequest()
Method.POST -> request.body.stream.source().buffer().use { it.parsePostGraphQLRequest() }
Method.GET -> request.uri.toString().parseGraphQLRequest()
Method.POST -> request.body.stream.source().buffer().use { it.parseGraphQLRequest() }
else -> error("")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package com.apollographql.apollo.sample.server.graphql

import com.apollographql.apollo.sample.server.WebSocketRegistry
import com.apollographql.apollo.api.ExecutionContext
import com.apollographql.execution.annotation.GraphQLMutationRoot
import com.apollographql.execution.annotation.GraphQLMutation


@GraphQLMutationRoot
@GraphQLMutation
class MutationRoot {
fun closeAllWebSockets(executionContext: ExecutionContext): String {
val registry = executionContext[WebSocketRegistry]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.apollographql.apollo.sample.server.graphql

import com.apollographql.execution.annotation.GraphQLQueryRoot
import com.apollographql.execution.annotation.GraphQLQuery


@GraphQLQueryRoot
@GraphQLQuery
class QueryRoot {
fun random(): Int = 42
fun zero(): Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.apollographql.apollo.sample.server.graphql

import com.apollographql.apollo.sample.server.CurrentWebSocket
import com.apollographql.apollo.api.ExecutionContext
import com.apollographql.execution.annotation.GraphQLSubscriptionRoot
import com.apollographql.execution.annotation.GraphQLSubscription
import com.apollographql.execution.websocket.subscriptionId
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import org.http4k.websocket.WsStatus

@GraphQLSubscriptionRoot
@GraphQLSubscription
class SubscriptionRoot(private val tag: String) {
fun count(to: Int, intervalMillis: Int): Flow<Int> = flow {
repeat(to) {
Expand Down

0 comments on commit fbaaa74

Please sign in to comment.