-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathIssue938.groovy
More file actions
135 lines (117 loc) · 4.66 KB
/
Issue938.groovy
File metadata and controls
135 lines (117 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package graphql
import graphql.language.IntValue
import graphql.schema.Coercing
import graphql.schema.DataFetcher
import graphql.schema.DataFetchingEnvironment
import graphql.schema.GraphQLScalarType
import graphql.schema.idl.RuntimeWiring
import graphql.schema.idl.TypeRuntimeWiring
import graphql.validation.ValidationError
import graphql.validation.ValidationErrorType
import spock.lang.Specification
class Issue938 extends Specification {
public static GraphQLScalarType GraphQLTimestamp = GraphQLScalarType.newScalar().name("Timestamp").description("Timestamp").coercing(new Coercing() {
@Override
Object serialize(Object input) {
return input
}
@Override
Object parseValue(Object input) {
GregorianCalendar calendar = new GregorianCalendar()
BigInteger value = new BigInteger(String.valueOf(input))
calendar.setTimeInMillis(value.multiply(new BigInteger("1000")).longValue())
return calendar
}
@Override
Object parseLiteral(Object input) {
if (input == null) {
return null
}
GregorianCalendar calendar = new GregorianCalendar()
calendar.setTimeInMillis(((IntValue) input).getValue().multiply(new BigInteger("1000")).longValue())
return calendar
}
})
.build()
class UserImpl {
int id
String username
String email
}
def "938 custom scalar and variables"() {
def schemaSDL = '''
type User {
id : Int
username : String
email : String
}
type Query {
User(username : String!) : User
}
'''
def userDataFetcher = new DataFetcher() {
@Override
Object get(DataFetchingEnvironment env) {
def username = env.getArgument("username")
return new UserImpl(id: 1, username: username, email: username + '@gmail.com')
}
}
def runtimeWiring = RuntimeWiring.newRuntimeWiring()
.scalar(GraphQLTimestamp)
.type(
TypeRuntimeWiring.newTypeWiring("Query")
.dataFetcher("User", userDataFetcher)
.build())
.build()
def graphql = TestUtil.graphQL(schemaSDL, runtimeWiring).build()
when:
def input = ExecutionInput.newExecutionInput()
.query('''
query myTwoBestFriends($friendOne: String!, $friendTwo: String!) {
friendOne: User(username: $friendOne) {
id
username
email
}
friendTwo: User(username: $friendTwo) {
id
username
email
}
}
''')
.variables(["friendOne": "joeyt", "friendTwo": "rossg"])
.build()
def executionResult = graphql.execute(input)
then:
executionResult.errors.isEmpty()
executionResult.data == [friendOne:
[id: 1, username: 'joeyt', email: 'joeyt@gmail.com'],
friendTwo:
[id: 1, username: 'rossg', email: 'rossg@gmail.com']
]
when:
input = ExecutionInput.newExecutionInput()
.query('''
query myTwoBestFriends($friendOne: String!, $friendTwo: String!) {
friendOne: User(user1: $friendOne) {
id
username
email
}
friendTwo: User(username: $friendTwo) {
id
username
email
}
}
''')
.variables(["friendOne": "joeyt", "friendTwo": "rossg"])
.build()
executionResult = graphql.execute(input)
then:
executionResult.errors.size() == 2
(executionResult.errors[0] as ValidationError).validationErrorType == ValidationErrorType.MissingFieldArgument
(executionResult.errors[1] as ValidationError).validationErrorType == ValidationErrorType.UnknownArgument
}
}