File tree Expand file tree Collapse file tree 2 files changed +83
-3
lines changed
src/test/groovy/com/coxautodev/graphql/tools Expand file tree Collapse file tree 2 files changed +83
-3
lines changed Original file line number Diff line number Diff line change 11package com.coxautodev.graphql.tools
22
3- import graphql.schema.GraphQLSchema
3+
44import spock.lang.Specification
55
66class GenericResolverSpec extends Specification {
77
88 def " methods from generic resolvers are resolved" () {
99 when :
10- GraphQLSchema schema = SchemaParser . newParser(). schemaString(''' \
10+ SchemaParser . newParser(). schemaString(''' \
1111 type Query {
1212 bar: Bar!
1313 }
@@ -21,7 +21,7 @@ class GenericResolverSpec extends Specification {
2121 .makeExecutableSchema()
2222
2323 then :
24- schema != null
24+ noExceptionThrown()
2525 }
2626
2727}
Original file line number Diff line number Diff line change 1+ package com.coxautodev.graphql.tools
2+
3+ import graphql.GraphQL
4+ import graphql.execution.AsyncExecutionStrategy
5+ import graphql.schema.GraphQLSchema
6+ import spock.lang.Shared
7+ import spock.lang.Specification
8+
9+ class MultiResolverSpec extends Specification {
10+
11+ @Shared
12+ GraphQL gql
13+
14+ def setupSpec () {
15+ GraphQLSchema schema = SchemaParser . newParser(). schemaString(''' \
16+ type Query {
17+ person: Person
18+ }
19+
20+ type Person {
21+ name: String!
22+ friends(friendName: String!): [Friend!]!
23+ }
24+
25+ type Friend {
26+ name: String!
27+ }
28+ ''' )
29+ .resolvers(new QueryWithPersonResolver (), new PersonFriendResolver (), new PersonNameResolver ())
30+ .build()
31+ .makeExecutableSchema()
32+ gql = GraphQL . newGraphQL(schema)
33+ .queryExecutionStrategy(new AsyncExecutionStrategy ())
34+ .build()
35+ }
36+
37+ def " multiple resolvers for one data class should resolve methods with arguments" () {
38+ when :
39+ def data = Utils . assertNoGraphQlErrors(gql, [friendName : " name" ]) {
40+ '''
41+ query friendOfPerson($friendName: String!) {
42+ person {
43+ friends(friendName: $friendName) {
44+ name
45+ }
46+ }
47+ }
48+ '''
49+ }
50+
51+ then :
52+ data. person
53+ }
54+ }
55+
56+ class QueryWithPersonResolver implements GraphQLQueryResolver {
57+ Person getPerson () {
58+ new Person ()
59+ }
60+ }
61+
62+ class Person {
63+
64+ }
65+
66+ class Friend {
67+ String name
68+ }
69+
70+ class PersonFriendResolver implements GraphQLResolver<Person > {
71+ List<Friend > friends (Person person , String friendName ) {
72+ Collections . emptyList()
73+ }
74+ }
75+
76+ class PersonNameResolver implements GraphQLResolver<Person > {
77+ String name (Person person ) {
78+ " name"
79+ }
80+ }
You can’t perform that action at this time.
0 commit comments