Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/src/main/java/graphql/nadel/Nadel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ class Nadel private constructor(

return try {
val executionInstrumentation = instrumentation.beginQueryExecution(instrumentationParameters)

parseValidateAndExecute(executionInput, querySchema, instrumentationState, nadelExecutionParams)
val schema = if (nadelExecutionInput.executionHints.executeOnEngineSchema()) {
engineSchema
} else {
querySchema
}
parseValidateAndExecute(executionInput, schema, instrumentationState, nadelExecutionParams)
// finish up instrumentation
.whenComplete { result: ExecutionResult?, t: Throwable? ->
executionInstrumentation.onCompleted(result, t)
Expand Down Expand Up @@ -412,7 +416,7 @@ class Nadel private constructor(

@Deprecated("Use overallSchemas instead", replaceWith = ReplaceWith("overallSchemas(serviceDSLs)"))
fun dsl(serviceDSLs: Map<String, String>): Builder {
return serviceDSLs(serviceDSLs.mapValues { (k, v) -> StringReader(v) })
return serviceDSLs(serviceDSLs.mapValues { (_, v) -> StringReader(v) })
}

@Deprecated("Use overallSchemas instead", replaceWith = ReplaceWith("overallSchemas(serviceDSLs)"))
Expand Down
10 changes: 10 additions & 0 deletions lib/src/main/java/graphql/nadel/NadelExecutionHints.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package graphql.nadel
import graphql.nadel.hints.AllDocumentVariablesHint
import graphql.nadel.hints.LegacyOperationNamesHint
import graphql.nadel.hints.NadelDeferSupportHint
import graphql.nadel.hints.NadelExecuteOnEngineSchemaHint
import graphql.nadel.hints.NadelSharedTypeRenamesHint
import graphql.nadel.hints.NadelShortCircuitEmptyQueryHint
import graphql.nadel.hints.NadelVirtualTypeSupportHint
Expand All @@ -16,6 +17,7 @@ data class NadelExecutionHints(
val sharedTypeRenames: NadelSharedTypeRenamesHint,
val shortCircuitEmptyQuery: NadelShortCircuitEmptyQueryHint,
val virtualTypeSupport: NadelVirtualTypeSupportHint,
val executeOnEngineSchema: NadelExecuteOnEngineSchemaHint,
) {
/**
* Returns a builder with the same field values as this object.
Expand All @@ -35,6 +37,7 @@ data class NadelExecutionHints(
private var shortCircuitEmptyQuery = NadelShortCircuitEmptyQueryHint { false }
private var sharedTypeRenames = NadelSharedTypeRenamesHint { false }
private var virtualTypeSupport = NadelVirtualTypeSupportHint { false }
private var executeOnEngineSchema = NadelExecuteOnEngineSchemaHint { false }

constructor()

Expand All @@ -43,6 +46,7 @@ data class NadelExecutionHints(
allDocumentVariablesHint = nadelExecutionHints.allDocumentVariablesHint
newResultMergerAndNamespacedTypename = nadelExecutionHints.newResultMergerAndNamespacedTypename
shortCircuitEmptyQuery = nadelExecutionHints.shortCircuitEmptyQuery
executeOnEngineSchema = nadelExecutionHints.executeOnEngineSchema
}

fun legacyOperationNames(flag: LegacyOperationNamesHint): Builder {
Expand Down Expand Up @@ -80,6 +84,11 @@ data class NadelExecutionHints(
return this
}

fun executeOnEngineSchema(flag: NadelExecuteOnEngineSchemaHint): Builder {
executeOnEngineSchema = flag
return this
}

fun build(): NadelExecutionHints {
return NadelExecutionHints(
legacyOperationNames,
Expand All @@ -89,6 +98,7 @@ data class NadelExecutionHints(
sharedTypeRenames,
shortCircuitEmptyQuery,
virtualTypeSupport,
executeOnEngineSchema
)
}
}
Expand Down
10 changes: 6 additions & 4 deletions lib/src/main/java/graphql/nadel/NextgenEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import graphql.nadel.engine.transform.result.NadelResultTransformer
import graphql.nadel.engine.util.MutableJsonMap
import graphql.nadel.engine.util.beginExecute
import graphql.nadel.engine.util.compileToDocument
import graphql.nadel.engine.util.getFieldDefinitionSequence
import graphql.nadel.engine.util.getOperationDefinitionOrNull
import graphql.nadel.engine.util.getOperationKind
import graphql.nadel.engine.util.newExecutionResult
Expand All @@ -52,14 +51,12 @@ import graphql.nadel.instrumentation.parameters.child
import graphql.nadel.result.NadelResultMerger
import graphql.nadel.result.NadelResultTracker
import graphql.nadel.time.NadelInternalLatencyTracker
import graphql.nadel.util.NamespacedUtil
import graphql.nadel.util.NamespacedUtil.isNamespacedFieldLike
import graphql.nadel.util.OperationNameUtil
import graphql.nadel.validation.NadelSchemaValidation
import graphql.normalized.ExecutableNormalizedField
import graphql.normalized.ExecutableNormalizedOperationFactory.createExecutableNormalizedOperationWithRawVariables
import graphql.normalized.VariablePredicate
import graphql.schema.GraphQLObjectType
import graphql.schema.GraphQLSchema
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -162,8 +159,13 @@ internal class NextgenEngine(
.deferSupport(executionHints.deferSupport.invoke())

val operation = timer.time(step = RootStep.ExecutableOperationParsing) {
val schema = if (executionHints.executeOnEngineSchema()) {
engineSchema
} else {
querySchema
}
createExecutableNormalizedOperationWithRawVariables(
querySchema,
schema,
queryDocument,
executionInput.operationName,
executionInput.rawVariables,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package graphql.nadel.hints

fun interface NadelExecuteOnEngineSchemaHint {
/**
* Determines whether a query is executed on the engine schema (true) or query schema (false).
*/
operator fun invoke(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import graphql.nadel.tests.next.ExpectedNadelResult
import graphql.nadel.tests.next.ExpectedServiceCall
import graphql.nadel.tests.next.TestSnapshot
import graphql.nadel.tests.next.listOfJsonStrings
import kotlin.Suppress
import kotlin.collections.List
import kotlin.collections.listOf

private suspend fun main() {
graphql.nadel.tests.next.update<BasicObjectSchemaTest>()
Expand All @@ -16,10 +13,9 @@ private suspend fun main() {
/**
* This class is generated. Do NOT modify.
*
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots]
*/
@Suppress("unused")
public class BasicObjectSchemaTestSnapshot : TestSnapshot() {
@Suppress("unused") class BasicObjectSchemaTestSnapshot : TestSnapshot() {
override val calls: List<ExpectedServiceCall> = listOf(
ExpectedServiceCall(
service = "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import graphql.nadel.tests.next.ExpectedNadelResult
import graphql.nadel.tests.next.ExpectedServiceCall
import graphql.nadel.tests.next.TestSnapshot
import graphql.nadel.tests.next.listOfJsonStrings
import kotlin.Suppress
import kotlin.collections.List
import kotlin.collections.listOf

private suspend fun main() {
graphql.nadel.tests.next.update<EchoTest>()
Expand All @@ -16,10 +13,9 @@ private suspend fun main() {
/**
* This class is generated. Do NOT modify.
*
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots]
*/
@Suppress("unused")
public class EchoTestSnapshot : TestSnapshot() {
@Suppress("unused") class EchoTestSnapshot : TestSnapshot() {
override val calls: List<ExpectedServiceCall> = listOf(
ExpectedServiceCall(
service = "hello",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package graphql.nadel.tests.next.fixtures.basic

import graphql.nadel.tests.jsonObjectMapper
import graphql.nadel.tests.next.NadelIntegrationTest
import graphql.nadel.tests.next.SerializedJsonValue
import graphql.nadel.tests.next.jsonDataFetcher

class HiddenFieldHintOff : NadelIntegrationTest(
query = """
query {
issueById(id: "ari:cloud:jira:19b8272f-8d25-4706-adce-8db72305e615:issue/1") {
id
}
}
""".trimIndent(),
variables = mapOf(),
services = listOf(
Service(
name = "test",
overallSchema = """
type Query {
issueById(id: ID!): Issue @hidden
echo: String
}
type Issue {
id: ID!
}
""".trimIndent(),
runtimeWiring = { wiring ->
wiring
.type("Query") {
it.jsonDataFetcher("issueById") {
val idSerialized = jsonObjectMapper.writeValueAsString(it.getArgument("id"))

SerializedJsonValue.JsonObject(
"""
{
"id": $idSerialized
}
""".trimIndent(),
)
}
}
},
),
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// @formatter:off
package graphql.nadel.tests.next.fixtures.basic

import graphql.nadel.tests.next.ExpectedNadelResult
import graphql.nadel.tests.next.ExpectedServiceCall
import graphql.nadel.tests.next.TestSnapshot
import graphql.nadel.tests.next.listOfJsonStrings

private suspend fun main() {
graphql.nadel.tests.next.update<HiddenFieldHintOff>()
}

/**
* This class is generated. Do NOT modify.
*
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots]
*/
@Suppress("unused") class HiddenFieldHintOffSnapshot : TestSnapshot() {
override val calls: List<ExpectedServiceCall> = listOf(
)

/**
* ```json
* {
* "errors": [
* {
* "message": "Validation error (FieldUndefined@[issueById]) : Field 'issueById' in type
* 'Query' is undefined",
* "locations": [
* {
* "line": 2,
* "column": 3
* }
* ],
* "extensions": {
* "classification": "ValidationError"
* }
* }
* ]
* }
* ```
*/
override val result: ExpectedNadelResult = ExpectedNadelResult(
result = """
| {
| "errors": [
| {
| "message": "Validation error (FieldUndefined@[issueById]) : Field 'issueById' in type 'Query' is undefined",
| "locations": [
| {
| "line": 2,
| "column": 3
| }
| ],
| "extensions": {
| "classification": "ValidationError"
| }
| }
| ]
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package graphql.nadel.tests.next.fixtures.basic

import graphql.nadel.NadelExecutionHints
import graphql.nadel.tests.jsonObjectMapper
import graphql.nadel.tests.next.NadelIntegrationTest
import graphql.nadel.tests.next.SerializedJsonValue
import graphql.nadel.tests.next.jsonDataFetcher

class HiddenFieldHintOn : NadelIntegrationTest(
query = """
query {
issueById(id: "ari:cloud:jira:19b8272f-8d25-4706-adce-8db72305e615:issue/1") {
id
}
}
""".trimIndent(),
variables = mapOf(),
services = listOf(
Service(
name = "test",
overallSchema = """
type Query {
issueById(id: ID!): Issue @hidden
echo: String
}
type Issue {
id: ID!
}
""".trimIndent(),
runtimeWiring = { wiring ->
wiring
.type("Query") {
it.jsonDataFetcher("issueById") {
val idSerialized = jsonObjectMapper.writeValueAsString(it.getArgument("id"))

SerializedJsonValue.JsonObject(
"""
{
"id": $idSerialized
}
""".trimIndent(),
)
}
}
},
),
),
) {

override fun makeExecutionHints(): NadelExecutionHints.Builder {
return super.makeExecutionHints().executeOnEngineSchema { true }
}
}
Loading