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);
}
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();
}
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();
}
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();
}
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);
}
}
}
Aggregations