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: 9 additions & 1 deletion src/main/java/graphql/execution/ValuesResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,15 @@ private static Object valueToLiteral(GraphqlFieldVisibility fieldVisibility, Inp
if (valueMode == NORMALIZED) {
return assertShouldNeverHappen("can't infer normalized structure");
}
return valueToLiteralLegacy(inputValueWithState.getValue(), type);
Value<?> value = valueToLiteralLegacy(
inputValueWithState.getValue(),
type);
//
// the valueToLiteralLegacy() nominally cant know if null means never set or is set to a null value
// but this code can know - its is SET to a value so, it MUST be a Null Literal
// this method would assert at the end of it if inputValueWithState.isNotSet() were true
//
return value == null ? NullValue.of() : value;
}
if (inputValueWithState.isLiteral()) {
return inputValueWithState.getValue();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/graphql/util/FpKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ public static <T> Supplier<T> interThreadMemoize(Supplier<T> delegate) {
*
* @param set1 first set
* @param set2 second set
* @param <T> for two
* @return intersection set
*/
public static <T> Set<T> intersection(Set<T> set1, Set<T> set2) {
Expand Down
28 changes: 28 additions & 0 deletions src/test/groovy/graphql/introspection/IntrospectionTest.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package graphql.introspection


import graphql.TestUtil
import graphql.schema.DataFetcher
import graphql.schema.FieldCoordinates
Expand All @@ -11,6 +12,11 @@ import spock.lang.See
import spock.lang.Specification

import static graphql.GraphQL.newGraphQL
import static graphql.Scalars.GraphQLString
import static graphql.schema.GraphQLArgument.newArgument
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition
import static graphql.schema.GraphQLObjectType.newObject
import static graphql.schema.GraphQLSchema.newSchema

class IntrospectionTest extends Specification {

Expand Down Expand Up @@ -353,4 +359,26 @@ class IntrospectionTest extends Specification {
then:
queryTypeFields == [[name: "inA"], [name: "inB"], [name: "inC"]]
}

def "issue 3285 - deprecated defaultValue on programmatic args prints AST literal as expected"() {
def queryObjType = newObject().name("Query")
.field(newFieldDefinition().name("f").type(GraphQLString)
.argument(newArgument().name("arg").type(GraphQLString).defaultValue(null)))
.build()
def schema = newSchema().query(queryObjType).build()
def graphQL = newGraphQL(schema).build()


when:
def executionResult = graphQL.execute(IntrospectionQuery.INTROSPECTION_QUERY)
then:
executionResult.errors.isEmpty()

def types = executionResult.data['__schema']['types'] as List
def queryType = types.find { it['name'] == 'Query' }
def fField = (queryType['fields'] as List)[0]
def arg = (fField['args'] as List)[0]
arg['name'] == "arg"
arg['defaultValue'] == "null" // printed AST
}
}
18 changes: 18 additions & 0 deletions src/test/groovy/graphql/schema/idl/SchemaPrinterTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,24 @@ type Query {
type TestObjectB {
field: String
}
'''
}

def "issue 3285 - deprecated defaultValue on programmatic args prints as expected"() {
def queryObjType = newObject().name("Query")
.field(newFieldDefinition().name("f").type(GraphQLString)
.argument(newArgument().name("arg").type(GraphQLString).defaultValue(null)))
.build()
def schema = GraphQLSchema.newSchema().query(queryObjType).build()


when:
def options = defaultOptions().includeDirectiveDefinitions(false)
def sdl = new SchemaPrinter(options).print(schema)
then:
sdl == '''type Query {
f(arg: String = null): String
}
'''
}
}