use of graphql.language.Description in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method newDescription.
private Description newDescription(GraphqlParser.DescriptionContext descriptionCtx) {
if (descriptionCtx == null) {
return null;
}
GraphqlParser.StringValueContext stringValueCtx = descriptionCtx.stringValue();
if (stringValueCtx == null) {
return null;
}
boolean multiLine = stringValueCtx.TripleQuotedStringValue() != null;
String content = stringValueCtx.getText();
if (multiLine) {
content = parseTripleQuotedString(content);
} else {
content = parseSingleQuotedString(content);
}
SourceLocation sourceLocation = getSourceLocation(descriptionCtx);
return new Description(content, sourceLocation, multiLine);
}
use of graphql.language.Description in project graphql-java by graphql-java.
the class SchemaPrinter method printComments.
private void printComments(PrintWriter out, Object graphQLType, String prefix) {
AstDescriptionAndComments descriptionAndComments = getDescriptionAndComments(graphQLType);
if (descriptionAndComments == null) {
return;
}
Description astDescription = descriptionAndComments.descriptionAst;
if (astDescription != null) {
String quoteStr = "\"";
if (astDescription.isMultiLine()) {
quoteStr = "\"\"\"";
}
out.write(prefix);
out.write(quoteStr);
out.write(astDescription.getContent());
out.write(quoteStr);
out.write("\n");
return;
}
if (descriptionAndComments.comments != null) {
descriptionAndComments.comments.forEach(cmt -> {
out.write(prefix);
out.write("#");
out.write(cmt.getContent());
out.write("\n");
});
} else {
String runtimeDescription = descriptionAndComments.runtimeDescription;
if (!isNullOrEmpty(runtimeDescription)) {
Stream<String> stream = Arrays.stream(runtimeDescription.split("\n"));
stream.map(s -> prefix + "#" + s + "\n").forEach(out::write);
}
}
}
use of graphql.language.Description 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.language.Description in project graphql-java by graphql-java.
the class SchemaPrinter method descriptionAndComments.
AstDescriptionAndComments descriptionAndComments(Supplier<String> stringSupplier, Supplier<Node> nodeSupplier, Supplier<Description> descriptionSupplier) {
String runtimeDesc = stringSupplier.get();
Node node = nodeSupplier.get();
Description description = null;
List<Comment> comments = null;
if (node != null) {
comments = node.getComments();
description = descriptionSupplier.get();
}
return new AstDescriptionAndComments(runtimeDesc, description, comments);
}
Aggregations