Search in sources :

Example 6 with GraphQLArgument

use of graphql.schema.GraphQLArgument in project graphql-java by graphql-java.

the class DirectivesUtil method directiveWithArg.

public static Optional<GraphQLArgument> directiveWithArg(List<GraphQLDirective> directiveList, String directiveName, String argumentName) {
    GraphQLDirective directive = directivesByName(directiveList).get(directiveName);
    GraphQLArgument argument = null;
    if (directive != null) {
        argument = directive.getArgument(argumentName);
    }
    return Optional.ofNullable(argument);
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument) GraphQLDirective(graphql.schema.GraphQLDirective)

Example 7 with GraphQLArgument

use of graphql.schema.GraphQLArgument in project admin-console-beta by connexta.

the class GraphQLTransformOutput method fieldToGraphQLFieldDefinition.

public GraphQLFieldDefinition fieldToGraphQLFieldDefinition(Field field) {
    List<GraphQLArgument> graphQLArgs = new ArrayList<>();
    DataType returnType;
    if (field instanceof FunctionField) {
        FunctionField function = (FunctionField) field;
        if (function.getArguments() != null) {
            function.getArguments().forEach(f -> graphQLArgs.add(fieldToGraphQLArgument((DataType) f)));
        }
        returnType = function.getReturnType();
    } else {
        returnType = (DataType) field;
    }
    return GraphQLFieldDefinition.newFieldDefinition().name(field.fieldName()).description(field.description()).type(fieldToGraphQLOutputType(returnType)).argument(graphQLArgs).dataFetcher(field instanceof FunctionField ? (env -> functionDataFetcher(env, (FunctionField) field)) : (env -> dataTypeDataFetcher(env, (DataType) field))).build();
}
Also used : FunctionField(org.codice.ddf.admin.api.fields.FunctionField) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) Arrays(java.util.Arrays) GraphQLScalarType(graphql.schema.GraphQLScalarType) LoggerFactory(org.slf4j.LoggerFactory) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) HashMap(java.util.HashMap) GraphQLUnionType(graphql.schema.GraphQLUnionType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Scalars(graphql.Scalars) Lists(com.google.common.collect.Lists) FIELD_TYPE_NAME_KEY(org.codice.ddf.admin.api.fields.UnionField.FIELD_TYPE_NAME_KEY) EnumField(org.codice.ddf.admin.api.fields.EnumField) FunctionReport(org.codice.ddf.admin.api.report.FunctionReport) Map(java.util.Map) FunctionField(org.codice.ddf.admin.api.fields.FunctionField) TypeResolver(graphql.schema.TypeResolver) GraphQLTransformCommons.capitalize(org.codice.ddf.admin.graphql.common.GraphQLTransformCommons.capitalize) UnionField(org.codice.ddf.admin.api.fields.UnionField) DataType(org.codice.ddf.admin.api.DataType) GraphQLObjectType(graphql.schema.GraphQLObjectType) Field(org.codice.ddf.admin.api.Field) Logger(org.slf4j.Logger) ObjectField(org.codice.ddf.admin.api.fields.ObjectField) GraphQLNonNull(graphql.schema.GraphQLNonNull) Set(java.util.Set) GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLOutputType(graphql.schema.GraphQLOutputType) Collectors(java.util.stream.Collectors) GraphQLArgument(graphql.schema.GraphQLArgument) List(java.util.List) GraphQLList(graphql.schema.GraphQLList) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) ListField(org.codice.ddf.admin.api.fields.ListField) Optional(java.util.Optional) FieldProvider(org.codice.ddf.admin.api.FieldProvider) ArrayList(java.util.ArrayList) DataType(org.codice.ddf.admin.api.DataType) GraphQLArgument(graphql.schema.GraphQLArgument)

Example 8 with GraphQLArgument

use of graphql.schema.GraphQLArgument in project graphql-java by graphql-java.

the class SchemaPrinter method directiveString.

private String directiveString(GraphQLDirective directive) {
    StringBuilder sb = new StringBuilder();
    sb.append("@").append(directive.getName());
    List<GraphQLArgument> args = directive.getArguments();
    args = args.stream().sorted(Comparator.comparing(GraphQLArgument::getName)).collect(toList());
    if (!args.isEmpty()) {
        sb.append("(");
        for (int i = 0; i < args.size(); i++) {
            GraphQLArgument arg = args.get(i);
            sb.append(arg.getName());
            if (arg.getDefaultValue() != null) {
                sb.append(" : ");
                sb.append(printAst(arg.getDefaultValue(), arg.getType()));
            }
            if (i < args.size() - 1) {
                sb.append(", ");
            }
        }
        sb.append(")");
    }
    return sb.toString();
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument)

Example 9 with GraphQLArgument

use of graphql.schema.GraphQLArgument in project graphql-java by graphql-java.

the class SchemaPrinter method argsString.

String argsString(List<GraphQLArgument> arguments) {
    boolean hasDescriptions = arguments.stream().filter(arg -> !isNullOrEmpty(arg.getDescription())).count() > 0;
    String prefix = hasDescriptions ? "  " : "";
    int count = 0;
    StringBuilder sb = new StringBuilder();
    arguments = arguments.stream().sorted(Comparator.comparing(GraphQLArgument::getName)).collect(toList());
    for (GraphQLArgument argument : arguments) {
        if (count == 0) {
            sb.append("(");
        } else {
            sb.append(", ");
        }
        if (hasDescriptions) {
            sb.append("\n");
        }
        String description = argument.getDescription();
        if (!isNullOrEmpty(description)) {
            Stream<String> stream = Arrays.stream(description.split("\n"));
            stream.map(s -> "  #" + s + "\n").forEach(sb::append);
        }
        sb.append(prefix).append(argument.getName()).append(": ").append(typeString(argument.getType()));
        Object defaultValue = argument.getDefaultValue();
        if (defaultValue != null) {
            sb.append(" = ");
            sb.append(printAst(defaultValue, argument.getType()));
        }
        count++;
    }
    if (count > 0) {
        if (hasDescriptions) {
            sb.append("\n");
        }
        sb.append(prefix).append(")");
    }
    return sb.toString();
}
Also used : Arrays(java.util.Arrays) Node(graphql.language.Node) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLScalarType(graphql.schema.GraphQLScalarType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLUnionType(graphql.schema.GraphQLUnionType) GraphQLType(graphql.schema.GraphQLType) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) Supplier(java.util.function.Supplier) AstValueHelper(graphql.language.AstValueHelper) Stack(java.util.Stack) LinkedHashMap(java.util.LinkedHashMap) Description(graphql.language.Description) Map(java.util.Map) GraphQLSchema(graphql.schema.GraphQLSchema) Assert(graphql.Assert) GraphQLObjectType(graphql.schema.GraphQLObjectType) PrintWriter(java.io.PrintWriter) GraphQLDirective(graphql.schema.GraphQLDirective) DEFAULT_FIELD_VISIBILITY(graphql.schema.visibility.DefaultGraphqlFieldVisibility.DEFAULT_FIELD_VISIBILITY) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphqlFieldVisibility(graphql.schema.visibility.GraphqlFieldVisibility) StringWriter(java.io.StringWriter) GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLOutputType(graphql.schema.GraphQLOutputType) GraphQLArgument(graphql.schema.GraphQLArgument) Collectors.joining(java.util.stream.Collectors.joining) AstPrinter(graphql.language.AstPrinter) Document(graphql.language.Document) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Comment(graphql.language.Comment) GraphQLList(graphql.schema.GraphQLList) Stream(java.util.stream.Stream) PublicApi(graphql.PublicApi) GraphQLEnumType(graphql.schema.GraphQLEnumType) Comparator(java.util.Comparator) GraphQLArgument(graphql.schema.GraphQLArgument)

Example 10 with GraphQLArgument

use of graphql.schema.GraphQLArgument in project graphql-java by graphql-java.

the class ProvidedNonNullArguments method checkDirective.

@Override
public void checkDirective(Directive directive, List<Node> ancestors) {
    GraphQLDirective graphQLDirective = getValidationContext().getDirective();
    if (graphQLDirective == null)
        return;
    Map<String, Argument> argumentMap = argumentMap(directive.getArguments());
    for (GraphQLArgument graphQLArgument : graphQLDirective.getArguments()) {
        Argument argument = argumentMap.get(graphQLArgument.getName());
        if (argument == null && (graphQLArgument.getType() instanceof GraphQLNonNull)) {
            String message = String.format("Missing directive argument %s", graphQLArgument.getName());
            addError(ValidationErrorType.MissingDirectiveArgument, directive.getSourceLocation(), message);
        }
    }
}
Also used : GraphQLArgument(graphql.schema.GraphQLArgument) Argument(graphql.language.Argument) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLArgument(graphql.schema.GraphQLArgument) GraphQLDirective(graphql.schema.GraphQLDirective)

Aggregations

GraphQLArgument (graphql.schema.GraphQLArgument)15 GraphQLDirective (graphql.schema.GraphQLDirective)5 GraphQLInputType (graphql.schema.GraphQLInputType)5 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)4 GraphQLNonNull (graphql.schema.GraphQLNonNull)4 Argument (graphql.language.Argument)3 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)2 GraphQLList (graphql.schema.GraphQLList)2 GraphQLObjectType (graphql.schema.GraphQLObjectType)2 GraphQLOutputType (graphql.schema.GraphQLOutputType)2 GraphQLScalarType (graphql.schema.GraphQLScalarType)2 GraphQLUnionType (graphql.schema.GraphQLUnionType)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Lists (com.google.common.collect.Lists)1 Assert (graphql.Assert)1 PublicApi (graphql.PublicApi)1 Scalars (graphql.Scalars)1