This repository was archived by the owner on Feb 27, 2023. It is now read-only.
forked from graphql-java/graphql-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoercing.java
More file actions
66 lines (60 loc) · 2.92 KB
/
Coercing.java
File metadata and controls
66 lines (60 loc) · 2.92 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
package graphql.schema;
import graphql.PublicSpi;
/**
* The Coercing interface is used by {@link graphql.schema.GraphQLScalarType}s to parse and serialise object values.
* <p>
* There are two major responsibilities, result coercion and input coercion.
* <p>
* Result coercion is taking a value from a Java object and coercing it into the constraints of the scalar type.
* For example imagine a DateTime scalar, the result coercion would need to take an object and turn it into a
* ISO date or throw an exception if it cant.
* <p>
* Input coercion is taking a value that came in from requests variables or hard coded query literals and coercing them into a
* Java object value that is acceptable to the scalar type. Again using the DateTime example, the input coercion would try to
* parse an ISO date time object or throw an exception if it cant.
*
* See http://facebook.github.io/graphql/#sec-Scalars
*/
@PublicSpi
public interface Coercing<I, O> {
/**
* Called to convert a Java object result of a DataFetcher to a valid runtime value for the scalar type.
*
* Note : You should not allow {@link java.lang.RuntimeException}s to come out of your serialize method, but rather
* catch them and fire them as {@link graphql.schema.CoercingSerializeException} instead as per the method contract.
*
* @param dataFetcherResult is never null
*
* @return a serialized value which is never null
*
* @throws graphql.schema.CoercingSerializeException if value input can't be serialized
*/
O serialize(Object dataFetcherResult) throws CoercingSerializeException;
/**
* Called to resolve a input from a query variable into a Java object acceptable for the scalar type.
*
* Note : You should not allow {@link java.lang.RuntimeException}s to come out of your parseValue method, but rather
* catch them and fire them as {@link graphql.schema.CoercingSerializeException} instead as per the method contract.
*
* @param input is never null
*
* @return a parsed value which is never null
*
* @throws graphql.schema.CoercingParseValueException if value input can't be parsed
*/
I parseValue(Object input) throws CoercingParseValueException;
/**
* Called to convert an query input AST node into a Java object acceptable for the scalar type. The input
* object will be an instance of {@link graphql.language.Value}.
*
* Note : You should not allow {@link java.lang.RuntimeException}s to come out of your parseLiteral method, but rather
* catch them and return null as per the method contract to indicate that the AST literal cannot be parsed into this scalar.
*
* @param input is never null
*
* @return a parsed value which is never null
*
* @throws graphql.schema.CoercingParseLiteralException if input literal can't be parsed
*/
I parseLiteral(Object input) throws CoercingParseLiteralException;
}