Package io.github.microcks.util.graphql
Class GraphQLSchemaValidator
- java.lang.Object
-
- io.github.microcks.util.graphql.GraphQLSchemaValidator
-
public class GraphQLSchemaValidator extends Object
Helper class for validating Json objects against their GraphQL schema. Supported version of GraphQL schema is https://spec.graphql.org/October2021/.- Author:
- laurent
-
-
Field Summary
Fields Modifier and Type Field Description static String
GRAPHQL_RESPONSE_DATA
-
Constructor Summary
Constructors Constructor Description GraphQLSchemaValidator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.fasterxml.jackson.databind.JsonNode
buildResponseJsonSchema(String schemaText, String query)
Build a JSON Schema that should apply to a GraphQL response giving the API GraphQL SDL and the query specification.static List<String>
validateJson(com.fasterxml.jackson.databind.JsonNode schemaNode, com.fasterxml.jackson.databind.JsonNode jsonNode)
Commodity method: just a shortcut to JsonSchemaValidator.validateJson(schemaNode, jsonNode)
-
-
-
Field Detail
-
GRAPHQL_RESPONSE_DATA
public static final String GRAPHQL_RESPONSE_DATA
- See Also:
- Constant Field Values
-
-
Method Detail
-
buildResponseJsonSchema
public static com.fasterxml.jackson.databind.JsonNode buildResponseJsonSchema(String schemaText, String query) throws IOException
Build a JSON Schema that should apply to a GraphQL response giving the API GraphQL SDL and the query specification. Query specification allows to get structure and mandatory fields from selection ; Schema allows to get type definition (scalar, arrays, objects).- Parameters:
schemaText
- The text representation of a GraphQL Schemaquery
- The text representation of a GraphQL query- Returns:
- The Jackson JsonNode representing the Json schema for response
- Throws:
IOException
- if parsing of either schema of query fails
-
validateJson
public static List<String> validateJson(com.fasterxml.jackson.databind.JsonNode schemaNode, com.fasterxml.jackson.databind.JsonNode jsonNode)
Commodity method: just a shortcut to JsonSchemaValidator.validateJson(schemaNode, jsonNode)- Parameters:
schemaNode
- The Json schema specification as a Jackson nodejsonNode
- The Json object as a Jackson node- Returns:
- The list of validation failures. If empty, json object is valid !
-
-