Class 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
    • Constructor Detail

      • GraphQLSchemaValidator

        public GraphQLSchemaValidator()
    • 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 Schema
        query - 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 node
        jsonNode - The Json object as a Jackson node
        Returns:
        The list of validation failures. If empty, json object is valid !