Skip to content

Commit 12598d0

Browse files
committed
add support for byte,short,bigInteger,bigDecimal and char
1 parent c14db62 commit 12598d0

File tree

11 files changed

+418
-0
lines changed

11 files changed

+418
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.annotations.processor.typeFunctions;
16+
17+
import graphql.Scalars;
18+
import graphql.annotations.processor.ProcessingElementsContainer;
19+
import graphql.schema.GraphQLType;
20+
21+
import java.lang.reflect.AnnotatedType;
22+
import java.math.BigDecimal;
23+
24+
public class BigDecimalFunction implements TypeFunction {
25+
@Override
26+
public String getTypeName(Class<?> aClass, AnnotatedType annotatedType) {
27+
return Scalars.GraphQLBigDecimal.getName();
28+
}
29+
30+
@Override
31+
public boolean canBuildType(Class<?> aClass, AnnotatedType annotatedType) {
32+
return aClass == BigDecimal.class;
33+
}
34+
35+
@Override
36+
public GraphQLType buildType(boolean input, Class<?> aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) {
37+
return buildType(input, aClass, annotatedType);
38+
}
39+
40+
private GraphQLType buildType(boolean inputType, Class<?> aClass, AnnotatedType annotatedType) {
41+
return Scalars.GraphQLBigDecimal;
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.annotations.processor.typeFunctions;
16+
17+
import graphql.Scalars;
18+
import graphql.annotations.processor.ProcessingElementsContainer;
19+
import graphql.schema.GraphQLType;
20+
21+
import java.lang.reflect.AnnotatedType;
22+
import java.math.BigInteger;
23+
24+
public class BigIntegerFunction implements TypeFunction {
25+
@Override
26+
public String getTypeName(Class<?> aClass, AnnotatedType annotatedType) {
27+
return Scalars.GraphQLBigInteger.getName();
28+
}
29+
30+
@Override
31+
public boolean canBuildType(Class<?> aClass, AnnotatedType annotatedType) {
32+
return aClass == BigInteger.class;
33+
}
34+
35+
@Override
36+
public GraphQLType buildType(boolean input, Class<?> aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) {
37+
return buildType(input, aClass, annotatedType);
38+
}
39+
40+
private GraphQLType buildType(boolean inputType, Class<?> aClass, AnnotatedType annotatedType) {
41+
return Scalars.GraphQLBigInteger;
42+
}
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.annotations.processor.typeFunctions;
16+
17+
import graphql.Scalars;
18+
import graphql.annotations.processor.ProcessingElementsContainer;
19+
import graphql.schema.GraphQLType;
20+
21+
import java.lang.reflect.AnnotatedType;
22+
23+
public class ByteFunction implements TypeFunction {
24+
@Override
25+
public String getTypeName(Class<?> aClass, AnnotatedType annotatedType) {
26+
return Scalars.GraphQLByte.getName();
27+
}
28+
29+
@Override
30+
public boolean canBuildType(Class<?> aClass, AnnotatedType annotatedType) {
31+
return aClass == Byte.class;
32+
}
33+
34+
@Override
35+
public GraphQLType buildType(boolean input, Class<?> aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) {
36+
return buildType(input, aClass, annotatedType);
37+
}
38+
39+
private GraphQLType buildType(boolean inputType, Class<?> aClass, AnnotatedType annotatedType) {
40+
return Scalars.GraphQLByte;
41+
}
42+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.annotations.processor.typeFunctions;
16+
17+
import graphql.Scalars;
18+
import graphql.annotations.processor.ProcessingElementsContainer;
19+
import graphql.schema.GraphQLType;
20+
21+
import java.lang.reflect.AnnotatedType;
22+
23+
public class CharFunction implements TypeFunction {
24+
25+
@Override
26+
public String getTypeName(Class<?> aClass, AnnotatedType annotatedType) {
27+
return Scalars.GraphQLChar.getName();
28+
}
29+
30+
@Override
31+
public boolean canBuildType(Class<?> aClass, AnnotatedType annotatedType) {
32+
return aClass == Character.class;
33+
}
34+
35+
@Override
36+
public GraphQLType buildType(boolean input, Class<?> aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) {
37+
return buildType(input, aClass, annotatedType);
38+
}
39+
40+
private GraphQLType buildType(boolean inputType, Class<?> aClass, AnnotatedType annotatedType) {
41+
return Scalars.GraphQLChar;
42+
}
43+
}

src/main/java/graphql/annotations/processor/typeFunctions/DefaultTypeFunction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public DefaultTypeFunction(GraphQLInputProcessor graphQLInputProcessor, GraphQLO
5555
typeFunctions.add(new FloatFunction());
5656
typeFunctions.add(new IntegerFunction());
5757
typeFunctions.add(new LongFunction());
58+
typeFunctions.add(new ByteFunction());
59+
typeFunctions.add(new ShortFunction());
60+
typeFunctions.add(new BigIntegerFunction());
61+
typeFunctions.add(new BigDecimalFunction());
62+
typeFunctions.add(new CharFunction());
5863
typeFunctions.add(new IterableFunction(DefaultTypeFunction.this));
5964
typeFunctions.add(new StreamFunction(DefaultTypeFunction.this));
6065
typeFunctions.add(new OptionalFunction(DefaultTypeFunction.this));
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.annotations.processor.typeFunctions;
16+
17+
import graphql.Scalars;
18+
import graphql.annotations.processor.ProcessingElementsContainer;
19+
import graphql.schema.GraphQLType;
20+
21+
import java.lang.reflect.AnnotatedType;
22+
23+
public class ShortFunction implements TypeFunction {
24+
@Override
25+
public String getTypeName(Class<?> aClass, AnnotatedType annotatedType) {
26+
return Scalars.GraphQLShort.getName();
27+
}
28+
29+
@Override
30+
public boolean canBuildType(Class<?> aClass, AnnotatedType annotatedType) {
31+
return aClass == Short.class;
32+
}
33+
34+
@Override
35+
public GraphQLType buildType(boolean input, Class<?> aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) {
36+
return buildType(input, aClass, annotatedType);
37+
}
38+
39+
private GraphQLType buildType(boolean inputType, Class<?> aClass, AnnotatedType annotatedType) {
40+
return Scalars.GraphQLShort;
41+
}
42+
}
43+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.annotations.processor.typeFunctions;
16+
17+
import graphql.annotations.processor.GraphQLAnnotations;
18+
import org.testng.annotations.BeforeMethod;
19+
import org.testng.annotations.Test;
20+
21+
import java.math.BigDecimal;
22+
23+
import static graphql.Scalars.GraphQLBigDecimal;
24+
import static graphql.annotations.processor.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction;
25+
import static org.testng.Assert.assertEquals;
26+
27+
public class BigDecimalFunctionTests {
28+
@BeforeMethod
29+
public void init() {
30+
GraphQLAnnotations.getInstance().getTypeRegistry().clear();
31+
}
32+
33+
@Test
34+
public void buildType_bigDecimalType_returnsGraphQLBigDecimal() {
35+
//arrange
36+
DefaultTypeFunction instance = testedDefaultTypeFunction();
37+
38+
//act+assert
39+
assertEquals(instance.buildType(BigDecimal.class, null, null), GraphQLBigDecimal);
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.annotations.processor.typeFunctions;
16+
17+
import graphql.annotations.processor.GraphQLAnnotations;
18+
import org.testng.annotations.BeforeMethod;
19+
import org.testng.annotations.Test;
20+
21+
import java.math.BigInteger;
22+
23+
import static graphql.Scalars.GraphQLBigInteger;
24+
import static graphql.annotations.processor.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction;
25+
import static org.testng.Assert.assertEquals;
26+
27+
public class BigIntegerFunctionTests {
28+
@BeforeMethod
29+
public void init() {
30+
GraphQLAnnotations.getInstance().getTypeRegistry().clear();
31+
}
32+
33+
@Test
34+
public void buildType_bigIntegerType_returnsGraphQLBigInteger() {
35+
//arrange
36+
DefaultTypeFunction instance = testedDefaultTypeFunction();
37+
38+
//act+assert
39+
assertEquals(instance.buildType(BigInteger.class, null, null), GraphQLBigInteger);
40+
}
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.annotations.processor.typeFunctions;
16+
17+
import graphql.annotations.processor.GraphQLAnnotations;
18+
import org.testng.annotations.BeforeMethod;
19+
import org.testng.annotations.Test;
20+
21+
import static graphql.Scalars.GraphQLByte;
22+
import static graphql.annotations.processor.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction;
23+
import static org.testng.Assert.assertEquals;
24+
25+
public class ByteFunctionTests {
26+
@BeforeMethod
27+
public void init() {
28+
GraphQLAnnotations.getInstance().getTypeRegistry().clear();
29+
}
30+
31+
@Test
32+
public void buildType_byteType_returnsGraphQLByte() {
33+
//arrange
34+
DefaultTypeFunction instance = testedDefaultTypeFunction();
35+
36+
//act+assert
37+
assertEquals(instance.buildType(Byte.class, null,null), GraphQLByte);
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.annotations.processor.typeFunctions;
16+
17+
import graphql.annotations.processor.GraphQLAnnotations;
18+
import org.testng.annotations.BeforeMethod;
19+
import org.testng.annotations.Test;
20+
21+
import static graphql.Scalars.GraphQLChar;
22+
import static graphql.annotations.processor.typeFunctions.DefaultTypeFunctionTestHelper.testedDefaultTypeFunction;
23+
import static org.testng.Assert.assertEquals;
24+
25+
public class CharFunctionTests {
26+
@BeforeMethod
27+
public void init() {
28+
GraphQLAnnotations.getInstance().getTypeRegistry().clear();
29+
}
30+
31+
@Test
32+
public void buildType_characterType_returnsGraphQLChar() {
33+
//arrange
34+
DefaultTypeFunction instance = testedDefaultTypeFunction();
35+
36+
//act+assert
37+
assertEquals(instance.buildType(Character.class, null, null), GraphQLChar);
38+
}
39+
}

0 commit comments

Comments
 (0)