use of org.dotwebstack.framework.core.model.ObjectField in project dotwebstack-framework by dotwebstack.
the class ObjectRequestHelper method addKeyFields.
public static void addKeyFields(final ObjectRequest objectRequest) {
var keyCriterias = objectRequest.getKeyCriterias();
keyCriterias.forEach(keyCriteria -> {
final AtomicReference<ObjectRequest> current = new AtomicReference<>(objectRequest);
var fieldPath = keyCriteria.getFieldPath();
for (int index = 0; index < fieldPath.size(); index++) {
ObjectField keyField = fieldPath.get(index);
if (index == (fieldPath.size() - 1)) {
findOrAddScalarField(current.get(), keyField);
} else {
ObjectField nextKeyField = fieldPath.get(index + 1);
current.set(findOrAddObjectRequest(current.get().getObjectFields(), keyField, nextKeyField));
}
}
});
}
use of org.dotwebstack.framework.core.model.ObjectField in project dotwebstack-framework by dotwebstack.
the class FilterValidator method validateFilterField.
private void validateFilterField(Schema schema, String objectTypeName, Map.Entry<String, FilterConfiguration> filterEntry) {
String filterFieldName = getFilterField(filterEntry);
ObjectField objectField = schema.getObjectType(objectTypeName).filter(objectType -> objectType.getFields().containsKey(filterFieldName)).map(objectType -> objectType.getField(filterFieldName)).orElseThrow(() -> invalidConfigurationException("Filter field '{}' not found in object type '{}'.", filterFieldName, objectTypeName));
var filterConfiguration = filterEntry.getValue();
if (!filterConfiguration.isCaseSensitive()) {
if (objectField.isEnumeration()) {
throw invalidConfigurationException("Filter '{}' with property 'caseSensitive' is 'false' not valid for enumerations.", filterEntry.getKey());
}
if (!Objects.equals(objectField.getType(), Scalars.GraphQLString.getName())) {
throw invalidConfigurationException("Filter '{}' with property 'caseSensitive' is 'false' not valid for type '{}'.", filterEntry.getKey(), objectField.getType());
}
}
if (FilterType.PARTIAL.equals(filterConfiguration.getType()) && !Objects.equals(objectField.getType(), Scalars.GraphQLString.getName())) {
throw invalidConfigurationException("Filter '{}' of type 'Partial' in object type '{}' doesn´t refer to a 'String' field type.", filterEntry.getKey(), objectTypeName);
}
}
use of org.dotwebstack.framework.core.model.ObjectField in project dotwebstack-framework by dotwebstack.
the class PostgresBackendLoaderTest method loadSingle_returnsMonoObject.
@Test
void loadSingle_returnsMonoObject() {
Map<String, Object> source = new HashMap<>();
source.put("a", "bbb");
RequestContext requestContext = RequestContext.builder().objectField(mock(ObjectField.class)).source(source).build();
FetchSpec fetchSpec = mock(FetchSpec.class);
when(fetchSpec.all()).thenReturn(Flux.just(Collections.emptyMap()));
DatabaseClient.GenericExecuteSpec anotherSpec = mock(DatabaseClient.GenericExecuteSpec.class);
when(anotherSpec.fetch()).thenReturn(fetchSpec);
DatabaseClient.GenericExecuteSpec spec = mock(DatabaseClient.GenericExecuteSpec.class);
when(spec.bind(anyInt(), any())).thenReturn(anotherSpec);
when(databaseClient.sql(anyString())).thenReturn(spec);
ObjectRequest objectRequest = initObjectRequest();
var res = backendLoader.loadSingle(objectRequest, requestContext);
assertThat(res, CoreMatchers.is(notNullValue()));
res.doOnNext(result -> assertTrue(result.isEmpty())).subscribe();
}
Aggregations