Class AbstractDirectiveConstraint

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean appliesTo​(graphql.schema.GraphQLArgument argument, graphql.schema.GraphQLFieldDefinition fieldDefinition, graphql.schema.GraphQLFieldsContainer fieldsContainer)
      This is called to work out if this rule applies to the argument of a specified field
      boolean appliesTo​(graphql.schema.GraphQLFieldDefinition fieldDefinition, graphql.schema.GraphQLFieldsContainer fieldsContainer)
      This is called to work out if this rule applies to a specified field
      protected abstract boolean appliesToListElements()  
      protected abstract boolean appliesToType​(graphql.schema.GraphQLInputType inputType)
      A derived class will be called to indicate whether this input type applies to the constraint
      protected java.math.BigDecimal asBigDecimal​(java.lang.Object value)
      Makes the object a BigDecimal with an assertion if we have no conversion of it
      protected boolean asBoolean​(java.lang.Object value)
      Makes the object a boolean with an assertion if we have no conversion of it
      protected java.util.Map asMap​(java.lang.Object value)
      Casts the object as a Map with an assertion of it is not one
      protected boolean getBoolArg​(graphql.schema.GraphQLAppliedDirective directive, java.lang.String argName)
      Returns an boolean argument from a directive (or its default) and throws an assertion of the argument is null
      protected int getIntArg​(graphql.schema.GraphQLAppliedDirective directive, java.lang.String argName)
      Returns an integer argument from a directive (or its default) and throws an assertion of the argument is null
      protected java.lang.String getMessageTemplate()  
      protected java.lang.String getMessageTemplate​(graphql.schema.GraphQLAppliedDirective directive)
      Returns the "message : String" argument from a directive or makes up one called "graphql.validation.{name}.message"
      java.lang.String getName()  
      protected java.lang.String getStrArg​(graphql.schema.GraphQLAppliedDirective directive, java.lang.String argName)
      Returns an String argument from a directive (or its default) and throws an assertion of the argument is null
      protected int getStringOrIDOrObjectOrMapLength​(graphql.schema.GraphQLInputType inputType, java.lang.Object value)
      Returns the length of a String, ID, size of a list or size of a Map
      protected boolean isMap​(graphql.schema.GraphQLInputType inputType)  
      protected boolean isOneOfTheseTypes​(graphql.schema.GraphQLInputType inputType, graphql.schema.GraphQLScalarType... scalarTypes)  
      protected boolean isOneOfTheseTypes​(graphql.schema.GraphQLInputType inputType, java.util.Collection<graphql.schema.GraphQLScalarType> scalarTypes)
      Returns true of the input type is one of the specified scalar types, regardless of non null ness
      protected boolean isStringOrID​(graphql.schema.GraphQLInputType inputType)
      Return true if the type is a String or ID
      protected boolean isStringOrIDOrList​(graphql.schema.GraphQLInputType inputType)
      Return true if the type is a String or ID or List type, regardless of non null ness
      protected boolean isStringOrIDOrListOrMap​(graphql.schema.GraphQLInputType inputType)
      Return true if the type is a String or ID or List type or GraphQLInputObjectType, regardless of non null ness
      protected java.util.List<graphql.GraphQLError> mkError​(ValidationEnvironment validationEnvironment, graphql.schema.GraphQLAppliedDirective directive, java.util.Map<java.lang.String,​java.lang.Object> msgParams)
      Creates a new GraphQLError
      protected java.util.List<graphql.GraphQLError> mkError​(ValidationEnvironment validationEnvironment, java.lang.Object... messageParameters)  
      protected java.util.Map<java.lang.String,​java.lang.Object> mkMessageParams​(java.lang.Object validatedValue, ValidationEnvironment validationEnvironment, java.lang.Object... args)
      Creates a map of named parameters for message interpolation
      protected abstract java.util.List<graphql.GraphQLError> runConstraint​(ValidationEnvironment validationEnvironment)
      This is called to perform the constraint validation
      java.util.List<graphql.GraphQLError> runValidation​(ValidationEnvironment validationEnvironment)
      This is called to runs the rule.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • AbstractDirectiveConstraint

        public AbstractDirectiveConstraint​(java.lang.String name)
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface DirectiveConstraint
        Returns:
        the name of the constraint
      • getMessageTemplate

        protected java.lang.String getMessageTemplate()
      • appliesTo

        public boolean appliesTo​(graphql.schema.GraphQLFieldDefinition fieldDefinition,
                                 graphql.schema.GraphQLFieldsContainer fieldsContainer)
        Description copied from interface: ValidationRule
        This is called to work out if this rule applies to a specified field
        Specified by:
        appliesTo in interface ValidationRule
        Parameters:
        fieldDefinition - the field to check
        fieldsContainer - the field container
        Returns:
        true if this rule applies to the field
      • appliesTo

        public boolean appliesTo​(graphql.schema.GraphQLArgument argument,
                                 graphql.schema.GraphQLFieldDefinition fieldDefinition,
                                 graphql.schema.GraphQLFieldsContainer fieldsContainer)
        Description copied from interface: ValidationRule
        This is called to work out if this rule applies to the argument of a specified field
        Specified by:
        appliesTo in interface ValidationRule
        Parameters:
        argument - the argument to check
        fieldDefinition - the field to check
        fieldsContainer - the field container
        Returns:
        true if this rule applies to the argument of the field field
      • appliesToType

        protected abstract boolean appliesToType​(graphql.schema.GraphQLInputType inputType)
        A derived class will be called to indicate whether this input type applies to the constraint
        Parameters:
        inputType - the input type
        Returns:
        true if the constraint can handle that type
      • runConstraint

        protected abstract java.util.List<graphql.GraphQLError> runConstraint​(ValidationEnvironment validationEnvironment)
        This is called to perform the constraint validation
        Parameters:
        validationEnvironment - the validation environment
        Returns:
        a list of errors or an empty one if there are no errors
      • runValidation

        public java.util.List<graphql.GraphQLError> runValidation​(ValidationEnvironment validationEnvironment)
        Description copied from interface: ValidationRule
        This is called to runs the rule. A rule maybe invoked MULTIPLE times per field. It will be invoked once for the original field, then invoked for each of the arguments on a field and then if the input types are complex ones such as GraphQLInputObjectType then it will be invoked for each attribute of that type.

        A rule should consult ValidationEnvironment.getValidatedElement() to check what element is being validated. If the rule does not handle that type of element, simply return an empty list of errors.

        Specified by:
        runValidation in interface ValidationRule
        Parameters:
        validationEnvironment - the validation environment
        Returns:
        a non null list of errors where emptyList() means its valid
      • appliesToListElements

        protected abstract boolean appliesToListElements()
      • isOneOfTheseTypes

        protected boolean isOneOfTheseTypes​(graphql.schema.GraphQLInputType inputType,
                                            graphql.schema.GraphQLScalarType... scalarTypes)
      • isOneOfTheseTypes

        protected boolean isOneOfTheseTypes​(graphql.schema.GraphQLInputType inputType,
                                            java.util.Collection<graphql.schema.GraphQLScalarType> scalarTypes)
        Returns true of the input type is one of the specified scalar types, regardless of non null ness
        Parameters:
        inputType - the type to check
        scalarTypes - the array of scalar types
        Returns:
        true if its one of them
      • getIntArg

        protected int getIntArg​(graphql.schema.GraphQLAppliedDirective directive,
                                java.lang.String argName)
        Returns an integer argument from a directive (or its default) and throws an assertion of the argument is null
        Parameters:
        directive - the directive to check
        argName - the argument name
        Returns:
        a non null value
      • getStrArg

        protected java.lang.String getStrArg​(graphql.schema.GraphQLAppliedDirective directive,
                                             java.lang.String argName)
        Returns an String argument from a directive (or its default) and throws an assertion of the argument is null
        Parameters:
        directive - the directive to check
        argName - the argument name
        Returns:
        a non null value
      • getBoolArg

        protected boolean getBoolArg​(graphql.schema.GraphQLAppliedDirective directive,
                                     java.lang.String argName)
        Returns an boolean argument from a directive (or its default) and throws an assertion of the argument is null
        Parameters:
        directive - the directive to check
        argName - the argument name
        Returns:
        a non null value
      • getMessageTemplate

        protected java.lang.String getMessageTemplate​(graphql.schema.GraphQLAppliedDirective directive)
        Returns the "message : String" argument from a directive or makes up one called "graphql.validation.{name}.message"
        Parameters:
        directive - the directive to check
        Returns:
        a non null value
      • mkMessageParams

        protected java.util.Map<java.lang.String,​java.lang.Object> mkMessageParams​(java.lang.Object validatedValue,
                                                                                         ValidationEnvironment validationEnvironment,
                                                                                         java.lang.Object... args)
        Creates a map of named parameters for message interpolation
        Parameters:
        validatedValue - the value being validated
        validationEnvironment - the validation environment
        args - must be an key / value array with String keys as the even params and values as then odd params
        Returns:
        a map of message parameters
      • mkError

        protected java.util.List<graphql.GraphQLError> mkError​(ValidationEnvironment validationEnvironment,
                                                               graphql.schema.GraphQLAppliedDirective directive,
                                                               java.util.Map<java.lang.String,​java.lang.Object> msgParams)
        Creates a new GraphQLError
        Parameters:
        validationEnvironment - the current validation environment
        directive - the directive being run
        msgParams - the map of parameters
        Returns:
        a list of a single error
      • mkError

        protected java.util.List<graphql.GraphQLError> mkError​(ValidationEnvironment validationEnvironment,
                                                               java.lang.Object... messageParameters)
      • isStringOrIDOrList

        protected boolean isStringOrIDOrList​(graphql.schema.GraphQLInputType inputType)
        Return true if the type is a String or ID or List type, regardless of non null ness
        Parameters:
        inputType - the type to check
        Returns:
        true if one of the above
      • isStringOrIDOrListOrMap

        protected boolean isStringOrIDOrListOrMap​(graphql.schema.GraphQLInputType inputType)
        Return true if the type is a String or ID or List type or GraphQLInputObjectType, regardless of non null ness
        Parameters:
        inputType - the type to check
        Returns:
        true if one of the above
      • isMap

        protected boolean isMap​(graphql.schema.GraphQLInputType inputType)
      • isStringOrID

        protected boolean isStringOrID​(graphql.schema.GraphQLInputType inputType)
        Return true if the type is a String or ID
        Parameters:
        inputType - the type to check
        Returns:
        true if one of the above
      • asMap

        protected java.util.Map asMap​(java.lang.Object value)
        Casts the object as a Map with an assertion of it is not one
        Parameters:
        value - the object to turn into a map
        Returns:
        a Map
      • asBigDecimal

        protected java.math.BigDecimal asBigDecimal​(java.lang.Object value)
                                             throws java.lang.NumberFormatException
        Makes the object a BigDecimal with an assertion if we have no conversion of it
        Parameters:
        value - the object to turn into a BigDecimal
        Returns:
        a BigDecimal
        Throws:
        java.lang.NumberFormatException
      • asBoolean

        protected boolean asBoolean​(java.lang.Object value)
        Makes the object a boolean with an assertion if we have no conversion of it
        Parameters:
        value - the boolean object
        Returns:
        a boolean
      • getStringOrIDOrObjectOrMapLength

        protected int getStringOrIDOrObjectOrMapLength​(graphql.schema.GraphQLInputType inputType,
                                                       java.lang.Object value)
        Returns the length of a String, ID, size of a list or size of a Map
        Parameters:
        inputType - the input type
        value - the value
        Returns:
        the length of a String or Map or List