com.yahoo.elide.graphql.containers.NodeContainer Maven / Gradle / Ivy
/*
* Copyright 2017, Oath Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.graphql.containers;
import com.yahoo.elide.core.PersistentResource;
import com.yahoo.elide.core.dictionary.EntityDictionary;
import com.yahoo.elide.core.exceptions.BadRequestException;
import com.yahoo.elide.core.request.Attribute;
import com.yahoo.elide.core.request.Relationship;
import com.yahoo.elide.core.type.Type;
import com.yahoo.elide.graphql.DeferredId;
import com.yahoo.elide.graphql.Environment;
import com.yahoo.elide.graphql.NonEntityDictionary;
import com.yahoo.elide.graphql.PersistentResourceFetcher;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* Container for nodes.
*/
@AllArgsConstructor
public class NodeContainer implements PersistentResourceContainer, GraphQLContainer {
@Getter private final PersistentResource persistentResource;
@Override
public Object processFetch(Environment context, PersistentResourceFetcher fetcher) {
EntityDictionary entityDictionary = context.requestScope.getDictionary();
NonEntityDictionary nonEntityDictionary = fetcher.getNonEntityDictionary();
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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy