Skip to content

Commit d639165

Browse files
andimarekbbakerman
authored andcommitted
add getField to DataFetchingEnvironment
1 parent db54f29 commit d639165

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/main/java/graphql/schema/DataFetchingEnvironment.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,34 @@ public interface DataFetchingEnvironment {
8080

8181

8282
/**
83-
* @return the list of fields currently in query context
83+
* It can happen that a query has overlapping fields which are
84+
* are querying the same data. If this is the case they get merged
85+
* together and fetched only once, but this method returns all of the Fields
86+
* from the query.
87+
*
88+
* Most of the time you probably want to use {@link #getField()}.
89+
*
90+
* Example query with more than one Field returned:
91+
*
92+
* query Foo {
93+
* bar
94+
* ...BarFragment
95+
* }
96+
*
97+
* fragment BarFragment on Query {
98+
* bar
99+
* }
100+
*
101+
*
102+
* @return the list of fields currently queried
84103
*/
85104
List<Field> getFields();
86105

106+
/**
107+
* @return returns the field which is currently queried. See also {@link #getFields()}
108+
*/
109+
Field getField();
110+
87111
/**
88112
* @return graphql type of the current field
89113
*/

src/main/java/graphql/schema/DataFetchingEnvironmentImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public List<Field> getFields() {
8383
return fields;
8484
}
8585

86+
@Override
87+
public Field getField() {
88+
return fields.get(0);
89+
}
90+
8691
@Override
8792
public GraphQLOutputType getFieldType() {
8893
return fieldType;

0 commit comments

Comments
 (0)