Search in sources :

Example 1 with RelationsOfSubjectDataFetcher

use of nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.RelationsOfSubjectDataFetcher in project timbuctoo by HuygensING.

the class RdfWiringFactory method getDataFetcher.

@Override
public DataFetcher getDataFetcher(FieldWiringEnvironment environment) {
    if (environment.getFieldDefinition().getDirective("passThrough") != null) {
        return DataFetchingEnvironment::getSource;
    } else if (environment.getFieldDefinition().getDirective("related") != null) {
        final Directive directive = environment.getFieldDefinition().getDirective("related");
        String source = ((StringValue) directive.getArgument("source").getValue()).getValue();
        String predicate = ((StringValue) directive.getArgument("predicate").getValue()).getValue();
        String direction = ((StringValue) directive.getArgument("direction").getValue()).getValue();
        return new CollectionFetcherWrapper(argumentsHelper, new RelationsOfSubjectDataFetcher(source, predicate, Direction.valueOf(direction)));
    } else if (environment.getFieldDefinition().getDirective("fromCollection") != null) {
        final Directive directive = environment.getFieldDefinition().getDirective("fromCollection");
        String uri = ((StringValue) directive.getArgument("uri").getValue()).getValue();
        boolean listAll = ((BooleanValue) directive.getArgument("listAll").getValue()).isValue();
        if (listAll) {
            return new CollectionFetcherWrapper(argumentsHelper, new CollectionDataFetcher(uri));
        } else {
            return lookupFetcher;
        }
    } else if (environment.getFieldDefinition().getDirective("rdf") != null) {
        final Directive directive = environment.getFieldDefinition().getDirective("rdf");
        String uri = ((StringValue) directive.getArgument("predicate").getValue()).getValue();
        Direction direction = valueOf(((StringValue) directive.getArgument("direction").getValue()).getValue());
        boolean isList = ((BooleanValue) directive.getArgument("isList").getValue()).isValue();
        boolean isObject = ((BooleanValue) directive.getArgument("isObject").getValue()).isValue();
        boolean isValue = ((BooleanValue) directive.getArgument("isValue").getValue()).isValue();
        if (isObject && isValue) {
            return new DataFetcherWrapper(argumentsHelper, isList, new UnionDataFetcher(uri, direction));
        } else {
            if (isObject) {
                return new DataFetcherWrapper(argumentsHelper, isList, new RelationDataFetcher(uri, direction));
            } else {
                return new DataFetcherWrapper(argumentsHelper, isList, new TypedLiteralDataFetcher(uri));
            }
        }
    } else if (environment.getFieldDefinition().getDirective("uri") != null) {
        return uriFetcher;
    } else if (environment.getFieldDefinition().getDirective("dataSet") != null) {
        final Directive directive = environment.getFieldDefinition().getDirective("dataSet");
        String userId = ((StringValue) directive.getArgument("userId").getValue()).getValue();
        String dataSetId = ((StringValue) directive.getArgument("dataSetId").getValue()).getValue();
        final DataSet dataSet = dataSetRepository.unsafeGetDataSetWithoutCheckingPermissions(userId, dataSetId).orElse(null);
        return dataFetchingEnvironment -> new DatabaseResult() {

            @Override
            public DataSet getDataSet() {
                return dataSet;
            }
        };
    } else if (environment.getFieldDefinition().getDirective("entityTitle") != null) {
        return entityTitleFetcher;
    } else if (environment.getFieldDefinition().getDirective("entityDescription") != null) {
        return entityDescriptionFetcher;
    } else if (environment.getFieldDefinition().getDirective("entityImage") != null) {
        return entityImageFetcher;
    }
    return null;
}
Also used : CollectionDataFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.CollectionDataFetcher) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) DatabaseResult(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DatabaseResult) RelationsOfSubjectDataFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.RelationsOfSubjectDataFetcher) TypedLiteralDataFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.TypedLiteralDataFetcher) Direction(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction) BooleanValue(graphql.language.BooleanValue) UnionDataFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.UnionDataFetcher) StringValue(graphql.language.StringValue) Directive(graphql.language.Directive) RelationDataFetcher(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.RelationDataFetcher)

Aggregations

BooleanValue (graphql.language.BooleanValue)1 Directive (graphql.language.Directive)1 StringValue (graphql.language.StringValue)1 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)1 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)1 CollectionDataFetcher (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.CollectionDataFetcher)1 RelationDataFetcher (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.RelationDataFetcher)1 RelationsOfSubjectDataFetcher (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.RelationsOfSubjectDataFetcher)1 TypedLiteralDataFetcher (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.TypedLiteralDataFetcher)1 UnionDataFetcher (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.UnionDataFetcher)1 DatabaseResult (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DatabaseResult)1