forked from graphql-java/graphql-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScalarInfo.java
More file actions
117 lines (100 loc) · 4.49 KB
/
Copy pathScalarInfo.java
File metadata and controls
117 lines (100 loc) · 4.49 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
package graphql.schema.idl;
import graphql.Scalars;
import graphql.language.ScalarTypeDefinition;
import graphql.schema.GraphQLScalarType;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Info on all the standard scalar objects provided by graphql-java
*/
public class ScalarInfo {
/**
* A list of the scalar types provided by graphql-java
*/
public static final List<GraphQLScalarType> STANDARD_SCALARS = new ArrayList<>();
/**
* A list of the built-in scalar types as defined by the graphql specification
*/
public static final List<GraphQLScalarType> GRAPHQL_SPECIFICATION_SCALARS = new ArrayList<>();
/**
* A map of scalar type definitions provided by graphql-java
*/
public static final Map<String, ScalarTypeDefinition> STANDARD_SCALAR_DEFINITIONS = new LinkedHashMap<>();
static {
GRAPHQL_SPECIFICATION_SCALARS.add(Scalars.GraphQLInt);
GRAPHQL_SPECIFICATION_SCALARS.add(Scalars.GraphQLFloat);
GRAPHQL_SPECIFICATION_SCALARS.add(Scalars.GraphQLString);
GRAPHQL_SPECIFICATION_SCALARS.add(Scalars.GraphQLBoolean);
GRAPHQL_SPECIFICATION_SCALARS.add(Scalars.GraphQLID);
STANDARD_SCALARS.add(Scalars.GraphQLInt);
STANDARD_SCALARS.add(Scalars.GraphQLFloat);
STANDARD_SCALARS.add(Scalars.GraphQLString);
STANDARD_SCALARS.add(Scalars.GraphQLBoolean);
STANDARD_SCALARS.add(Scalars.GraphQLID);
STANDARD_SCALARS.add(Scalars.GraphQLBigDecimal);
STANDARD_SCALARS.add(Scalars.GraphQLBigInteger);
STANDARD_SCALARS.add(Scalars.GraphQLByte);
STANDARD_SCALARS.add(Scalars.GraphQLChar);
STANDARD_SCALARS.add(Scalars.GraphQLShort);
STANDARD_SCALARS.add(Scalars.GraphQLLong);
}
static {
// graphql standard scalars
STANDARD_SCALAR_DEFINITIONS.put("Int", new ScalarTypeDefinition("Int"));
STANDARD_SCALAR_DEFINITIONS.put("Float", new ScalarTypeDefinition("Float"));
STANDARD_SCALAR_DEFINITIONS.put("String", new ScalarTypeDefinition("String"));
STANDARD_SCALAR_DEFINITIONS.put("Boolean", new ScalarTypeDefinition("Boolean"));
STANDARD_SCALAR_DEFINITIONS.put("ID", new ScalarTypeDefinition("ID"));
// graphql-java library extensions
STANDARD_SCALAR_DEFINITIONS.put("Long", new ScalarTypeDefinition("Long"));
STANDARD_SCALAR_DEFINITIONS.put("BigInteger", new ScalarTypeDefinition("BigInteger"));
STANDARD_SCALAR_DEFINITIONS.put("BigDecimal", new ScalarTypeDefinition("BigDecimal"));
STANDARD_SCALAR_DEFINITIONS.put("Short", new ScalarTypeDefinition("Short"));
STANDARD_SCALAR_DEFINITIONS.put("Char", new ScalarTypeDefinition("Char"));
}
/**
* Returns true if the scalar type is a standard one provided by graphql-java
*
* @param scalarType the type in question
*
* @return true if the scalar type is a graphql-java provided scalar
*/
public static boolean isStandardScalar(GraphQLScalarType scalarType) {
return inList(STANDARD_SCALARS, scalarType.getName());
}
/**
* Returns true if the scalar type is a standard one provided by graphql-java
*
* @param scalarTypeName the name of the scalar type in question
*
* @return true if the scalar type is a graphql-java provided scalar
*/
public static boolean isStandardScalar(String scalarTypeName) {
return inList(STANDARD_SCALARS, scalarTypeName);
}
/**
* Returns true if the scalar type is a scalar that is specified by the graphql specification
*
* @param scalarTypeName the name of the scalar type in question
*
* @return true if the scalar type is is specified by the graphql specification
*/
public static boolean isGraphqlSpecifiedScalar(String scalarTypeName) {
return inList(GRAPHQL_SPECIFICATION_SCALARS, scalarTypeName);
}
/**
* Returns true if the scalar type is a scalar that is specified by the graphql specification
*
* @param scalarType the type in question
*
* @return true if the scalar type is is specified by the graphql specification
*/
public static boolean isGraphqlSpecifiedScalar(GraphQLScalarType scalarType) {
return inList(GRAPHQL_SPECIFICATION_SCALARS, scalarType.getName());
}
private static boolean inList(List<GraphQLScalarType> scalarList, String scalarTypeName) {
return scalarList.stream().anyMatch(sc -> sc.getName().equals(scalarTypeName));
}
}