Reputation: 10695
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).
Upvotes: 2
Views: 845
Reputation: 10695
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);
Upvotes: 2