Skip to content

Commit 34aec35

Browse files
committed
MethodDataFetcher should not swallow exceptions. Fixes Enigmatis#4
1 parent 5db558f commit 34aec35

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/main/java/graphql/annotations/MethodDataFetcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Object get(DataFetchingEnvironment environment) {
4747
}
4848
return method.invoke(environment.getSource(), args.toArray());
4949
} catch (IllegalAccessException | InvocationTargetException e) {
50-
return null;
50+
throw new RuntimeException(e);
5151
}
5252
}
5353
}
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;
16+
17+
import graphql.schema.DataFetchingEnvironment;
18+
import org.testng.annotations.Test;
19+
20+
import java.util.ArrayList;
21+
import java.util.HashMap;
22+
23+
import static org.testng.Assert.*;
24+
25+
public class MethodDataFetcherTest {
26+
27+
public class TestException extends Exception {};
28+
29+
public String method() throws TestException {
30+
throw new TestException();
31+
}
32+
@Test(expectedExceptions = RuntimeException.class)
33+
public void exceptionRethrowing() {
34+
try {
35+
MethodDataFetcher methodDataFetcher = new MethodDataFetcher(getClass().getMethod("method"));
36+
methodDataFetcher.get(new DataFetchingEnvironment(this, new HashMap<>(), null, new ArrayList<>(), null, null, null));
37+
} catch (NoSuchMethodException e) {
38+
e.printStackTrace();
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)