|
1 | 1 | package com.coxautodev.graphql.tools |
2 | 2 |
|
| 3 | +import graphql.GraphQL |
| 4 | +import graphql.execution.AsyncExecutionStrategy |
3 | 5 | import graphql.relay.Connection |
4 | 6 | import graphql.relay.DefaultConnection |
5 | 7 | import graphql.relay.Edge |
6 | 8 | import graphql.relay.SimpleListConnection |
7 | 9 | import graphql.schema.DataFetchingEnvironment |
| 10 | +import graphql.schema.GraphQLSchema |
| 11 | +import spock.lang.Shared |
8 | 12 | import spock.lang.Specification |
9 | 13 |
|
10 | 14 | class RelayConnectionSpec extends Specification { |
11 | 15 |
|
12 | 16 | def "relay connection types are compatible"() { |
13 | 17 | when: |
14 | | - SchemaParser.newParser().schemaString('''\ |
| 18 | + GraphQLSchema schema = SchemaParser.newParser().schemaString('''\ |
15 | 19 | type Query { |
16 | 20 | users(first: Int, after: String): UserConnection |
17 | 21 | otherTypes: AnotherTypeConnection |
@@ -43,34 +47,72 @@ class RelayConnectionSpec extends Specification { |
43 | 47 | } |
44 | 48 | |
45 | 49 | type AnotherType { |
46 | | - |
| 50 | + echo: String |
47 | 51 | } |
48 | 52 | ''') |
49 | 53 | .resolvers(new QueryResolver()) |
50 | 54 | .build() |
51 | 55 | .makeExecutableSchema() |
| 56 | + GraphQL gql = GraphQL.newGraphQL(schema) |
| 57 | + .queryExecutionStrategy(new AsyncExecutionStrategy()) |
| 58 | + .build() |
| 59 | + def data = Utils.assertNoGraphQlErrors(gql, [limit: 10]) { |
| 60 | + ''' |
| 61 | + query { |
| 62 | + users { |
| 63 | + edges { |
| 64 | + node { |
| 65 | + id |
| 66 | + name |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + otherTypes { |
| 71 | + edges { |
| 72 | + node { |
| 73 | + echo |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + ''' |
| 79 | + } |
52 | 80 |
|
53 | 81 | then: |
54 | 82 | noExceptionThrown() |
| 83 | + data.users.edges.size == 1 |
| 84 | + data.users.edges[0].node.id == "1" |
| 85 | + data.users.edges[0].node.name == "name" |
| 86 | + data.otherTypes.edges.size == 1 |
| 87 | + data.otherTypes.edges[0].node.echo == "echo" |
55 | 88 | } |
56 | 89 |
|
57 | 90 | static class QueryResolver implements GraphQLQueryResolver { |
58 | 91 | Connection<User> users(int first, String after, DataFetchingEnvironment env) { |
59 | | - new SimpleListConnection<User>(new ArrayList()).get(env) |
| 92 | + new SimpleListConnection<User>(new ArrayList([new User(1L, "name")])).get(env) |
60 | 93 | } |
61 | 94 |
|
62 | 95 | Connection<AnotherType> otherTypes(DataFetchingEnvironment env) { |
63 | | - new SimpleListConnection<AnotherType>(new ArrayList()).get(env) |
| 96 | + new SimpleListConnection<AnotherType>(new ArrayList([new AnotherType("echo")])).get(env) |
64 | 97 | } |
65 | 98 | } |
66 | 99 |
|
67 | 100 | static class User { |
68 | 101 | Long id |
69 | 102 | String name |
| 103 | + |
| 104 | + User(Long id, String name) { |
| 105 | + this.id = id |
| 106 | + this.name = name |
| 107 | + } |
70 | 108 | } |
71 | 109 |
|
72 | 110 | private static class AnotherType { |
| 111 | + String echo |
73 | 112 |
|
| 113 | + AnotherType(String echo) { |
| 114 | + this.echo = echo |
| 115 | + } |
74 | 116 | } |
75 | 117 |
|
76 | 118 |
|
|
0 commit comments