graphql.execution.MergedField Java Examples

The following examples show how to use graphql.execution.MergedField. 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) {

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

  Builder maskFromSelectionBuilder = FieldMask.newBuilder();
  for (Field field :
      Optional.ofNullable(environment.getMergedField())
          .map(MergedField::getFields)
          .orElse(ImmutableList.of())) {
    for (Selection<?> selection : field.getSelectionSet().getSelections()) {
      maskFromSelectionBuilder.addAllPaths(
          getPathsForProto("", selection, descriptor, fragmentsByName));
    }
  }
  return maskFromSelectionBuilder;
}
 
Example #2
Source File: SelectorToFieldMaskTest.java    From rejoiner with Apache License 2.0 6 votes vote down vote up
@Test
public void getFieldMaskForProtoShouldReturnSingleField() {
  assertThat(
          SelectorToFieldMask.getFieldMaskForProto(
                  DataFetchingEnvironmentImpl.newDataFetchingEnvironment()
                      .mergedField(
                          MergedField.newMergedField()
                              .addField(
                                  new Field(
                                      "top_level_field",
                                      new SelectionSet(ImmutableList.of(new Field("username")))))
                              .build())
                      .build(),
                 PersonOuterClass.Person.getDescriptor())
              .build())
      .isEqualTo(FieldMask.newBuilder().addPaths("username").build());
}
 
Example #3
Source File: SelectorToFieldMaskTest.java    From rejoiner with Apache License 2.0 6 votes vote down vote up
@Test
public void getFieldMaskForProtoShouldIgnoreSelectorsNotInProto() {
  assertThat(
          SelectorToFieldMask.getFieldMaskForProto(
                  DataFetchingEnvironmentImpl.newDataFetchingEnvironment()
                      .mergedField(
                          MergedField.newMergedField()
                              .addField(
                                  new Field(
                                      "top_level_field",
                                      new SelectionSet(
                                          ImmutableList.of(
                                              new Field("username"),
                                              new Field("notInPersonProto")))))
                              .build())
                      .build(),
                 PersonOuterClass.Person.getDescriptor())
              .build())
      .isEqualTo(FieldMask.newBuilder().addPaths("username").build());
}
 
Example #4
Source File: SelectorToFieldMaskTest.java    From rejoiner with Apache License 2.0 6 votes vote down vote up
@Test
public void getFieldMaskForProtoShouldReturnNestedField() {
  assertThat(
          SelectorToFieldMask.getFieldMaskForProto(
                  DataFetchingEnvironmentImpl.newDataFetchingEnvironment()
                      .mergedField(
                          MergedField.newMergedField()
                              .addField(
                                  new Field(
                                      "top_level_field",
                                      new SelectionSet(
                                          ImmutableList.of(
                                              new Field(
                                                  "birthday",
                                                  new SelectionSet(
                                                      ImmutableList.of(new Field("month"))))))))
                              .build())
                      .build(),
                 PersonOuterClass.Person.getDescriptor())
              .build())
      .isEqualTo(FieldMask.newBuilder().addPaths("birthday.month").build());
}
 
Example #5
Source File: SelectorToFieldMaskTest.java    From rejoiner with Apache License 2.0 6 votes vote down vote up
@Test
public void getFieldMaskForProtoShouldReturnMultipleNestedField() {
  assertThat(
          SelectorToFieldMask.getFieldMaskForProto(
                  DataFetchingEnvironmentImpl.newDataFetchingEnvironment()
                      .mergedField(
                          MergedField.newMergedField()
                              .addField(
                                  new Field(
                                      "top_level_field",
                                      new SelectionSet(
                                          ImmutableList.of(
                                              new Field(
                                                  "birthday",
                                                  new SelectionSet(
                                                      ImmutableList.of(
                                                          new Field("day"),
                                                          new Field("month"))))))))
                              .build())
                      .build(),
                 PersonOuterClass.Person.getDescriptor())
              .build())
      .isEqualTo(
          FieldMask.newBuilder().addPaths("birthday.day").addPaths("birthday.month").build());
}
 
Example #6
Source File: SelectorToFieldMaskTest.java    From rejoiner with Apache License 2.0 6 votes vote down vote up
@Test
public void getFieldMaskForProtoShouldFallbackToStarPathIfSubSelectorNameDoesntMatchProto() {
  assertThat(
          SelectorToFieldMask.getFieldMaskForProto(
                  DataFetchingEnvironmentImpl.newDataFetchingEnvironment()
                      .mergedField(
                          MergedField.newMergedField()
                              .addField(
                                  new Field(
                                      "top_level_field",
                                      new SelectionSet(
                                          ImmutableList.of(
                                              new Field(
                                                  "birthday",
                                                  new SelectionSet(
                                                      ImmutableList.of(new Field("unknown"))))))))
                              .build())
                      .build(),
                 PersonOuterClass.Person.getDescriptor())
              .build())
      .isEqualTo(FieldMask.newBuilder().addPaths("birthday.*").build());
}
 
Example #7
Source File: EnvironmentInjector.java    From graphql-spqr with Apache License 2.0 6 votes vote down vote up
@Override
public Object getArgumentValue(ArgumentInjectorParams params) {
    Class raw = GenericTypeReflector.erase(params.getType().getType());
    if (ResolutionEnvironment.class.isAssignableFrom(raw)) {
        return params.getResolutionEnvironment();
    }
    if (GenericTypeReflector.isSuperType(setOfStrings, params.getType().getType())) {
        return params.getResolutionEnvironment().dataFetchingEnvironment.getSelectionSet().get().keySet();
    }
    if (MergedField.class.equals(raw)) {
        return params.getResolutionEnvironment().dataFetchingEnvironment.getMergedField();
    }
    if (ValueMapper.class.isAssignableFrom(raw)) {
        return params.getResolutionEnvironment().valueMapper;
    }
    throw new IllegalArgumentException("Argument of type " + raw.getName()
            + " can not be injected via @" + GraphQLEnvironment.class.getSimpleName());
}
 
Example #8
Source File: SelectorToFieldMaskTest.java    From rejoiner with Apache License 2.0 5 votes vote down vote up
@Test
public void getFieldMaskForChildProto() {
  assertThat(
          SelectorToFieldMask.getFieldMaskForProto(
                  DataFetchingEnvironmentImpl.newDataFetchingEnvironment()
                      .mergedField(
                          MergedField.newMergedField()
                              .addField(
                                  new Field(
                                      "top_level_field", // QueryType
                                      new SelectionSet(
                                          ImmutableList.of(
                                              new Field(
                                                  "second_level_field", // RequestType
                                                  new SelectionSet(
                                                      ImmutableList.of(
                                                          new Field(
                                                              "birthday",
                                                              new SelectionSet(
                                                                  ImmutableList.of(
                                                                      new Field("month")))))))))))
                              .build())
                      .build(),
                 PersonOuterClass.Person.getDescriptor(),
                  "second_level_field")
              .build())
      .isEqualTo(FieldMask.newBuilder().addPaths("birthday.month").build());
}
 
Example #9
Source File: RelayDataFetchingEnvironmentDecorator.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@Override
public MergedField getMergedField() {
    return delegate.getMergedField();
}