Package io.github.microcks.util.graphql
Class GraphQLSchemaValidator
java.lang.Object
io.github.microcks.util.graphql.GraphQLSchemaValidator
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.validateJson
(com.fasterxml.jackson.databind.JsonNode schemaNode, com.fasterxml.jackson.databind.JsonNode jsonNode) Commodity method: just a shortcut to JsonSchemaValidator.validateJson(schemaNode, jsonNode)
-
Field Details
-
GRAPHQL_RESPONSE_DATA
- See Also:
-
-
Constructor Details
-
GraphQLSchemaValidator
public GraphQLSchemaValidator()
-
-
Method Details
-
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 !
-