deprecated default value method produces bad results by bbakerman · Pull Request #3286 · graphql-java/graphql-java · GitHub
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
86 changes: 54 additions & 32 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 Down Expand Up @@ -438,7 +439,7 @@ class IntrospectionTest extends Specification {

def "test AST printed introspection query is equivalent to original string"() {
when:
def oldIntrospectionQuery = "\n" +
def oldIntrospectionQuery = "\n" +
" query IntrospectionQuery {\n" +
" __schema {\n" +
" queryType { name }\n" +
Expand Down Expand Up @@ -540,12 +541,11 @@ class IntrospectionTest extends Specification {
" }\n" +
"\n"

def newIntrospectionQuery = IntrospectionQuery.INTROSPECTION_QUERY;
def newIntrospectionQuery = IntrospectionQuery.INTROSPECTION_QUERY

then:
oldIntrospectionQuery.replaceAll("\\s+","").equals(
newIntrospectionQuery.replaceAll("\\s+","")
)
oldIntrospectionQuery.replaceAll("\\s+", "") ==
newIntrospectionQuery.replaceAll("\\s+", "")
}

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

def parseExecutionResult = {
[
it.data["__schema"]["types"].find{it["name"] == "Query"}["fields"].find{it["name"] == "notDeprecated"}["description"] != null, // descriptions is true
it.data["__schema"]["types"].find{it["name"] == "UUID"}["specifiedByURL"] != null, // specifiedByUrl is true
it.data["__schema"]["directives"].find{it["name"] == "repeatableDirective"}["isRepeatable"] != null, // directiveIsRepeatable is true
it.data["__schema"]["description"] != null, // schemaDescription is true
it.data["__schema"]["types"].find { it['name'] == 'InputType' }["inputFields"].find({ it["name"] == "inputField" }) != null // inputValueDeprecation is true
it.data["__schema"]["types"].find { it["name"] == "Query" }["fields"].find { it["name"] == "notDeprecated" }["description"] != null, // descriptions is true
it.data["__schema"]["types"].find { it["name"] == "UUID" }["specifiedByURL"] != null, // specifiedByUrl is true
it.data["__schema"]["directives"].find { it["name"] == "repeatableDirective" }["isRepeatable"] != null, // directiveIsRepeatable is true
it.data["__schema"]["description"] != null, // schemaDescription is true
it.data["__schema"]["types"].find { it['name'] == 'InputType' }["inputFields"].find({ it["name"] == "inputField" }) != null // inputValueDeprecation is true
]
}

when:
def allFalseExecutionResult = graphQL.execute(
def allFalseExecutionResult = graphQL.execute(
IntrospectionQueryBuilder.build(
IntrospectionQueryBuilder.Options.defaultOptions()
.descriptions(false)
.specifiedByUrl(false)
.directiveIsRepeatable(false)
.schemaDescription(false)
.inputValueDeprecation(false)
.typeRefFragmentDepth(5)
IntrospectionQueryBuilder.Options.defaultOptions()
.descriptions(false)
.specifiedByUrl(false)
.directiveIsRepeatable(false)
.schemaDescription(false)
.inputValueDeprecation(false)
.typeRefFragmentDepth(5)
)
)
)
then:
!parseExecutionResult(allFalseExecutionResult).any()
allFalseExecutionResult.data["__schema"]["types"].find{it["name"] == "Query"}["fields"].find{it["name"] == "tenDimensionalList"}["type"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"] == null // typeRefFragmentDepth is 5
!parseExecutionResult(allFalseExecutionResult).any()
allFalseExecutionResult.data["__schema"]["types"].find { it["name"] == "Query" }["fields"].find { it["name"] == "tenDimensionalList" }["type"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"]["ofType"] == null // typeRefFragmentDepth is 5

when:
def allTrueExecutionResult = graphQL.execute(
def allTrueExecutionResult = graphQL.execute(
IntrospectionQueryBuilder.build(
IntrospectionQueryBuilder.Options.defaultOptions()
.descriptions(true)
.specifiedByUrl(true)
.directiveIsRepeatable(true)
.schemaDescription(true)
.inputValueDeprecation(true)
.typeRefFragmentDepth(7)
IntrospectionQueryBuilder.Options.defaultOptions()
.descriptions(true)
.specifiedByUrl(true)
.directiveIsRepeatable(true)
.schemaDescription(true)
.inputValueDeprecation(true)
.typeRefFragmentDepth(7)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly just reformatting

)
)
)
then:
parseExecutionResult(allTrueExecutionResult).every()
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
}

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:
parseExecutionResult(allTrueExecutionResult).every()
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
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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test is here - the introspection AST printed value is "null" and not ""

}
}
18 changes: 18 additions & 0 deletions src/test/groovy/graphql/schema/idl/SchemaPrinterTest.groovy