Java Code Examples for graphql.schema.DataFetchingEnvironment#getFields()

The following examples show how to use graphql.schema.DataFetchingEnvironment#getFields() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectorToFieldMask.java    From rejoiner with Apache License 2.0 6 votes vote down vote up
public static Builder getFieldMaskForProto(
    DataFetchingEnvironment environment, Descriptor descriptor, String startAtFieldName) {

  Map<String, FragmentDefinition> fragmentsByName = environment.getFragmentsByName();

  Builder maskFromSelectionBuilder = FieldMask.newBuilder();

  for (Field field : environment.getFields()) {
    for (Selection<?> selection1 : field.getSelectionSet().getSelections()) {
      if (selection1 instanceof Field) {
        Field field2 = (Field) selection1;
        if (field2.getName().equals(startAtFieldName)) {
          for (Selection<?> selection : field2.getSelectionSet().getSelections()) {
            maskFromSelectionBuilder.addAllPaths(
                getPathsForProto("", selection, descriptor, fragmentsByName));
          }
        }
      }
    }
  }
  return maskFromSelectionBuilder;
}
 
Example 2
Source File: FetchParams.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
private String extractPredicate(DataFetchingEnvironment environment) {

        final List<Field> fields = environment.getFields();
        if (fields == null || fields.isEmpty()) {
            return null;
        }
        return fields.get(0).getName();
    }