Skip to content

Commit 097848a

Browse files
authored
Merge branch 'master' into schema-printer-comments
2 parents 466b0fd + a54bb43 commit 097848a

4 files changed

Lines changed: 86 additions & 39 deletions

File tree

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ dependencies {
8989
api 'com.graphql-java:java-dataloader:3.2.0'
9090
api 'org.reactivestreams:reactive-streams:' + reactiveStreamsVersion
9191
antlr 'org.antlr:antlr4:' + antlrVersion
92-
implementation 'com.google.guava:guava:32.1.1-jre'
92+
implementation 'com.google.guava:guava:32.1.2-jre'
9393
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
9494
testImplementation 'org.spockframework:spock-core:2.0-groovy-3.0'
9595
testImplementation 'org.codehaus.groovy:groovy:3.0.18'
@@ -106,10 +106,10 @@ dependencies {
106106

107107
testImplementation 'org.testng:testng:7.8.0' // use for reactive streams test inheritance
108108

109-
testImplementation 'org.openjdk.jmh:jmh-core:1.36'
110-
testAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.36'
111-
jmh 'org.openjdk.jmh:jmh-core:1.36'
112-
jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.36'
109+
testImplementation 'org.openjdk.jmh:jmh-core:1.37'
110+
testAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.37'
111+
jmh 'org.openjdk.jmh:jmh-core:1.37'
112+
jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.37'
113113
}
114114

115115
shadowJar {
@@ -124,7 +124,7 @@ shadowJar {
124124
}
125125
relocate('org.antlr.v4.runtime', 'graphql.org.antlr.v4.runtime')
126126
dependencies {
127-
include(dependency('com.google.guava:guava:32.1.1-jre'))
127+
include(dependency('com.google.guava:guava:32.1.2-jre'))
128128
include(dependency('org.antlr:antlr4-runtime:' + antlrVersion))
129129
}
130130
from "LICENSE.md"

src/main/java/graphql/execution/ValuesResolverConversion.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,17 @@ static Object valueToLiteralImpl(GraphqlFieldVisibility fieldVisibility,
6969
if (valueMode == NORMALIZED) {
7070
return assertShouldNeverHappen("can't infer normalized structure");
7171
}
72-
return ValuesResolverLegacy.valueToLiteralLegacy(
72+
Value<?> value = ValuesResolverLegacy.valueToLiteralLegacy(
7373
inputValueWithState.getValue(),
7474
type,
7575
graphqlContext,
7676
locale);
77+
//
78+
// the valueToLiteralLegacy() nominally cant know if null means never set or is set to a null value
79+
// but this code can know - its is SET to a value so, it MUST be a Null Literal
80+
// this method would assert at the end of it if inputValueWithState.isNotSet() were true
81+
//
82+
return value == null ? NullValue.of() : value;
7783
}
7884
if (inputValueWithState.isLiteral()) {
7985
return inputValueWithState.getValue();

src/test/groovy/graphql/introspection/IntrospectionTest.groovy

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package graphql.introspection
22

3+
34
import graphql.TestUtil
45
import graphql.schema.DataFetcher
56
import graphql.schema.FieldCoordinates
@@ -438,7 +439,7 @@ class IntrospectionTest extends Specification {
438439

439440
def "test AST printed introspection query is equivalent to original string"() {
440441
when:
441-
def oldIntrospectionQuery = "\n" +
442+
def oldIntrospectionQuery = "\n" +
442443
" query IntrospectionQuery {\n" +
443444
" __schema {\n" +
444445
" queryType { name }\n" +
@@ -540,12 +541,11 @@ class IntrospectionTest extends Specification {
540541
" }\n" +
541542
"\n"
542543

543-
def newIntrospectionQuery = IntrospectionQuery.INTROSPECTION_QUERY;
544+
def newIntrospectionQuery = IntrospectionQuery.INTROSPECTION_QUERY
544545

545546
then:
546-
oldIntrospectionQuery.replaceAll("\\s+","").equals(
547-
newIntrospectionQuery.replaceAll("\\s+","")
548-
)
547+
oldIntrospectionQuery.replaceAll("\\s+", "") ==
548+
newIntrospectionQuery.replaceAll("\\s+", "")
549549
}
550550

551551
def "test parameterized introspection queries"() {
@@ -582,44 +582,66 @@ class IntrospectionTest extends Specification {
582582

583583
def parseExecutionResult = {
584584
[
585-
it.data["__schema"]["types"].find{it["name"] == "Query"}["fields"].find{it["name"] == "notDeprecated"}["description"] != null, // descriptions is true
586-
it.data["__schema"]["types"].find{it["name"] == "UUID"}["specifiedByURL"] != null, // specifiedByUrl is true
587-
it.data["__schema"]["directives"].find{it["name"] == "repeatableDirective"}["isRepeatable"] != null, // directiveIsRepeatable is true
588-
it.data["__schema"]["description"] != null, // schemaDescription is true
589-
it.data["__schema"]["types"].find { it['name'] == 'InputType' }["inputFields"].find({ it["name"] == "inputField" }) != null // inputValueDeprecation is true
585+
it.data["__schema"]["types"].find { it["name"] == "Query" }["fields"].find { it["name"] == "notDeprecated" }["description"] != null, // descriptions is true
586+
it.data["__schema"]["types"].find { it["name"] == "UUID" }["specifiedByURL"] != null, // specifiedByUrl is true
587+
it.data["__schema"]["directives"].find { it["name"] == "repeatableDirective" }["isRepeatable"] != null, // directiveIsRepeatable is true
588+
it.data["__schema"]["description"] != null, // schemaDescription is true
589+
it.data["__schema"]["types"].find { it['name'] == 'InputType' }["inputFields"].find({ it["name"] == "inputField" }) != null // inputValueDeprecation is true
590590
]
591591
}
592592

593593
when:
594-
def allFalseExecutionResult = graphQL.execute(
594+
def allFalseExecutionResult = graphQL.execute(
595595
IntrospectionQueryBuilder.build(
596-
IntrospectionQueryBuilder.Options.defaultOptions()
597-
.descriptions(false)
598-
.specifiedByUrl(false)
599-
.directiveIsRepeatable(false)
600-
.schemaDescription(false)
601-
.inputValueDeprecation(false)
602-
.typeRefFragmentDepth(5)
596+
IntrospectionQueryBuilder.Options.defaultOptions()
597+
.descriptions(false)
598+
.specifiedByUrl(false)
599+
.directiveIsRepeatable(false)
600+
.schemaDescription(false)
601+
.inputValueDeprecation(false)
602+
.typeRefFragmentDepth(5)
603603
)
604-
)
604+
)
605605
then:
606-
!parseExecutionResult(allFalseExecutionResult).any()
607-
allFalseExecutionResult.data["__schema"]["types"].find{it["name"] == "Query"}["fields"].find{it["name"] == "tenDimensionalList"}["type"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"] == null // typeRefFragmentDepth is 5
606+
!parseExecutionResult(allFalseExecutionResult).any()
607+
allFalseExecutionResult.data["__schema"]["types"].find { it["name"] == "Query" }["fields"].find { it["name"] == "tenDimensionalList" }["type"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"] == null // typeRefFragmentDepth is 5
608608

609609
when:
610-
def allTrueExecutionResult = graphQL.execute(
610+
def allTrueExecutionResult = graphQL.execute(
611611
IntrospectionQueryBuilder.build(
612-
IntrospectionQueryBuilder.Options.defaultOptions()
613-
.descriptions(true)
614-
.specifiedByUrl(true)
615-
.directiveIsRepeatable(true)
616-
.schemaDescription(true)
617-
.inputValueDeprecation(true)
618-
.typeRefFragmentDepth(7)
612+
IntrospectionQueryBuilder.Options.defaultOptions()
613+
.descriptions(true)
614+
.specifiedByUrl(true)
615+
.directiveIsRepeatable(true)
616+
.schemaDescription(true)
617+
.inputValueDeprecation(true)
618+
.typeRefFragmentDepth(7)
619619
)
620-
)
620+
)
621+
then:
622+
parseExecutionResult(allTrueExecutionResult).every()
623+
allTrueExecutionResult.data["__schema"]["types"].find { it["name"] == "Query" }["fields"].find { it["name"] == "tenDimensionalList" }["type"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"] == null // typeRefFragmentDepth is 7
624+
}
625+
626+
def "issue 3285 - deprecated defaultValue on programmatic args prints AST literal as expected"() {
627+
def queryObjType = newObject().name("Query")
628+
.field(newFieldDefinition().name("f").type(GraphQLString)
629+
.argument(newArgument().name("arg").type(GraphQLString).defaultValue(null)))
630+
.build()
631+
def schema = newSchema().query(queryObjType).build()
632+
def graphQL = newGraphQL(schema).build()
633+
634+
635+
when:
636+
def executionResult = graphQL.execute(IntrospectionQuery.INTROSPECTION_QUERY)
621637
then:
622-
parseExecutionResult(allTrueExecutionResult).every()
623-
allTrueExecutionResult.data["__schema"]["types"].find{it["name"] == "Query"}["fields"].find{it["name"] == "tenDimensionalList"}["type"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"] == null // typeRefFragmentDepth is 7
638+
executionResult.errors.isEmpty()
639+
640+
def types = executionResult.data['__schema']['types'] as List
641+
def queryType = types.find { it['name'] == 'Query' }
642+
def fField = (queryType['fields'] as List)[0]
643+
def arg = (fField['args'] as List)[0]
644+
arg['name'] == "arg"
645+
arg['defaultValue'] == "null" // printed AST
624646
}
625647
}

src/test/groovy/graphql/schema/idl/SchemaPrinterTest.groovy

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,3 +2613,22 @@ input Gun {
26132613
'''
26142614
}
26152615
}
2616+
2617+
def "issue 3285 - deprecated defaultValue on programmatic args prints as expected"() {
2618+
def queryObjType = newObject().name("Query")
2619+
.field(newFieldDefinition().name("f").type(GraphQLString)
2620+
.argument(newArgument().name("arg").type(GraphQLString).defaultValue(null)))
2621+
.build()
2622+
def schema = GraphQLSchema.newSchema().query(queryObjType).build()
2623+
2624+
2625+
when:
2626+
def options = defaultOptions().includeDirectiveDefinitions(false)
2627+
def sdl = new SchemaPrinter(options).print(schema)
2628+
then:
2629+
sdl == '''type Query {
2630+
f(arg: String = null): String
2631+
}
2632+
'''
2633+
}
2634+
}

0 commit comments

Comments
 (0)