|
1 | 1 | package graphql.introspection
|
2 | 2 |
|
| 3 | + |
3 | 4 | import graphql.TestUtil
|
4 | 5 | import graphql.schema.DataFetcher
|
5 | 6 | import graphql.schema.FieldCoordinates
|
@@ -438,7 +439,7 @@ class IntrospectionTest extends Specification {
|
438 | 439 |
|
439 | 440 | def "test AST printed introspection query is equivalent to original string"() {
|
440 | 441 | when:
|
441 |
| - def oldIntrospectionQuery = "\n" + |
| 442 | + def oldIntrospectionQuery = "\n" + |
442 | 443 | " query IntrospectionQuery {\n" +
|
443 | 444 | " __schema {\n" +
|
444 | 445 | " queryType { name }\n" +
|
@@ -540,12 +541,11 @@ class IntrospectionTest extends Specification {
|
540 | 541 | " }\n" +
|
541 | 542 | "\n"
|
542 | 543 |
|
543 |
| - def newIntrospectionQuery = IntrospectionQuery.INTROSPECTION_QUERY; |
| 544 | + def newIntrospectionQuery = IntrospectionQuery.INTROSPECTION_QUERY |
544 | 545 |
|
545 | 546 | then:
|
546 |
| - oldIntrospectionQuery.replaceAll("\\s+","").equals( |
547 |
| - newIntrospectionQuery.replaceAll("\\s+","") |
548 |
| - ) |
| 547 | + oldIntrospectionQuery.replaceAll("\\s+", "") == |
| 548 | + newIntrospectionQuery.replaceAll("\\s+", "") |
549 | 549 | }
|
550 | 550 |
|
551 | 551 | def "test parameterized introspection queries"() {
|
@@ -582,44 +582,66 @@ class IntrospectionTest extends Specification {
|
582 | 582 |
|
583 | 583 | def parseExecutionResult = {
|
584 | 584 | [
|
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 |
590 | 590 | ]
|
591 | 591 | }
|
592 | 592 |
|
593 | 593 | when:
|
594 |
| - def allFalseExecutionResult = graphQL.execute( |
| 594 | + def allFalseExecutionResult = graphQL.execute( |
595 | 595 | 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) |
603 | 603 | )
|
604 |
| - ) |
| 604 | + ) |
605 | 605 | 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 |
608 | 608 |
|
609 | 609 | when:
|
610 |
| - def allTrueExecutionResult = graphQL.execute( |
| 610 | + def allTrueExecutionResult = graphQL.execute( |
611 | 611 | 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) |
619 | 619 | )
|
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) |
621 | 637 | 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 |
624 | 646 | }
|
625 | 647 | }
|
0 commit comments