Skip to content

Commit 59f78b1

Browse files
committed
fix extensions
1 parent 09aa67e commit 59f78b1

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

src/main/java/graphql/annotations/AnnotationsSchemaCreator.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2016 Yurii Rashkovskii
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,6 +15,7 @@
1515
package graphql.annotations;
1616

1717
import graphql.annotations.processor.GraphQLAnnotations;
18+
import graphql.annotations.processor.typeFunctions.TypeFunction;
1819
import graphql.schema.GraphQLDirective;
1920
import graphql.schema.GraphQLSchema;
2021
import graphql.schema.GraphQLType;
@@ -70,6 +71,16 @@ public Builder additionalType(Class<?> additionalObject) {
7071
return this;
7172
}
7273

74+
public Builder typeExtension(Class<?> typeExtension) {
75+
this.graphQLAnnotations.registerTypeExtension(typeExtension);
76+
return this;
77+
}
78+
79+
public Builder typeFunction(TypeFunction typeFunction) {
80+
this.graphQLAnnotations.registerType(typeFunction);
81+
return this;
82+
}
83+
7384
public GraphQLSchema build() {
7485
assert this.queryObject != null;
7586

src/main/java/graphql/annotations/processor/retrievers/GraphQLExtensionsHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ public List<GraphQLFieldDefinition> getExtensionFields(Class<?> object, List<Str
5151
continue;
5252
}
5353
if (methodSearchAlgorithm.isFound(method)) {
54-
addExtensionField(fieldRetriever.getField(object.getTypeName(), method, container), fields, definedFields);
54+
addExtensionField(fieldRetriever.getField(object.getSimpleName(), method, container), fields, definedFields);
5555
}
5656
}
5757
for (Field field : getAllFields(aClass).values()) {
5858
if (Modifier.isStatic(field.getModifiers())) {
5959
continue;
6060
}
6161
if (fieldSearchAlgorithm.isFound(field)) {
62-
addExtensionField(fieldRetriever.getField(object.getTypeName(), field, container), fields, definedFields);
62+
addExtensionField(fieldRetriever.getField(object.getSimpleName(), field, container), fields, definedFields);
6363
}
6464
}
6565
}

src/test/java/graphql/annotations/GraphQLExtensionsTest.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2016 Yurii Rashkovskii
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,7 +28,7 @@
2828
import java.util.Map;
2929

3030
import static graphql.Scalars.GraphQLString;
31-
import static graphql.schema.GraphQLSchema.newSchema;
31+
import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema;
3232
import static org.testng.Assert.*;
3333

3434
public class GraphQLExtensionsTest {
@@ -114,13 +114,7 @@ public void fields() {
114114

115115
@Test
116116
public void values() {
117-
GraphQLAnnotations instance = new GraphQLAnnotations();
118-
instance.registerTypeExtension(TestObjectExtension.class);
119-
GraphQLObjectHandler graphQLObjectHandler = instance.getObjectHandler();
120-
GraphQLObjectType object = graphQLObjectHandler.getGraphQLType(GraphQLExtensionsTest.TestObject.class, instance.getContainer());
121-
122-
GraphQLSchema schema = newSchema().query(object).build();
123-
GraphQLSchema schemaInherited = newSchema().query(object).build();
117+
GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).typeExtension(TestObjectExtension.class).build();
124118

125119
ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{field field2 field3 field4 field5}", new GraphQLExtensionsTest.TestObject());
126120
Map<String, Object> data = result.getData();
@@ -136,7 +130,7 @@ public void testDuplicateField() {
136130
GraphQLAnnotations instance = new GraphQLAnnotations();
137131
GraphQLObjectHandler graphQLObjectHandler = instance.getObjectHandler();
138132
instance.registerTypeExtension(TestObjectExtensionInvalid.class);
139-
GraphQLAnnotationsException e = expectThrows(GraphQLAnnotationsException.class, () -> graphQLObjectHandler.getGraphQLType(TestObject.class,instance.getContainer()));
133+
GraphQLAnnotationsException e = expectThrows(GraphQLAnnotationsException.class, () -> graphQLObjectHandler.getGraphQLType(TestObject.class, instance.getContainer()));
140134
assertTrue(e.getMessage().startsWith("Duplicate field"));
141135
}
142136
}

0 commit comments

Comments
 (0)