use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.
the class CSVExportFormatterTest method testHeaderWithNonmatchingAlias.
@Test
public void testHeaderWithNonmatchingAlias() {
CSVExportFormatter formatter = new CSVExportFormatter(elide, false);
TableExport queryObj = new TableExport();
String query = "{ tableExport { edges { node { query queryType } } } }";
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
queryObj.setResultType(ResultType.CSV);
// Prepare EntityProjection
Set<Attribute> attributes = new LinkedHashSet<>();
attributes.add(Attribute.builder().type(TableExport.class).name("query").alias("foo").build());
attributes.add(Attribute.builder().type(TableExport.class).name("queryType").build());
EntityProjection projection = EntityProjection.builder().type(TableExport.class).attributes(attributes).build();
String output = formatter.preFormat(projection, queryObj);
assertEquals("\"query\",\"queryType\"", output);
}
use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.
the class CSVExportFormatterTest method testHeaderSkip.
@Test
public void testHeaderSkip() {
CSVExportFormatter formatter = new CSVExportFormatter(elide, true);
TableExport queryObj = new TableExport();
String query = "{ tableExport { edges { node { query queryType } } } }";
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
queryObj.setResultType(ResultType.CSV);
// Prepare EntityProjection
Set<Attribute> attributes = new LinkedHashSet<>();
attributes.add(Attribute.builder().type(TableExport.class).name("query").alias("query").build());
attributes.add(Attribute.builder().type(TableExport.class).name("queryType").build());
EntityProjection projection = EntityProjection.builder().type(TableExport.class).attributes(attributes).build();
String output = formatter.preFormat(projection, queryObj);
assertNull(output);
}
use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.
the class GraphQLEntityProjectionMaker method addAttributeField.
/**
* Add an attribute to an entity projection.
*
* @param attributeField graphQL field for an attribute
* @param projectionBuilder projection that is being built
*/
private void addAttributeField(Field attributeField, EntityProjectionBuilder projectionBuilder) {
Type<?> parentType = projectionBuilder.getType();
String attributeName = attributeField.getName();
String attributeAlias = attributeField.getAlias() == null ? attributeName : attributeField.getAlias();
Type<?> attributeType = entityDictionary.getType(parentType, attributeName);
if (attributeType != null) {
Attribute attribute = Attribute.builder().type(attributeType).name(attributeName).alias(attributeAlias).arguments(getArguments(attributeField, entityDictionary.getAttributeArguments(parentType, attributeName))).build();
projectionBuilder.attribute(attribute);
attributeMap.put(attributeField.getSourceLocation(), attribute);
} else {
throw new InvalidEntityBodyException(String.format("Unknown attribute field {%s.%s}.", entityDictionary.getJsonAliasFor(projectionBuilder.getType()), attributeName));
}
}
use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.
the class NodeContainer method processFetch.
@Override
public Object processFetch(Environment context) {
EntityDictionary entityDictionary = context.requestScope.getDictionary();
NonEntityDictionary nonEntityDictionary = context.nonEntityDictionary;
Type parentClass = context.parentResource.getResourceType();
String fieldName = context.field.getName();
String idFieldName = entityDictionary.getIdFieldName(parentClass);
if (entityDictionary.isAttribute(parentClass, fieldName)) {
/* fetch attribute properties */
Attribute requested = context.requestScope.getProjectionInfo().getAttributeMap().getOrDefault(context.field.getSourceLocation(), null);
Object attribute = context.parentResource.getAttribute(requested);
if (attribute != null && nonEntityDictionary.hasBinding(EntityDictionary.getType(attribute))) {
return new NonEntityContainer(attribute);
}
if (attribute instanceof Map) {
return ((Map<Object, Object>) attribute).entrySet().stream().map(MapEntryContainer::new).collect(Collectors.toList());
}
if (attribute instanceof Collection) {
Type<?> innerType = entityDictionary.getParameterizedType(parentClass, fieldName);
if (nonEntityDictionary.hasBinding(innerType)) {
return ((Collection) attribute).stream().map(NonEntityContainer::new).collect(Collectors.toList());
}
}
return attribute;
}
if (entityDictionary.isRelation(parentClass, fieldName)) {
/* fetch relationship properties */
// get the relationship from constructed projections
Relationship relationship = context.requestScope.getProjectionInfo().getRelationshipMap().getOrDefault(context.field.getSourceLocation(), null);
if (relationship == null) {
throw new BadRequestException("Relationship doesn't have projection " + context.parentResource.getTypeName() + "." + fieldName);
}
return fetchRelationship(context, relationship);
}
if (Objects.equals(idFieldName, fieldName)) {
return new DeferredId(context.parentResource);
}
throw new BadRequestException("Unrecognized object: " + fieldName + " for: " + parentClass.getName() + " in node");
}
Aggregations