Skip to content

Commit d72774a

Browse files
committed
added docs to readme
1 parent 5f8ba01 commit d72774a

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class, it will be used instead of the default constructor.
5858

5959
To have a union, you must annotate an interface with `@GraphQLUnion`. In the annotation, you must declare all the
6060
possible types of the union, and a type resolver.
61-
If no type resolver is specified, `UnionTypeResovler` is used. It follows this algorithm:
61+
If no type resolver is specified, `UnionTypeResolver` is used. It follows this algorithm:
6262
The resolver assumes the the DB entity's name is the same as the API entity's name.
6363
If so, it takes the result from the dataFetcher and decides to which
6464
API entity it should be mapped (according to the name).
@@ -166,9 +166,43 @@ You can specify a custom data fetcher for a field with `@GraphQLDataFetcher`. Th
166166
which will be used as data fetcher.
167167

168168
An instance of the data fetcher will be created. The `args` attribute on the annotation can be used to specify a list of
169-
String arguments to pass to the construcor, allowing to reuse the same class on different fields, with different parameter.
169+
String arguments to pass to the constructor, allowing to reuse the same class on different fields, with different parameter.
170170
The `firstArgIsTargetName` attribute can also be set on `@GraphQLDataFetcher` to pass the field name as a single parameter of the constructor.
171171

172+
Assuming you are using `@GraphQLDataFetcher` this way:
173+
174+
```java
175+
@GraphQLField
176+
@GraphQLDataFetcher(value = HelloWorldDataFetcher.class, args = { "arg1", "arg2" })
177+
public String getHelloWorld(){
178+
return null;
179+
}
180+
```
181+
182+
Then the class that extends from `DataFetcher.class` will get this args to two supported constructors <br>
183+
Or to a constructor that expecting String array that's way (`String[] args` or `String... args`) or for a constructor that expecting the same number of args that you send with in the annotation.<br>
184+
You get to choose which implementation you want.
185+
```java
186+
public class HelloWorldDataFetcher implements DataFetcher<String> {
187+
188+
public HelloWorldDataFetcher(String[] args){
189+
// Do something with your args
190+
}
191+
192+
// Note that you need to expect the same number of args as you send with in the annotation args
193+
public HelloWorldDataFetcher(String arg1, String arg2){
194+
// Do something with your args
195+
}
196+
197+
@Override
198+
public String get(DataFetchingEnvironment environment) {
199+
return "something";
200+
}
201+
}
202+
```
203+
204+
205+
172206
If no argument is needed and a `getInstance` method is present, this method will be called instead of the constructor.
173207

174208
## Type extensions
@@ -218,7 +252,7 @@ public class HumanExtension {
218252
Classes marked as "extensions" will actually not define a new type, but rather set new fields on the class it extends when it will be created.
219253
All GraphQL annotations can be used on extension classes.
220254

221-
Extensions are registered in GraqhQLAnnotationProcessor by using `registerTypeExtension`. Note that extensions must be registered before the type itself is requested with `getObject()` :
255+
Extensions are registered in GraphQLAnnotationProcessor by using `registerTypeExtension`. Note that extensions must be registered before the type itself is requested with `getObject()` :
222256

223257
```
224258
GraphQLAnnotationsProcessor processor = GraphQLAnnotations.getInstance();

0 commit comments

Comments
 (0)