AddThis

Wednesday, 21 October 2020

How to format graphql query string in Java


import graphql.language.AstPrinter;
import graphql.language.Document;
import graphql.parser.Parser;

public class GraphqlQueryFormatter {
    public static void main(String[] args) {
        String gql = "query { getEmployee (employeeId:"4859493") { name dob department } ";
        Parser parser = new Parser();
        Document doc = parser.parseDocument(gql);
        System.out.println(AstPrinter.printAst(doc));
    }
}

No comments:

Post a Comment

Core functional interfaces in Java (Function, Predicate, Consumer, and Supplier)

  The four core functional interfaces in Java ( Function , Predicate , Consumer , and Supplier ) are the backbone of lambda expressions a...