Search in sources :

Example 1 with Description

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);
}
Also used : SourceLocation(graphql.language.SourceLocation) Description(graphql.language.Description) GraphqlParser(graphql.parser.antlr.GraphqlParser) StringValueParsing.parseTripleQuotedString(graphql.parser.StringValueParsing.parseTripleQuotedString) StringValueParsing.parseSingleQuotedString(graphql.parser.StringValueParsing.parseSingleQuotedString)

Example 2 with Description

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);
        }
    }
}
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) Description(graphql.language.Description)

Example 3 with Description

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();
}
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 4 with Description

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);
}
Also used : Comment(graphql.language.Comment) Description(graphql.language.Description) Node(graphql.language.Node)

Aggregations

Description (graphql.language.Description)4 Comment (graphql.language.Comment)3 Node (graphql.language.Node)3 Assert (graphql.Assert)2 PublicApi (graphql.PublicApi)2 AstPrinter (graphql.language.AstPrinter)2 AstValueHelper (graphql.language.AstValueHelper)2 Document (graphql.language.Document)2 GraphQLArgument (graphql.schema.GraphQLArgument)2 GraphQLDirective (graphql.schema.GraphQLDirective)2 GraphQLEnumType (graphql.schema.GraphQLEnumType)2 GraphQLEnumValueDefinition (graphql.schema.GraphQLEnumValueDefinition)2 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)2 GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)2 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)2 GraphQLInputType (graphql.schema.GraphQLInputType)2 GraphQLInterfaceType (graphql.schema.GraphQLInterfaceType)2 GraphQLList (graphql.schema.GraphQLList)2 GraphQLNonNull (graphql.schema.GraphQLNonNull)2 GraphQLObjectType (graphql.schema.GraphQLObjectType)2