diff --git a/pom.xml b/pom.xml
index 0e14abc8..1528cd35 100644
--- a/pom.xml
+++ b/pom.xml
@@ -155,9 +155,9 @@
- org.spockframework
- spock-core
- 1.0-groovy-2.4
+ junit
+ junit
+ 4.12
test
@@ -209,7 +209,6 @@
src/test/kotlin
- src/test/groovy
@@ -240,23 +239,6 @@
-
-
- org.codehaus.gmavenplus
- gmavenplus-plugin
- 1.5
-
-
-
- generateStubs
- testGenerateStubs
- addTestSources
- testCompile
-
-
-
-
-
org.apache.maven.plugins
maven-compiler-plugin
@@ -279,7 +261,6 @@
- **/*Spec.*
**/*Test.*
diff --git a/src/test/groovy/graphql/kickstart/tools/BuiltInIdSpec.groovy b/src/test/groovy/graphql/kickstart/tools/BuiltInIdSpec.groovy
deleted file mode 100644
index a9bfb62f..00000000
--- a/src/test/groovy/graphql/kickstart/tools/BuiltInIdSpec.groovy
+++ /dev/null
@@ -1,134 +0,0 @@
-package graphql.kickstart.tools
-
-import graphql.GraphQL
-import graphql.execution.AsyncExecutionStrategy
-import graphql.schema.GraphQLSchema
-import spock.lang.Shared
-import spock.lang.Specification
-
-class BuiltInIdSpec extends Specification {
-
- @Shared
- GraphQL gql
-
- def setupSpec() {
- GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
- type Query {
- itemByLongId(id: ID!): Item1!
- itemsByLongIds(ids: [ID!]!): [Item1!]!
- itemByUuidId(id: ID!): Item2!
- itemsByUuidIds(ids: [ID!]!): [Item2!]!
- }
-
- type Item1 {
- id: ID!
- }
-
- type Item2 {
- id: ID!
- }
- '''.stripIndent())
- .resolvers(new QueryWithLongItemResolver())
- .build()
- .makeExecutableSchema()
- gql = GraphQL.newGraphQL(schema)
- .queryExecutionStrategy(new AsyncExecutionStrategy())
- .build()
- }
-
- def "supports Long as ID as input"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- itemByLongId(id: 1) {
- id
- }
- }
- '''
- }
-
- then:
- data.itemByLongId != null
- data.itemByLongId.id == "1"
- }
-
- def "supports list of Long as ID as input"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- itemsByLongIds(ids: [1,2,3]) {
- id
- }
- }
- '''
- }
-
- then:
- data.itemsByLongIds != null
- data.itemsByLongIds.size == 3
- data.itemsByLongIds[0].id == "1"
- }
-
- def "supports UUID as ID as input"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- itemByUuidId(id: "00000000-0000-0000-0000-000000000000") {
- id
- }
- }
- '''
- }
-
- then:
- data.itemByUuidId != null
- data.itemByUuidId.id == "00000000-0000-0000-0000-000000000000"
- }
-
- def "supports list of UUID as ID as input"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- itemsByUuidIds(ids: ["00000000-0000-0000-0000-000000000000","11111111-1111-1111-1111-111111111111","22222222-2222-2222-2222-222222222222"]) {
- id
- }
- }
- '''
- }
-
- then:
- data.itemsByUuidIds != null
- data.itemsByUuidIds.size == 3
- data.itemsByUuidIds[0].id == "00000000-0000-0000-0000-000000000000"
- }
-
- class QueryWithLongItemResolver implements GraphQLQueryResolver {
- Item1 itemByLongId(Long id) {
- new Item1(id: id)
- }
-
- List itemsByLongIds(List ids) {
- ids.collect { new Item1(id: it) }
- }
-
- Item2 itemByUuidId(UUID id) {
- new Item2(id: id)
- }
-
- List itemsByUuidIds(List ids) {
- ids.collect { new Item2(id: it) }
- }
- }
-
- class Item1 {
- Long id
- }
-
- class Item2 {
- UUID id
- }
-}
diff --git a/src/test/groovy/graphql/kickstart/tools/EndToEndSpec.groovy b/src/test/groovy/graphql/kickstart/tools/EndToEndSpec.groovy
deleted file mode 100644
index e654d455..00000000
--- a/src/test/groovy/graphql/kickstart/tools/EndToEndSpec.groovy
+++ /dev/null
@@ -1,653 +0,0 @@
-package graphql.kickstart.tools
-
-import graphql.ExecutionInput
-import graphql.ExecutionResult
-import graphql.GraphQL
-import graphql.execution.AsyncExecutionStrategy
-import graphql.schema.GraphQLSchema
-import org.reactivestreams.Publisher
-import org.reactivestreams.Subscriber
-import org.reactivestreams.tck.TestEnvironment
-import spock.lang.Shared
-import spock.lang.Specification
-
-import java.util.concurrent.CountDownLatch
-import java.util.concurrent.TimeUnit
-
-/**
- * @author Andrew Potter
- */
-class EndToEndSpec extends Specification {
-
- @Shared
- GraphQL gql
-
- def setupSpec() {
- GraphQLSchema schema = EndToEndSpecHelperKt.createSchema()
-
- gql = GraphQL.newGraphQL(schema)
- .queryExecutionStrategy(new AsyncExecutionStrategy())
- .build()
- }
-
- def "schema comments are used as descriptions"() {
- expect:
- gql.graphQLSchema.allTypesAsList.find { it.name == 'Type' }?.valueDefinitionMap?.TYPE_1?.description == "Item type 1"
- }
-
- def "generated schema should respond to simple queries"() {
- when:
- Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- items(itemsInput: {name: "item1"}) {
- id
- type
- }
- }
- '''
- }
-
- then:
- noExceptionThrown()
- }
-
- def "generated schema should respond to simple mutations"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql, [name: "new1", type: Type.TYPE_2.toString()]) {
- '''
- mutation addNewItem($name: String!, $type: Type!) {
- addItem(newItem: {name: $name, type: $type}) {
- id
- name
- type
- }
- }
- '''
- }
-
- then:
- data.addItem
- }
-
- def "generated schema should execute the subscription query"() {
- when:
- def newItem = new Item(1, "item", Type.TYPE_1, UUID.randomUUID(), [])
- def returnedItem = null
- def data = Utils.assertNoGraphQlErrors(gql, [:], new OnItemCreatedContext(newItem)) {
- '''
- subscription {
- onItemCreated {
- id
- }
- }
- '''
- }
- CountDownLatch latch = new CountDownLatch(1)
- (data as Publisher).subscribe(new Subscriber() {
- @Override
- void onSubscribe(org.reactivestreams.Subscription s) {
-
- }
-
- @Override
- void onNext(ExecutionResult executionResult) {
- returnedItem = executionResult.data
- latch.countDown()
- }
-
- @Override
- void onError(Throwable t) {
- }
-
- @Override
- void onComplete() {
- }
- })
- latch.await(3, TimeUnit.SECONDS)
-
- then:
- returnedItem.get("onItemCreated").id == 1
- }
-
- def "generated schema should handle interface types"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- itemsByInterface {
- name
- type
- }
- }
- '''
- }
-
- then:
- data.itemsByInterface
- }
-
- def "generated schema should handle union types"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- allItems {
- ... on Item {
- id
- name
- }
- ... on OtherItem {
- name
- type
- }
- }
- }
- '''
- }
-
- then:
- data.allItems
- }
-
- def "generated schema should handle nested union types"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- nestedUnionItems {
- ... on Item {
- itemId: id
- }
- ... on OtherItem {
- otherItemId: id
- }
- ... on ThirdItem {
- thirdItemId: id
- }
- }
- }
- '''
- }
-
- then:
- data.nestedUnionItems == [[itemId: 0], [itemId: 1], [otherItemId: 0], [otherItemId: 1], [thirdItemId: 100]]
- }
-
- def "generated schema should handle scalar types"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- itemByUUID(uuid: "38f685f1-b460-4a54-a17f-7fd69e8cf3f8") {
- uuid
- }
- }
- '''
- }
-
- then:
- data.itemByUUID
- }
-
- def "generated schema should handle non nullable scalar types"() {
- when:
- def fileParts = [new MockPart("test.doc", "Hello"), new MockPart("test.doc", "World")]
- def args = ["fileParts": fileParts]
- def data = Utils.assertNoGraphQlErrors(gql, args) {
- '''
- mutation ($fileParts: [Upload!]!) { echoFiles(fileParts: $fileParts)}
- '''
- }
- then:
- (data["echoFiles"] as ArrayList).join(",") == "Hello,World"
- }
-
- def "generated schema should handle any java.util.Map (using HashMap) types as property maps"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- propertyHashMapItems {
- name
- age
- }
- }
- '''
- }
-
- then:
- data.propertyHashMapItems == [[name: "bob", age: 55]]
- }
-
- def "generated schema should handle any java.util.Map (using SortedMap) types as property maps"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- propertySortedMapItems {
- name
- age
- }
- }
- '''
- }
-
- then:
- data.propertySortedMapItems == [[name: "Arthur", age: 76], [name: "Jane", age: 28]]
- }
-
- // In this test a dictionary entry for the schema type ComplexMapItem is defined
- // so that it is possible for a POJO mapping to be known since the ComplexMapItem is contained
- // in a property map (i.e. Map) and so the normal resolver and schema traversal code
- // will not be able to find the POJO since it does not exist as a strongly typed object in
- // resolver/POJO graph.
- def "generated schema should handle java.util.Map types as property maps when containing complex data"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- propertyMapWithComplexItems {
- nameId {
- id
- }
- age
- }
- }
- '''
- }
-
- then:
- data.propertyMapWithComplexItems == [[nameId: [id: 150], age: 72]]
- }
-
- // This behavior is consistent with PropertyDataFetcher
- def "property map returns null when a property is not defined."() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- propertyMapMissingNamePropItems {
- name
- age
- }
- }
- '''
- }
-
- then:
- data.propertyMapMissingNamePropItems == [[name: null, age: 55]]
- }
-
- // In this test a dictonary entry for the schema type NestedComplexMapItem is defined
- // however we expect to not be required to define one for the transitive UndiscoveredItem object since
- // the schema resolver discovery code should still be able to automatically determine the POJO that
- // maps to this schema type.
- def "generated schema should continue to associate resolvers for transitive types of a java.util.Map complex data type"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- propertyMapWithNestedComplexItems {
- nested {
- item {
- id
- }
- }
- age
- }
- }
- '''
- }
-
- then:
- data.propertyMapWithNestedComplexItems == [[nested: [item: [id: 63]], age: 72]]
- }
-
-
- def "generated schema should handle optional arguments"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- missing: itemsWithOptionalInput {
- id
- }
-
- present: itemsWithOptionalInput(itemsInput: {name: "item1"}) {
- id
- }
- }
- '''
- }
-
- then:
- data.missing?.size > 1
- data.present?.size == 1
- }
-
- def "generated schema should handle optional arguments using java.util.Optional"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- missing: itemsWithOptionalInputExplicit {
- id
- }
-
- present: itemsWithOptionalInputExplicit(itemsInput: {name: "item1"}) {
- id
- }
- }
- '''
- }
-
- then:
- data.missing?.size > 1
- data.present?.size == 1
- }
-
- def "generated schema should handle optional return types using java.util.Optional"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- missing: optionalItem(itemsInput: {name: "item?"}) {
- id
- }
-
- present: optionalItem(itemsInput: {name: "item1"}) {
- id
- }
- }
- '''
- }
-
- then:
- data.missing == null
- data.present
- }
-
- def "generated schema should pass default arguments"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- defaultArgument
- }
- '''
- }
-
- then:
- data.defaultArgument == true
- }
-
- def "introspection shouldn't fail for arguments of type list with a default value (defaultEnumListArgument)"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- __type(name: "Query") {
- name
- fields {
- name
- args {
- name
- defaultValue
- }
- }
- }
- }
- '''
- }
-
- then:
- data.__type
- }
-
- def "generated schema should return null without errors for null value with nested fields"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- complexNullableType {
- first
- second
- third
- }
- }
- '''
- }
-
- then:
- data.containsKey('complexNullableType')
- data.complexNullableType == null
- }
-
- def "generated schema handles nested lists in input type fields"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- complexInputType(complexInput: [[{first: "foo", second: [[{first: "bar"}]]}]])
- }
- '''
- }
-
- then:
- data.complexInputType
- }
-
- def "generated schema should use type extensions"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- extendedType {
- first
- second
- }
- }
- '''
- }
-
- then:
- data.extendedType
- data.extendedType.first
- data.extendedType.second
- }
-
- def "generated schema uses properties if no methods are found"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- propertyField
- }
- '''
- }
-
- then:
- data.propertyField
- }
-
- def "generated schema allows enums in input types"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- enumInputType(type: TYPE_2)
- }
- '''
- }
-
- then:
- data.enumInputType == "TYPE_2"
- }
-
- def "generated schema works with custom scalars as input values"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- customScalarMapInputType(customScalarMap: { test: "me" })
- }
- '''
- }
-
- then:
- data.customScalarMapInputType == [
- test: "me"
- ]
- }
-
- def "generated schema should handle extended input types"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- mutation {
- saveUser(input: {name: "John", password: "secret"})
- }
- '''
- }
-
- then:
- data.saveUser == "John/secret"
- }
-
- def "generated schema supports generic properties"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- itemWithGenericProperties {
- keys
- }
- }
- '''
- }
-
- then:
- data.itemWithGenericProperties == [
- keys: ["A", "B"]
- ]
- }
-
- def "generated schema supports overriding built-in scalars"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- itemByBuiltInId(id: "38f685f1-b460-4a54-a17f-7fd69e8cf3f8") {
- name
- }
- }
- '''
- }
-
- then:
- noExceptionThrown()
- data.itemByBuiltInId != null
- }
-
- def "generated schema supports DataFetcherResult"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- dataFetcherResult {
- name
- }
- }
- '''
- }
-
- then:
- data.dataFetcherResult.name == "item1"
- }
-
- def "generated schema supports Kotlin suspend functions"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- coroutineItems {
- id
- name
- }
- }
- '''
- }
-
- then:
- data.coroutineItems == [[id: 0, name: "item1"], [id: 1, name: "item2"]]
- }
-
- def "generated schema supports Kotlin coroutine channels for the subscription query"() {
- when:
- def newItem = new Item(1, "item", Type.TYPE_1, UUID.randomUUID(), [])
- def data = Utils.assertNoGraphQlErrors(gql, [:], new OnItemCreatedContext(newItem)) {
- '''
- subscription {
- onItemCreatedCoroutineChannel {
- id
- }
- }
- '''
- }
- def subscriber = new TestEnvironment().newManualSubscriber(data as Publisher)
-
- then:
- subscriber.requestNextElement().data.get("onItemCreatedCoroutineChannel").id == 1
- subscriber.expectCompletion()
- }
-
- def "generated schema supports Kotlin coroutine channels with suspend function for the subscription query"() {
- when:
- def newItem = new Item(1, "item", Type.TYPE_1, UUID.randomUUID(), [])
- def data = Utils.assertNoGraphQlErrors(gql, [:], new OnItemCreatedContext(newItem)) {
- '''
- subscription {
- onItemCreatedCoroutineChannelAndSuspendFunction {
- id
- }
- }
- '''
- }
- def subscriber = new TestEnvironment().newManualSubscriber(data as Publisher)
-
- then:
- subscriber.requestNextElement().data.get("onItemCreatedCoroutineChannelAndSuspendFunction").id == 1
- subscriber.expectCompletion()
- }
-
- def "generated schema supports arrays"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql) {
- '''
- {
- arrayItems {
- name
- }
- }
- '''
- }
-
- then:
- data.arrayItems.collect { it.name } == ['item1', 'item2']
- }
-
- def "generated schema should re-throw original runtime exception when executing a resolver method"() {
- when:
-
- gql.execute(ExecutionInput.newExecutionInput().query('''
- {
- throwsIllegalArgumentException
- }
- '''
- ))
-
- then:
- IllegalArgumentException
- }
-}
diff --git a/src/test/groovy/graphql/kickstart/tools/EnumDefaultValueSpec.groovy b/src/test/groovy/graphql/kickstart/tools/EnumDefaultValueSpec.groovy
deleted file mode 100644
index e9813bc2..00000000
--- a/src/test/groovy/graphql/kickstart/tools/EnumDefaultValueSpec.groovy
+++ /dev/null
@@ -1,59 +0,0 @@
-package graphql.kickstart.tools
-
-import graphql.GraphQL
-import graphql.execution.AsyncExecutionStrategy
-import graphql.schema.GraphQLSchema
-import spock.lang.Specification
-
-class EnumDefaultValueSpec extends Specification {
-
- def "enumvalue is not passed down to graphql-java"() {
- when:
- GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
- type Query {
- test(input: MySortSpecifier): SortBy
- }
- input MySortSpecifier {
- sortBy: SortBy = createdOn
- value: Int = 10
- }
- enum SortBy {
- createdOn
- updatedOn
- }
- ''').resolvers(new GraphQLQueryResolver() {
-
- SortBy test(MySortSpecifier input) {
- return input.sortBy
- }
-
- })
- .build()
- .makeExecutableSchema()
- GraphQL gql = GraphQL.newGraphQL(schema)
- .queryExecutionStrategy(new AsyncExecutionStrategy())
- .build()
- def data = Utils.assertNoGraphQlErrors(gql, [input: [value: 1]]) {
- '''
- query test($input: MySortSpecifier) {
- test(input: $input)
- }
- '''
- }
-
- then:
- noExceptionThrown()
- data.test == 'createdOn'
- }
-
- static class MySortSpecifier {
- SortBy sortBy
- int value
- }
-
- enum SortBy {
- createdOn,
- updatedOn
- }
-
-}
diff --git a/src/test/groovy/graphql/kickstart/tools/EnumListParameterSpec.groovy b/src/test/groovy/graphql/kickstart/tools/EnumListParameterSpec.groovy
deleted file mode 100644
index 0166f84c..00000000
--- a/src/test/groovy/graphql/kickstart/tools/EnumListParameterSpec.groovy
+++ /dev/null
@@ -1,76 +0,0 @@
-package graphql.kickstart.tools
-
-import graphql.GraphQL
-import graphql.execution.AsyncExecutionStrategy
-import graphql.schema.GraphQLSchema
-import spock.lang.Shared
-import spock.lang.Specification
-
-class EnumListParameterSpec extends Specification {
-
- @Shared
- GraphQL gql
-
- def setupSpec() {
- GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
- type Query {
- countries(regions: [Region!]!): [Country!]!
- }
-
- enum Region {
- EUROPE
- ASIA
- }
-
- type Country {
- code: String!
- name: String!
- regions: [Region!]
- }
- '''.stripIndent())
- .resolvers(new QueryResolver())
- .build()
- .makeExecutableSchema()
- gql = GraphQL.newGraphQL(schema)
- .queryExecutionStrategy(new AsyncExecutionStrategy())
- .build()
- }
-
- def "query with parameter type list of enums should resolve correctly"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql, [regions: ["EUROPE", "ASIA"]]) {
- '''
- query getCountries($regions: [Region!]!) {
- countries(regions: $regions){
- code
- name
- regions
- }
- }
- '''
- }
-
- then:
- data.countries == []
- }
-
- class QueryResolver implements GraphQLQueryResolver {
- Set getCountries(Set regions) {
- return Collections.emptySet()
- }
- }
-
- class Country {
- String code
- String name
- List regions
- }
-
- enum Region {
- EUROPE,
- ASIA
- }
-
-}
-
-
diff --git a/src/test/groovy/graphql/kickstart/tools/FieldResolverScannerSpec.groovy b/src/test/groovy/graphql/kickstart/tools/FieldResolverScannerSpec.groovy
deleted file mode 100644
index e2a14b89..00000000
--- a/src/test/groovy/graphql/kickstart/tools/FieldResolverScannerSpec.groovy
+++ /dev/null
@@ -1,141 +0,0 @@
-package graphql.kickstart.tools
-
-import graphql.kickstart.tools.resolver.FieldResolverError
-import graphql.kickstart.tools.resolver.FieldResolverScanner
-import graphql.kickstart.tools.resolver.MethodFieldResolver
-import graphql.kickstart.tools.resolver.PropertyFieldResolver
-import graphql.language.FieldDefinition
-import graphql.language.TypeName
-import graphql.relay.Connection
-import spock.lang.Specification
-
-/**
- * @author Andrew Potter
- */
-class FieldResolverScannerSpec extends Specification {
-
- private static final SchemaParserOptions options = SchemaParserOptions.defaultOptions()
- private static final FieldResolverScanner scanner = new FieldResolverScanner(options)
-
- def "scanner finds fields on multiple root types"() {
- setup:
- def resolver = new RootResolverInfo([new RootQuery1(), new RootQuery2()], options)
-
- when:
- def result1 = scanner.findFieldResolver(new FieldDefinition("field1", new TypeName("String")), resolver)
- def result2 = scanner.findFieldResolver(new FieldDefinition("field2", new TypeName("String")), resolver)
-
- then:
- result1.search.source != result2.search.source
- }
-
- def "scanner throws exception when more than one resolver method is found"() {
- setup:
- def resolver = new RootResolverInfo([new RootQuery1(), new DuplicateQuery()], options)
-
- when:
- scanner.findFieldResolver(new FieldDefinition("field1", new TypeName("String")), resolver)
-
- then:
- thrown(FieldResolverError)
- }
-
- def "scanner throws exception when no resolver methods are found"() {
- setup:
- def resolver = new RootResolverInfo([], options)
-
- when:
- scanner.findFieldResolver(new FieldDefinition("field1", new TypeName("String")), resolver)
-
- then:
- thrown(FieldResolverError)
- }
-
- def "scanner finds properties when no method is found"() {
- setup:
- def resolver = new RootResolverInfo([new PropertyQuery()], options)
-
- when:
- def name = scanner.findFieldResolver(new FieldDefinition("name", new TypeName("String")), resolver)
- def version = scanner.findFieldResolver(new FieldDefinition("version", new TypeName("Integer")), resolver)
-
- then:
- name instanceof PropertyFieldResolver
- version instanceof PropertyFieldResolver
- }
-
- def "scanner finds generic return type"() {
- setup:
- def resolver = new RootResolverInfo([new GenericQuery()], options)
-
- when:
- def users = scanner.findFieldResolver(new FieldDefinition("users", new TypeName("UserConnection")), resolver)
-
- then:
- users instanceof MethodFieldResolver
- }
-
- def "scanner prefers concrete resolver"() {
- setup:
- def resolver = new DataClassResolverInfo(Kayak.class)
-
- when:
- def meta = scanner.findFieldResolver(new FieldDefinition("information", new TypeName("VehicleInformation")), resolver)
-
- then:
- meta instanceof MethodFieldResolver
- ((MethodFieldResolver) meta).getMethod().getReturnType() == BoatInformation.class
- }
-
- def "scanner finds field resolver method using camelCase for snake_cased field_name"() {
- setup:
- def resolver = new RootResolverInfo([new CamelCaseQuery1()], options)
-
- when:
- def meta = scanner.findFieldResolver(new FieldDefinition("hull_type", new TypeName("HullType")), resolver)
-
- then:
- meta instanceof MethodFieldResolver
- ((MethodFieldResolver) meta).getMethod().getReturnType() == HullType.class
- }
-
- class RootQuery1 implements GraphQLQueryResolver {
- def field1() {}
- }
-
- class RootQuery2 implements GraphQLQueryResolver {
- def field2() {}
- }
-
- class DuplicateQuery implements GraphQLQueryResolver {
- def field1() {}
- }
-
- class CamelCaseQuery1 implements GraphQLQueryResolver {
- HullType getHullType(){}
- }
-
- class HullType {}
-
- class ParentPropertyQuery {
- private Integer version = 1
- }
-
- class PropertyQuery extends ParentPropertyQuery implements GraphQLQueryResolver {
- private String name = "name"
- }
-
- class User {}
-
- class GenericQuery implements GraphQLQueryResolver {
- Connection getUsers() {}
- }
-
- abstract class Boat implements Vehicle {
- BoatInformation getInformation() { return this.information; }
- }
-
- class BoatInformation implements VehicleInformation {}
-
- class Kayak extends Boat {}
-}
diff --git a/src/test/groovy/graphql/kickstart/tools/GenericResolverSpec.groovy b/src/test/groovy/graphql/kickstart/tools/GenericResolverSpec.groovy
deleted file mode 100644
index ea67500a..00000000
--- a/src/test/groovy/graphql/kickstart/tools/GenericResolverSpec.groovy
+++ /dev/null
@@ -1,84 +0,0 @@
-package graphql.kickstart.tools
-
-
-import spock.lang.Specification
-
-class GenericResolverSpec extends Specification {
-
- def "methods from generic resolvers are resolved"() {
- when:
- SchemaParser.newParser().schemaString('''\
- type Query {
- bar: Bar!
- }
-
- type Bar {
- value: String
- }
- ''')
- .resolvers(new QueryResolver1(), new BarResolver())
- .build()
- .makeExecutableSchema()
-
- then:
- noExceptionThrown()
- }
-
- class QueryResolver1 implements GraphQLQueryResolver {
- Bar getBar() {
- return new Bar()
- }
- }
-
- class Bar {
- }
-
- abstract class FooResolver implements GraphQLResolver {
- String getValue(T foo) {
- return "value"
- }
- }
-
- class BarResolver extends FooResolver implements GraphQLResolver {
-
- }
-
-
- def "methods from generic inherited resolvers are resolved"() {
- when:
- SchemaParser.newParser().schemaString('''\
- type Query {
- car: Car!
- }
- type Car {
- value: String
- }
- ''')
- .resolvers(new QueryResolver2(), new CarResolver())
- .build()
- .makeExecutableSchema()
-
- then:
- noExceptionThrown()
- }
-
-
- class QueryResolver2 implements GraphQLQueryResolver {
- Car getCar() {
- return new Car()
- }
- }
-
- abstract class FooGraphQLResolver implements GraphQLResolver {
- String getValue(T foo) {
- return "value"
- }
- }
-
- class Car {
- }
-
- class CarResolver extends FooGraphQLResolver {
-
- }
-}
diff --git a/src/test/groovy/graphql/kickstart/tools/InterfaceImplementation.groovy b/src/test/groovy/graphql/kickstart/tools/InterfaceImplementation.groovy
deleted file mode 100644
index a453f703..00000000
--- a/src/test/groovy/graphql/kickstart/tools/InterfaceImplementation.groovy
+++ /dev/null
@@ -1,11 +0,0 @@
-package graphql.kickstart.tools
-
-class InterfaceImplementation implements GraphQLQueryResolver {
- NamedResource query1() { null }
-
- NamedResourceImpl query2() { null }
-
- static class NamedResourceImpl implements NamedResource {
- String name() {}
- }
-}
diff --git a/src/test/groovy/graphql/kickstart/tools/MethodFieldResolverDataFetcherSpec.groovy b/src/test/groovy/graphql/kickstart/tools/MethodFieldResolverDataFetcherSpec.groovy
deleted file mode 100644
index c7ca1c34..00000000
--- a/src/test/groovy/graphql/kickstart/tools/MethodFieldResolverDataFetcherSpec.groovy
+++ /dev/null
@@ -1,254 +0,0 @@
-package graphql.kickstart.tools
-
-import graphql.Assert
-import graphql.ExecutionResult
-import graphql.execution.*
-import graphql.execution.instrumentation.SimpleInstrumentation
-import graphql.kickstart.tools.resolver.FieldResolverError
-import graphql.kickstart.tools.resolver.FieldResolverScanner
-import graphql.language.FieldDefinition
-import graphql.language.InputValueDefinition
-import graphql.language.NonNullType
-import graphql.language.TypeName
-import graphql.schema.DataFetcher
-import graphql.schema.DataFetchingEnvironment
-import graphql.schema.DataFetchingEnvironmentImpl
-import spock.lang.Specification
-
-import java.util.concurrent.CompletableFuture
-
-/**
- * @author Andrew Potter
- */
-class MethodFieldResolverDataFetcherSpec extends Specification {
-
- def "data fetcher throws exception if resolver has too many arguments"() {
- when:
- createFetcher("active", new GraphQLQueryResolver() {
- boolean active(def arg1, def arg2) { true }
- })
-
- then:
- thrown(FieldResolverError)
- }
-
- def "data fetcher throws exception if resolver has too few arguments"() {
- when:
- createFetcher("active", [new InputValueDefinition("doesNotExist", new TypeName("Boolean"))], new GraphQLQueryResolver() {
- boolean active() { true }
- })
-
- then:
- thrown(FieldResolverError)
- }
-
- def "data fetcher prioritizes methods on the resolver"() {
- setup:
- def name = "Resolver Name"
- def resolver = createFetcher("name", new GraphQLResolver() {
- String getName(DataClass dataClass) { name }
- })
-
- expect:
- resolver.get(createEnvironment(new DataClass())) == name
- }
-
- def "data fetcher uses data class methods if no resolver method is given"() {
- setup:
- def resolver = createFetcher("name", new GraphQLResolver() {})
-
- expect:
- resolver.get(createEnvironment(new DataClass())) == DataClass.name
- }
-
- def "data fetcher prioritizes methods without a prefix"() {
- setup:
- def name = "correct name"
- def resolver = createFetcher("name", new GraphQLResolver() {
- String name(DataClass dataClass) { name }
-
- String getName(DataClass dataClass) { "in" + name }
- })
-
- expect:
- resolver.get(createEnvironment(new DataClass())) == name
- }
-
- def "data fetcher uses 'is' prefix for booleans (primitive type)"() {
- setup:
- def resolver = createFetcher("active", new GraphQLResolver() {
- boolean isActive(DataClass dataClass) { true }
-
- boolean getActive(DataClass dataClass) { true }
- })
-
- expect:
- resolver.get(createEnvironment(new DataClass()))
- }
-
- def "data fetcher uses 'is' prefix for Booleans (Object type)"() {
- setup:
- def resolver = createFetcher("active", new GraphQLResolver() {
- Boolean isActive(DataClass dataClass) { Boolean.TRUE }
-
- Boolean getActive(DataClass dataClass) { Boolean.TRUE }
- })
-
- expect:
- resolver.get(createEnvironment(new DataClass()))
- }
-
- def "data fetcher passes environment if method has extra argument"() {
- setup:
- def resolver = createFetcher("active", new GraphQLResolver() {
- boolean isActive(DataClass dataClass, DataFetchingEnvironment env) {
- env instanceof DataFetchingEnvironment
- }
- })
-
- expect:
- resolver.get(createEnvironment(new DataClass()))
- }
-
- def "data fetcher passes environment if method has extra argument even if context is specified"() {
- setup:
- def options = SchemaParserOptions.newOptions().contextClass(ContextClass).build()
- def resolver = createFetcher(options, "active", new GraphQLResolver() {
- boolean isActive(DataClass dataClass, DataFetchingEnvironment env) {
- env instanceof DataFetchingEnvironment
- }
- })
-
- expect:
- resolver.get(createEnvironment(new ContextClass(), new DataClass()))
- }
-
- def "data fetcher passes context if method has extra argument and context is specified"() {
- setup:
- def context = new ContextClass()
- def options = SchemaParserOptions.newOptions().contextClass(ContextClass).build()
- def resolver = createFetcher(options, "active", new GraphQLResolver() {
- boolean isActive(DataClass dataClass, ContextClass ctx) {
- ctx == context
- }
- })
-
- expect:
- resolver.get(createEnvironment(context, new DataClass()))
- }
-
- def "data fetcher marshalls input object if required"() {
- setup:
- def name = "correct name"
- def resolver = createFetcher("active", [new InputValueDefinition("input", new TypeName("InputClass"))], new GraphQLQueryResolver() {
- boolean active(InputClass input) {
- input instanceof InputClass && input.name == name
- }
- })
-
- expect:
- resolver.get(createEnvironment([input: [name: name]]))
- }
-
- def "data fetcher doesn't marshall input object if not required"() {
- setup:
- def name = "correct name"
- def resolver = createFetcher("active", [new InputValueDefinition("input", new TypeName("Map"))], new GraphQLQueryResolver() {
- boolean active(Map input) {
- input instanceof Map && input.name == name
- }
- })
-
- expect:
- resolver.get(createEnvironment([input: [name: name]]))
- }
-
- def "data fetcher returns null if nullable argument is passed null"() {
- setup:
- def resolver = createFetcher("echo", [new InputValueDefinition("message", new TypeName("String"))], new GraphQLQueryResolver() {
- String echo(String message) {
- return message
- }
- })
-
- expect:
- resolver.get(createEnvironment()) == null
- }
-
- def "data fetcher throws exception if non-null argument is passed null"() {
- setup:
- def resolver = createFetcher("echo", [new InputValueDefinition("message", new NonNullType(new TypeName("String")))], new GraphQLQueryResolver() {
- String echo(String message) {
- return message
- }
- })
-
- when:
- resolver.get(createEnvironment())
-
- then:
- thrown(ResolverError)
- }
-
- private static DataFetcher createFetcher(String methodName, List arguments = [], GraphQLResolver> resolver) {
- return createFetcher(SchemaParserOptions.defaultOptions(), methodName, arguments, resolver)
- }
-
- private static DataFetcher createFetcher(SchemaParserOptions options, String methodName, List arguments = [], GraphQLResolver> resolver) {
- def field = FieldDefinition.newFieldDefinition()
- .name(methodName)
- .type(new TypeName('Boolean'))
- .inputValueDefinitions(arguments)
- .build()
-
- new FieldResolverScanner(options).findFieldResolver(field, resolver instanceof GraphQLQueryResolver ? new RootResolverInfo([resolver], options) : new NormalResolverInfo(resolver, options)).createDataFetcher()
- }
-
- private static DataFetchingEnvironment createEnvironment(Map arguments = [:]) {
- createEnvironment(new Object(), arguments)
- }
-
- private static DataFetchingEnvironment createEnvironment(Object source, Map arguments = [:]) {
- createEnvironment(null, source, arguments)
- }
-
- private static DataFetchingEnvironment createEnvironment(Object context, Object source, Map arguments = [:]) {
- DataFetchingEnvironmentImpl.newDataFetchingEnvironment(buildExecutionContext())
- .source(source)
- .arguments(arguments)
- .context(context)
- .build()
- }
-
- private static ExecutionContext buildExecutionContext() {
- ExecutionStrategy executionStrategy = new ExecutionStrategy() {
- @Override
- CompletableFuture execute(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {
- return Assert.assertShouldNeverHappen("should not be called")
- }
- }
- ExecutionId executionId = ExecutionId.from("executionId123")
- ExecutionContextBuilder.newExecutionContextBuilder()
- .instrumentation(SimpleInstrumentation.INSTANCE)
- .executionId(executionId)
- .queryStrategy(executionStrategy)
- .mutationStrategy(executionStrategy)
- .subscriptionStrategy(executionStrategy)
- .build()
- }
-
- class DataClass {
- private static final String name = "Data Class Name"
-
- String getName() {
- name
- }
- }
-
- static class InputClass {
- String name
- }
-
- class ContextClass {
- }
-}
diff --git a/src/test/groovy/graphql/kickstart/tools/MultiResolverSpec.groovy b/src/test/groovy/graphql/kickstart/tools/MultiResolverSpec.groovy
deleted file mode 100644
index 00451ac1..00000000
--- a/src/test/groovy/graphql/kickstart/tools/MultiResolverSpec.groovy
+++ /dev/null
@@ -1,80 +0,0 @@
-package graphql.kickstart.tools
-
-import graphql.GraphQL
-import graphql.execution.AsyncExecutionStrategy
-import graphql.schema.GraphQLSchema
-import spock.lang.Shared
-import spock.lang.Specification
-
-class MultiResolverSpec extends Specification {
-
- @Shared
- GraphQL gql
-
- def setupSpec() {
- GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
- type Query {
- person: Person
- }
-
- type Person {
- name: String!
- friends(friendName: String!): [Friend!]!
- }
-
- type Friend {
- name: String!
- }
- '''.stripIndent())
- .resolvers(new QueryWithPersonResolver(), new PersonFriendResolver(), new PersonNameResolver())
- .build()
- .makeExecutableSchema()
- gql = GraphQL.newGraphQL(schema)
- .queryExecutionStrategy(new AsyncExecutionStrategy())
- .build()
- }
-
- def "multiple resolvers for one data class should resolve methods with arguments"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql, [friendName: "name"]) {
- '''
- query friendOfPerson($friendName: String!) {
- person {
- friends(friendName: $friendName) {
- name
- }
- }
- }
- '''
- }
-
- then:
- data.person
- }
-
- class QueryWithPersonResolver implements GraphQLQueryResolver {
- Person getPerson() {
- new Person()
- }
- }
-
- class Person {
-
- }
-
- class Friend {
- String name
- }
-
- class PersonFriendResolver implements GraphQLResolver {
- List friends(Person person, String friendName) {
- Collections.emptyList()
- }
- }
-
- class PersonNameResolver implements GraphQLResolver {
- String name(Person person) {
- "name"
- }
- }
-}
diff --git a/src/test/groovy/graphql/kickstart/tools/MultipleInterfaces.groovy b/src/test/groovy/graphql/kickstart/tools/MultipleInterfaces.groovy
deleted file mode 100644
index 8c8783f0..00000000
--- a/src/test/groovy/graphql/kickstart/tools/MultipleInterfaces.groovy
+++ /dev/null
@@ -1,17 +0,0 @@
-package graphql.kickstart.tools
-
-class MultipleInterfaces implements GraphQLQueryResolver {
- NamedResourceImpl query1() { null }
-
- VersionedResourceImpl query2() { null }
-
- static class NamedResourceImpl implements NamedResource {
- String name() {}
- }
-
- static class VersionedResourceImpl implements VersionedResource {
- int version() {}
- }
-}
-
-
diff --git a/src/test/groovy/graphql/kickstart/tools/NamedResource.groovy b/src/test/groovy/graphql/kickstart/tools/NamedResource.groovy
deleted file mode 100644
index 0f871caf..00000000
--- a/src/test/groovy/graphql/kickstart/tools/NamedResource.groovy
+++ /dev/null
@@ -1,5 +0,0 @@
-package graphql.kickstart.tools
-
-interface NamedResource {
- String name()
-}
diff --git a/src/test/groovy/graphql/kickstart/tools/NestedInputTypesSpec.groovy b/src/test/groovy/graphql/kickstart/tools/NestedInputTypesSpec.groovy
deleted file mode 100644
index d0ce1a68..00000000
--- a/src/test/groovy/graphql/kickstart/tools/NestedInputTypesSpec.groovy
+++ /dev/null
@@ -1,127 +0,0 @@
-package graphql.kickstart.tools
-
-import graphql.GraphQL
-import graphql.execution.AsyncExecutionStrategy
-import graphql.schema.GraphQLSchema
-import spock.lang.Specification
-
-class NestedInputTypesSpec extends Specification {
-
- def "nested input types are parsed"() {
- when:
- GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
- type Query {
- materials(filter: MaterialFilter): [Material!]!
- }
-
- input MaterialFilter {
- title: String
- requestFilter: RequestFilter
- }
-
- input RequestFilter {
- and: [RequestFilter!]
- or: [RequestFilter!]
- discountTypeFilter: DiscountTypeFilter
- }
-
- input DiscountTypeFilter {
- name: String
- }
-
- type Material {
- id: ID!
- }
- ''').resolvers(new QueryResolver())
- .build()
- .makeExecutableSchema()
- GraphQL gql = GraphQL.newGraphQL(schema)
- .queryExecutionStrategy(new AsyncExecutionStrategy())
- .build()
- def data = Utils.assertNoGraphQlErrors(gql, [filter: [title: "title", requestFilter: [discountTypeFilter: [name: "discount"]]]]) {
- '''
- query materials($filter: MaterialFilter!) {
- materials(filter: $filter) {
- id
- }
- }
- '''
- }
-
- then:
- noExceptionThrown()
- data.materials == []
- }
-
- def "nested input in extensions are parsed"() {
- when:
- GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
- type Query {
- materials(filter: MaterialFilter): [Material!]!
- }
-
- input MaterialFilter {
- title: String
- }
-
- extend input MaterialFilter {
- requestFilter: RequestFilter
- }
-
- input RequestFilter {
- and: [RequestFilter!]
- or: [RequestFilter!]
- discountTypeFilter: DiscountTypeFilter
- }
-
- input DiscountTypeFilter {
- name: String
- }
-
- type Material {
- id: ID!
- }
- ''').resolvers(new QueryResolver())
- .build()
- .makeExecutableSchema()
- GraphQL gql = GraphQL.newGraphQL(schema)
- .queryExecutionStrategy(new AsyncExecutionStrategy())
- .build()
- def data = Utils.assertNoGraphQlErrors(gql, [filter: [title: "title", requestFilter: [discountTypeFilter: [name: "discount"]]]]) {
- '''
- query materials($filter: MaterialFilter!) {
- materials(filter: $filter) {
- id
- }
- }
- '''
- }
-
- then:
- noExceptionThrown()
- data.materials == []
- }
-
- class QueryResolver implements GraphQLQueryResolver {
- List materials(MaterialFilter filter) { Collections.emptyList() }
- }
-
- class Material {
- Long id
- }
-
- static class MaterialFilter {
- String title
- RequestFilter requestFilter
- }
-
- static class RequestFilter {
- List and
- List or
- DiscountTypeFilter discountTypeFilter
- }
-
- static class DiscountTypeFilter {
- String name
- }
-}
diff --git a/src/test/groovy/graphql/kickstart/tools/ParameterizedGetterSpec.groovy b/src/test/groovy/graphql/kickstart/tools/ParameterizedGetterSpec.groovy
deleted file mode 100644
index 0d5ccade..00000000
--- a/src/test/groovy/graphql/kickstart/tools/ParameterizedGetterSpec.groovy
+++ /dev/null
@@ -1,70 +0,0 @@
-package graphql.kickstart.tools
-
-import graphql.GraphQL
-import graphql.execution.AsyncExecutionStrategy
-import graphql.schema.GraphQLSchema
-import spock.lang.Shared
-import spock.lang.Specification
-
-class ParameterizedGetterSpec extends Specification {
-
- @Shared
- GraphQL gql
-
- def setupSpec() {
- GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
- type Query {
- human: Human
- }
-
- type Human {
- bestFriends: [Character!]!
- allFriends(limit: Int!): [Character!]!
- }
-
- type Character {
- name: String!
- }
- '''.stripIndent())
- .resolvers(new QueryResolver(), new HumanResolver())
- .build()
- .makeExecutableSchema()
- gql = GraphQL.newGraphQL(schema)
- .queryExecutionStrategy(new AsyncExecutionStrategy())
- .build()
- }
-
- def "parameterized query is resolved on data type instead of on its resolver"() {
- when:
- def data = Utils.assertNoGraphQlErrors(gql, [limit: 10]) {
- '''
- query allFriends($limit: Int!) {
- human {
- allFriends(limit: $limit) {
- name
- }
- }
- }
- '''
- }
-
- then:
- data.human
- }
-
- class QueryResolver implements GraphQLQueryResolver {
- Human human() { new Human() }
- }
-
- class Human {
- List allFriends(int limit) { Collections.emptyList() }
- }
-
- class HumanResolver implements GraphQLResolver {
- List bestFriends(Human human) { Collections.emptyList() }
- }
-
- class Character {
- String name
- }
-}
diff --git a/src/test/groovy/graphql/kickstart/tools/SchemaClassScannerSpec.groovy b/src/test/groovy/graphql/kickstart/tools/SchemaClassScannerSpec.groovy
deleted file mode 100644
index 876ba3c6..00000000
--- a/src/test/groovy/graphql/kickstart/tools/SchemaClassScannerSpec.groovy
+++ /dev/null
@@ -1,512 +0,0 @@
-package graphql.kickstart.tools
-
-import graphql.language.*
-import graphql.schema.Coercing
-import graphql.schema.GraphQLScalarType
-import spock.lang.Specification
-
-import java.util.concurrent.CompletableFuture
-
-/**
- * @author Andrew Potter
- */
-class SchemaClassScannerSpec extends Specification {
-
- def "scanner handles futures and immediate return types"() {
- when:
- SchemaParser.newParser()
- .resolvers(new FutureImmediateQuery())
- .schemaString("""
- type Query {
- future: Int!
- immediate: Int!
- }
- """)
- .scan()
- then:
- noExceptionThrown()
- }
-
- private class FutureImmediateQuery implements GraphQLQueryResolver {
- CompletableFuture future() {
- CompletableFuture.completedFuture(1)
- }
-
- Integer immediate() {
- 1
- }
- }
-
- def "scanner handles primitive and boxed return types"() {
- when:
- SchemaParser.newParser()
- .resolvers(new PrimitiveBoxedQuery())
- .schemaString("""
- type Query {
- primitive: Int!
- boxed: Int!
- }
- """)
- .scan()
- then:
- noExceptionThrown()
- }
-
- private class PrimitiveBoxedQuery implements GraphQLQueryResolver {
- int primitive() {
- 1
- }
-
- Integer boxed() {
- 1
- }
- }
-
- def "scanner handles different scalars with same java class"() {
- when:
- SchemaParser.newParser()
- .resolvers(new ScalarDuplicateQuery())
- .schemaString("""
- type Query {
- string: String!
- id: ID!
- }
- """)
- .scan()
-
- then:
- noExceptionThrown()
- }
-
- private class ScalarDuplicateQuery implements GraphQLQueryResolver {
- String string() { "" }
-
- String id() { "" }
- }
-
- def "scanner handles interfaces referenced by objects that aren't explicitly used"() {
- when:
- ScannedSchemaObjects objects = SchemaParser.newParser()
- .resolvers(new InterfaceMissingQuery())
- .schemaString("""
- interface Interface {
- id: ID!
- }
-
- type Query implements Interface {
- id: ID!
- }
- """)
- .scan()
-
- then:
- objects.definitions.find { it instanceof InterfaceTypeDefinition } != null
- }
-
- private class InterfaceMissingQuery implements GraphQLQueryResolver {
- String id() { "" }
- }
-
- def "scanner handles input types that reference other input types"() {
- when:
- ScannedSchemaObjects objects = SchemaParser.newParser()
- .resolvers(new MultipleInputTypeQuery())
- .schemaString("""
- input FirstInput {
- id: String!
- second: SecondInput!
- third: ThirdInput!
- }
- input SecondInput {
- id: String!
- }
- input ThirdInput {
- id: String!
- }
-
- type Query {
- test(input: FirstInput): String!
- }
- """)
- .scan()
-
- then:
- objects.definitions.findAll { it instanceof InputObjectTypeDefinition }.size() == 3
-
- }
-
- private class MultipleInputTypeQuery implements GraphQLQueryResolver {
-
- String test(FirstInput input) { "" }
-
- class FirstInput {
- String id
-
- SecondInput second() { new SecondInput() }
- ThirdInput third
- }
-
- class SecondInput {
- String id
- }
-
- class ThirdInput {
- String id
- }
- }
-
- def "scanner handles input types extensions"() {
- when:
- ScannedSchemaObjects objects = SchemaParser.newParser()
- .schemaString('''
- type Query { }
-
- type Mutation {
- save(input: UserInput!): Boolean
- }
-
- input UserInput {
- name: String
- }
-
- extend input UserInput {
- password: String
- }
- ''')
- .resolvers(
- new GraphQLMutationResolver() {
- boolean save(Map map) { true }
- },
- new GraphQLQueryResolver() {}
- )
- .scan()
-
- then:
- objects.definitions.findAll { (it.class == InputObjectTypeExtensionDefinition.class) }.size() == 1
- objects.definitions.findAll { (it.class == InputObjectTypeDefinition.class) }.size() == 1
- }
-
- def "scanner allows multiple return types for custom scalars"() {
- when:
- ScannedSchemaObjects objects = SchemaParser.newParser()
- .resolvers(new ScalarsWithMultipleTypes())
- .scalars(new GraphQLScalarType("UUID", "Test scalars with duplicate types", new Coercing() {
- @Override
- Object serialize(Object input) {
- return null
- }
-
- @Override
- Object parseValue(Object input) {
- return null
- }
-
- @Override
- Object parseLiteral(Object input) {
- return null
- }
- }))
- .schemaString("""
- scalar UUID
-
- type Query {
- first: UUID
- second: UUID
- }
- """)
- .scan()
-
- then:
- objects.definitions.findAll { it instanceof ScalarTypeDefinition }.size() == 1
- }
-
- class ScalarsWithMultipleTypes implements GraphQLQueryResolver {
- Integer first() { null }
-
- String second() { null }
- }
-
- def "scanner handles multiple interfaces that are not used as field types"() {
- when:
- ScannedSchemaObjects objects = SchemaParser.newParser()
- .resolvers(new MultipleInterfaces())
- .schemaString("""
- type Query {
- query1: NamedResourceImpl
- query2: VersionedResourceImpl
- }
-
- interface NamedResource {
- name: String!
- }
-
- interface VersionedResource {
- version: Int!
- }
-
- type NamedResourceImpl implements NamedResource {
- name: String!
- }
-
- type VersionedResourceImpl implements VersionedResource {
- version: Int!
- }
- """)
- .scan()
-
- then:
- objects.definitions.findAll { it instanceof InterfaceTypeDefinition }.size() == 2
- }
-
- def "scanner handles interface implementation that is not used as field type"() {
- when:
- ScannedSchemaObjects objects = SchemaParser.newParser()
- // uncommenting the line below makes the test succeed
- .dictionary(InterfaceImplementation.NamedResourceImpl.class)
- .resolvers(new InterfaceImplementation())
- .schemaString("""
- type Query {
- query1: NamedResource
- }
-
- interface NamedResource {
- name: String!
- }
-
- type NamedResourceImpl implements NamedResource {
- name: String!
- }
- """)
- .scan()
-
- then:
- objects.definitions.findAll { it instanceof InterfaceTypeDefinition }.size() == 1
- }
-
- def "scanner handles custom scalars when matching input types"() {
- when:
- GraphQLScalarType customMap = new GraphQLScalarType('customMap', '', new Coercing