Search in sources :

Example 1 with StringValue

use of graphql.language.StringValue in project graphql-java by graphql-java.

the class GraphqlAntlrToLanguage method getValue.

private Value getValue(GraphqlParser.ValueWithVariableContext ctx) {
    if (ctx.IntValue() != null) {
        IntValue intValue = new IntValue(new BigInteger(ctx.IntValue().getText()));
        newNode(intValue, ctx);
        return intValue;
    } else if (ctx.FloatValue() != null) {
        FloatValue floatValue = new FloatValue(new BigDecimal(ctx.FloatValue().getText()));
        newNode(floatValue, ctx);
        return floatValue;
    } else if (ctx.BooleanValue() != null) {
        BooleanValue booleanValue = new BooleanValue(Boolean.parseBoolean(ctx.BooleanValue().getText()));
        newNode(booleanValue, ctx);
        return booleanValue;
    } else if (ctx.NullValue() != null) {
        newNode(Null, ctx);
        return Null;
    } else if (ctx.stringValue() != null) {
        StringValue stringValue = new StringValue(quotedString(ctx.stringValue()));
        newNode(stringValue, ctx);
        return stringValue;
    } else if (ctx.enumValue() != null) {
        EnumValue enumValue = new EnumValue(ctx.enumValue().getText());
        newNode(enumValue, ctx);
        return enumValue;
    } else if (ctx.arrayValueWithVariable() != null) {
        ArrayValue arrayValue = new ArrayValue();
        newNode(arrayValue, ctx);
        for (GraphqlParser.ValueWithVariableContext valueWithVariableContext : ctx.arrayValueWithVariable().valueWithVariable()) {
            arrayValue.getValues().add(getValue(valueWithVariableContext));
        }
        return arrayValue;
    } else if (ctx.objectValueWithVariable() != null) {
        ObjectValue objectValue = new ObjectValue();
        newNode(objectValue, ctx);
        for (GraphqlParser.ObjectFieldWithVariableContext objectFieldWithVariableContext : ctx.objectValueWithVariable().objectFieldWithVariable()) {
            ObjectField objectField = new ObjectField(objectFieldWithVariableContext.name().getText(), getValue(objectFieldWithVariableContext.valueWithVariable()));
            objectValue.getObjectFields().add(objectField);
        }
        return objectValue;
    } else if (ctx.variable() != null) {
        VariableReference variableReference = new VariableReference(ctx.variable().name().getText());
        newNode(variableReference, ctx);
        return variableReference;
    }
    return Assert.assertShouldNeverHappen();
}
Also used : VariableReference(graphql.language.VariableReference) EnumValue(graphql.language.EnumValue) BigDecimal(java.math.BigDecimal) ObjectValue(graphql.language.ObjectValue) GraphqlParser(graphql.parser.antlr.GraphqlParser) BooleanValue(graphql.language.BooleanValue) ObjectField(graphql.language.ObjectField) BigInteger(java.math.BigInteger) FloatValue(graphql.language.FloatValue) StringValue(graphql.language.StringValue) IntValue(graphql.language.IntValue) ArrayValue(graphql.language.ArrayValue)

Example 2 with StringValue

use of graphql.language.StringValue in project graphql-java by graphql-java.

the class GraphqlAntlrToLanguage method getValue.

private Value getValue(GraphqlParser.ValueContext ctx) {
    if (ctx.IntValue() != null) {
        IntValue intValue = new IntValue(new BigInteger(ctx.IntValue().getText()));
        newNode(intValue, ctx);
        return intValue;
    } else if (ctx.FloatValue() != null) {
        FloatValue floatValue = new FloatValue(new BigDecimal(ctx.FloatValue().getText()));
        newNode(floatValue, ctx);
        return floatValue;
    } else if (ctx.BooleanValue() != null) {
        BooleanValue booleanValue = new BooleanValue(Boolean.parseBoolean(ctx.BooleanValue().getText()));
        newNode(booleanValue, ctx);
        return booleanValue;
    } else if (ctx.NullValue() != null) {
        newNode(Null, ctx);
        return Null;
    } else if (ctx.stringValue() != null) {
        StringValue stringValue = new StringValue(quotedString(ctx.stringValue()));
        newNode(stringValue, ctx);
        return stringValue;
    } else if (ctx.enumValue() != null) {
        EnumValue enumValue = new EnumValue(ctx.enumValue().getText());
        newNode(enumValue, ctx);
        return enumValue;
    } else if (ctx.arrayValue() != null) {
        ArrayValue arrayValue = new ArrayValue();
        newNode(arrayValue, ctx);
        for (GraphqlParser.ValueContext valueWithVariableContext : ctx.arrayValue().value()) {
            arrayValue.getValues().add(getValue(valueWithVariableContext));
        }
        return arrayValue;
    } else if (ctx.objectValue() != null) {
        ObjectValue objectValue = new ObjectValue();
        newNode(objectValue, ctx);
        for (GraphqlParser.ObjectFieldContext objectFieldContext : ctx.objectValue().objectField()) {
            ObjectField objectField = new ObjectField(objectFieldContext.name().getText(), getValue(objectFieldContext.value()));
            objectValue.getObjectFields().add(objectField);
        }
        return objectValue;
    }
    return Assert.assertShouldNeverHappen();
}
Also used : EnumValue(graphql.language.EnumValue) BigDecimal(java.math.BigDecimal) ObjectValue(graphql.language.ObjectValue) GraphqlParser(graphql.parser.antlr.GraphqlParser) BooleanValue(graphql.language.BooleanValue) ObjectField(graphql.language.ObjectField) BigInteger(java.math.BigInteger) FloatValue(graphql.language.FloatValue) StringValue(graphql.language.StringValue) IntValue(graphql.language.IntValue) ArrayValue(graphql.language.ArrayValue)

Example 3 with StringValue

use of graphql.language.StringValue in project graphql-java by graphql-java.

the class SchemaTypeChecker method checkDeprecatedDirective.

/**
 * A special check for the magic @deprecated directive
 *
 * @param errors        the list of errors
 * @param directive     the directive to check
 * @param errorSupplier the error supplier function
 */
static void checkDeprecatedDirective(List<GraphQLError> errors, Directive directive, Supplier<InvalidDeprecationDirectiveError> errorSupplier) {
    if ("deprecated".equals(directive.getName())) {
        // it can have zero args
        List<Argument> arguments = directive.getArguments();
        if (arguments.size() == 0) {
            return;
        }
        // but if has more than it must have 1 called "reason" of type StringValue
        if (arguments.size() == 1) {
            Argument arg = arguments.get(0);
            if ("reason".equals(arg.getName()) && arg.getValue() instanceof StringValue) {
                return;
            }
        }
        // not valid
        errors.add(errorSupplier.get());
    }
}
Also used : Argument(graphql.language.Argument) StringValue(graphql.language.StringValue)

Example 4 with StringValue

use of graphql.language.StringValue 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)

Example 5 with StringValue

use of graphql.language.StringValue in project graphql-java by graphql-java.

the class IntrospectionResultToSchema method createDeprecatedDirective.

private void createDeprecatedDirective(Map<String, Object> field, List<Directive> directives) {
    if ((Boolean) field.get("isDeprecated")) {
        String reason = (String) field.get("deprecationReason");
        if (reason == null) {
            // default according to spec
            reason = "No longer supported";
        }
        Argument reasonArg = new Argument("reason", new StringValue(reason));
        Directive deprecated = new Directive("deprecated", Collections.singletonList(reasonArg));
        directives.add(deprecated);
    }
}
Also used : Argument(graphql.language.Argument) StringValue(graphql.language.StringValue) Directive(graphql.language.Directive)

Aggregations

StringValue (graphql.language.StringValue)6 BooleanValue (graphql.language.BooleanValue)4 IntValue (graphql.language.IntValue)3 ObjectValue (graphql.language.ObjectValue)3 Argument (graphql.language.Argument)2 ArrayValue (graphql.language.ArrayValue)2 Directive (graphql.language.Directive)2 EnumValue (graphql.language.EnumValue)2 FloatValue (graphql.language.FloatValue)2 ObjectField (graphql.language.ObjectField)2 GraphqlParser (graphql.parser.antlr.GraphqlParser)2 BigDecimal (java.math.BigDecimal)2 BigInteger (java.math.BigInteger)2 VariableReference (graphql.language.VariableReference)1 LinkedHashMap (java.util.LinkedHashMap)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