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: 4 additions & 6 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ jobs:
include:
- gradle-argument: 'assemble && ./gradlew check -x test -x testng'
label: 'check'
- gradle-argument: 'testWithJava11 testngWithJava11'
label: 'java11'
test-results-dirs: 'testWithJava11 testngWithJava11'
- gradle-argument: 'testWithJava17 testngWithJava17'
label: 'java17'
test-results-dirs: 'testWithJava17 testngWithJava17'
Expand Down Expand Up @@ -125,7 +122,7 @@ jobs:
const path = require('path');
const { parseJacocoXml } = require('./.github/scripts/parse-jacoco.js');

const versions = ['java11', 'java17', 'java21', 'java25', 'jcstress'];
const versions = ['java17', 'java21', 'java25', 'jcstress'];
const zeroTest = { total: 0, passed: 0, failed: 0, errors: 0, skipped: 0 };

// Read current baseline
Expand All @@ -136,13 +133,14 @@ jobs:
}

// Update test stats from artifacts
const tests = baseline.tests || {};
const previousTests = baseline.tests || {};
const tests = {};
for (const v of versions) {
const file = path.join('test-stats', `${v}.json`);
if (fs.existsSync(file)) {
tests[v] = JSON.parse(fs.readFileSync(file, 'utf8'));
} else {
tests[v] = tests[v] || zeroTest;
tests[v] = previousTests[v] || zeroTest;
}
}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:

const { parseJacocoXml, pct, zeroCov, isRegression } = require('./.github/scripts/parse-jacoco.js');

const versions = ['java11', 'java17', 'java21', 'java25', 'jcstress'];
const versions = ['java17', 'java21', 'java25', 'jcstress'];
const zeroTest = { total: 0, passed: 0, failed: 0, errors: 0, skipped: 0 };

// --- Read current test stats from artifacts ---
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ jobs:
include:
- gradle-argument: 'assemble && ./gradlew check -x test -x testng'
label: 'check'
- gradle-argument: 'testWithJava11 testngWithJava11'
label: 'java11'
test-results-dirs: 'testWithJava11 testngWithJava11'
- gradle-argument: 'testWithJava17 testngWithJava17'
label: 'java17'
test-results-dirs: 'testWithJava17 testngWithJava17'
Expand Down
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
./gradlew test
```

This runs tests on Java 25 only. Other JVM versions (11, 17, 21) require explicit tasks (e.g. `testWithJava11`).
The library requires Java 17 or later; the build toolchain uses Java 25.
This runs tests on Java 25 only. Other supported JVM versions (17, 21) require explicit tasks (e.g. `testWithJava17`).
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Discuss and ask questions in our Discussions: https://github.com/graphql-java/gr

This is a [GraphQL](https://github.com/graphql/graphql-spec) Java implementation.

The current development version requires **Java 17 or later** to run. The Gradle build uses a JDK 25 toolchain.

Latest build in Maven central: https://repo1.maven.org/maven2/com/graphql-java/graphql-java/

[![Build](https://github.com/graphql-java/graphql-java/actions/workflows/master.yml/badge.svg)](https://github.com/graphql-java/graphql-java/actions/workflows/master.yml)
Expand Down
2 changes: 2 additions & 0 deletions README.zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

该组件是 [GraphQL 规范](https://github.com/graphql/graphql-spec) 的 Java 实现。

当前开发版本需要 **Java 17 或更高版本**才能运行。Gradle 构建使用 JDK 25 工具链。

[![Build](https://github.com/graphql-java/graphql-java/actions/workflows/master.yml/badge.svg)](https://github.com/graphql-java/graphql-java/actions/workflows/master.yml)
[![Latest Release](https://img.shields.io/maven-central/v/com.graphql-java/graphql-java?versionPrefix=24.)](https://maven-badges.herokuapp.com/maven-central/com.graphql-java/graphql-java/)
[![Latest Snapshot](https://img.shields.io/maven-central/v/com.graphql-java/graphql-java?label=maven-central%20snapshot&versionPrefix=0)](https://maven-badges.herokuapp.com/maven-central/com.graphql-java/graphql-java/)
Expand Down
30 changes: 8 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ plugins {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(25) // build on 25 - release on 11
languageVersion = JavaLanguageVersion.of(25) // build on 25 - release on 17
}
}

kotlin {
compilerOptions {
apiVersion = KotlinVersion.KOTLIN_2_0
languageVersion = KotlinVersion.KOTLIN_2_0
jvmTarget = JvmTarget.JVM_11
jvmTarget = JvmTarget.JVM_17
javaParameters = true
freeCompilerArgs = [
'-Xemit-jvm-type-annotations',
Expand Down Expand Up @@ -568,7 +568,7 @@ def verifyShadedClassAnnotations = tasks.register('verifyShadedClassAnnotations'
}

/**
* Compiles a small Java 11 consumer against only the completed shaded JAR.
* Compiles a small Java 17 consumer against only the completed shaded JAR.
* Resolving {@code ExecutionContext.getOperationDirectives()} forces javac to
* inspect the shaded ImmutableList signature; {@code -Xlint:classfile -Werror}
* turns dangling annotation references into a build failure.
Expand All @@ -583,7 +583,7 @@ def compileShadedJarConsumer = tasks.register('compileShadedJarConsumer', JavaCo
}
classpath = files(buildFinalJar.flatMap { it.archiveFile })
destinationDirectory = layout.buildDirectory.dir('classes/shaded-jar-consumer')
options.release = 11
options.release = 17
options.compilerArgs.addAll(['-Xlint:classfile', '-Werror'])
}

Expand Down Expand Up @@ -695,13 +695,13 @@ tasks.withType(GroovyCompile) {
// Options when compiling Java using the Groovy plugin.
// (Groovy itself defaults to UTF-8 for Groovy code)
options.encoding = 'UTF-8'
sourceCompatibility = '11'
targetCompatibility = '11'
sourceCompatibility = '17'
targetCompatibility = '17'
groovyOptions.forkOptions.memoryMaximumSize = "4g"
}

tasks.withType(JavaCompile) {
options.release = 11
options.release = 17
options.errorprone {
disableAllChecks = true
check("NullAway", CheckSeverity.ERROR)
Expand Down Expand Up @@ -812,21 +812,7 @@ tasks.register('testWithJava17', Test) {

}

tasks.register('testWithJava11', Test) {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(11)
}
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath

dependsOn tasks.named('testClasses')

classpath += sourceSets.jmh.output
dependsOn "jmhClasses"

}

['11', '17', '21'].each { ver ->
['17', '21'].each { ver ->
tasks.register("testngWithJava${ver}", Test) {
useTestNG()
javaLauncher = javaToolchains.launcherFor {
Expand Down
46 changes: 16 additions & 30 deletions src/test/groovy/graphql/ExecutionInputTest.groovy
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package graphql

import graphql.execution.ExecutionId
import graphql.execution.instrumentation.ExecuteObjectInstrumentationContext
import graphql.execution.instrumentation.ExecutionStrategyInstrumentationContext
import graphql.execution.instrumentation.Instrumentation
import graphql.execution.instrumentation.InstrumentationContext
import graphql.execution.instrumentation.InstrumentationState
import graphql.execution.instrumentation.SimplePerformantInstrumentation
import graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters
import graphql.execution.instrumentation.parameters.InstrumentationFieldCompleteParameters
import graphql.execution.instrumentation.parameters.InstrumentationFieldParameters
Expand Down Expand Up @@ -768,10 +770,7 @@ class ExecutionInputTest extends Specification {
}

def "without capturePartialResultsOnCancel a late cancel discards even fully gathered nested data"() {
// capture is OFF, so there is no cancellation race; the top-level 'outer' field value info
// completes quickly while its nested 'value' is still resolving. Cancelling at that point and
// then letting 'value' finish means the field values are fully gathered, but because capture
// is disabled the gathered data must be discarded and only the cancel error returned.
given:
def sdl = '''
type Query {
outer : Inner
Expand All @@ -780,44 +779,31 @@ class ExecutionInputTest extends Specification {
value : String
}
'''

CountDownLatch valueStarted = new CountDownLatch(1)
CountDownLatch valueRelease = new CountDownLatch(1)

def valueResult = new CompletableFuture<String>()
DataFetcher outerDf = { DataFetchingEnvironment env -> [:] }
DataFetcher valueDf = { DataFetchingEnvironment env ->
return CompletableFuture.supplyAsync {
valueStarted.countDown()
valueRelease.await()
return "value"
}
}
DataFetcher valueDf = { DataFetchingEnvironment env -> valueResult }
def schema = TestUtil.schema(sdl, ["Query": ["outer": outerDf], "Inner": ["value": valueDf]])
def executionInput = ExecutionInput.newExecutionInput("{ outer { value } }").build()

def fetcherMap = ["Query": ["outer": outerDf], "Inner": ["value": valueDf]]
def schema = TestUtil.schema(sdl, fetcherMap)
def graphQL = GraphQL.newGraphQL(schema).build()
// Cancel after the nested values have been gathered, before the object result is assembled.
def objectInstrumentation = Stub(ExecuteObjectInstrumentationContext) {
onFieldValuesInfo(_) >> { executionInput.cancel() }
}
def instrumentation = Spy(SimplePerformantInstrumentation) {
beginExecuteObject(_, _) >> objectInstrumentation
}
def graphQL = GraphQL.newGraphQL(schema).instrumentation(instrumentation).build()

when:
ExecutionInput executionInput = ExecutionInput.newExecutionInput()
.query("{ outer { value } }")
.build() // capturePartialResultsOnCancel NOT enabled

def cf = graphQL.executeAsync(executionInput)

// the nested value DF has started, so 'outer' field value info is already done
valueStarted.await()
// cancel while the nested value is still resolving, then let it finish
executionInput.cancel()
valueRelease.countDown()

valueResult.complete("value")
await().atMost(Duration.ofSeconds(10)).until({ -> cf.isDone() })
def er = cf.join()

then:
!cf.isCompletedExceptionally()
!er.errors.isEmpty()
er.errors[0]["message"] == "Execution has been asked to be cancelled"
// capture disabled - even though the data was fully gathered, it is discarded
er.data == null
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package graphql.schema.fetching

import graphql.Scalars
import graphql.schema.GraphQLFieldDefinition
import graphql.schema.PropertyDataFetcher
import graphql.util.javac.DynamicJavacSupport
import spock.lang.IgnoreIf
import spock.lang.Specification

class LambdaFetchingSupportTest extends Specification {
Expand Down Expand Up @@ -165,53 +160,4 @@ class LambdaFetchingSupportTest extends Specification {
!getter.isPresent()
}

GraphQLFieldDefinition fld(String fldName) {
return GraphQLFieldDefinition.newFieldDefinition().name(fldName).type(Scalars.GraphQLString).build()
}

@IgnoreIf({ System.getProperty("java.version").split('\\.')[0] as Integer > 11 })
def "different class loaders induce certain behaviours"() {
String sourceCode = '''
package com.dynamic;
public class TestClass {
public String hello() {
return "world";
}
}
'''

def customClass = new DynamicJavacSupport(null).compile("com.dynamic.TestClass", sourceCode)
def targetObject = customClass.getDeclaredConstructor().newInstance()

// show that the graphql-java classes cant access this custom loaded class
when:
LambdaFetchingSupport.class.getClassLoader().loadClass("com.dynamic.TestClass")
then:
thrown(ClassNotFoundException)

// show that reflection works
when:
def helloMethod = targetObject.getClass().getMethod("hello")
def reflectedValue = helloMethod.invoke(targetObject)
then:
reflectedValue == "world"

// without MethodHandles.privateLookupIn this will fail crossing class loaders in Java 8
// if we change to privateLookupIn - then this will start working and this test will need to be changed
when:
def getter = LambdaFetchingSupport.createGetter(customClass, "hello")
then:

// with Java 9+ we can get access to methods across class loaders
getter.isPresent()
def value = getter.get().apply(targetObject)
value == "world"

// show that a DF can be used
when:
def ageDF = PropertyDataFetcher.fetching("hello")
value = ageDF.get(fld("hello"), targetObject, { -> null })
then:
value == "world"
}
}
19 changes: 6 additions & 13 deletions test-baseline.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
{
"tests": {
"java11": {
"total": 6178,
"passed": 6122,
"failed": 0,
"errors": 0,
"skipped": 56
},
"java17": {
"total": 6178,
"total": 6177,
"passed": 6121,
"failed": 0,
"errors": 0,
"skipped": 57
"skipped": 56
},
"java21": {
"total": 6178,
"total": 6177,
"passed": 6121,
"failed": 0,
"errors": 0,
"skipped": 57
"skipped": 56
},
"java25": {
"total": 6178,
"total": 6177,
"passed": 6121,
"failed": 0,
"errors": 0,
"skipped": 57
"skipped": 56
},
"jcstress": {
"total": 32,
Expand Down
Loading