When writing a GraphQL-client that builds query strings manually, is there a way to write unit tests that checks that the syntax of a graphQL query is valid? Like using some official parser and checking it does not find syntax errors?
Usage of libraries is allowed in the answer, (though obviously if it's a library to not use raw strings to write queries, then the question becomes moot).
Seems this might work, including graphql-java library:
<!-- https://mvnrepository.com/artifact/com.graphql-java/graphql-java -->
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
<version>2020-05-19T06-33-01-57ce5cf</version>
</dependency>
The parse the query.
graphql.parser.Parser graphQLParser = new Parser();
// assert no exception
graphQLParser.parseDocument(queryString);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.