Download the PHP package infinityloop-dev/graphpinator-constraint-directives without Composer
On this page you can find all versions of the php package infinityloop-dev/graphpinator-constraint-directives. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download infinityloop-dev/graphpinator-constraint-directives
More information about infinityloop-dev/graphpinator-constraint-directives
Files in infinityloop-dev/graphpinator-constraint-directives
Package graphpinator-constraint-directives
Short Description Typesystem directives to declare additional validation on top of GraphQL type system.
License MIT
Homepage https://github.com/graphpql/
Informations about the package graphpinator-constraint-directives
GraPHPinator Constraint directives

:zap::globe_with_meridians::zap: Typesystem directives declare additional validation on the top of the GraphQL type system.
Introduction
This package allows server to declare additional constraints on accepted values for arguments, fields and input fields. It is also possible for client to declare constraints for variables in request document.
Additional benefit of using constraint directives is that expected values are displayed to client using GraphQL type language in a self-documenting manner.
Installation
Install package using composer
How to use
In order to enable constraint directives on your server, the only thing you need to do is to put selected directives to your Container
. To avoid cyclic dependencies ConstraintDirectiveAccessor
must be implemented. This step should be automated when using a DI solution.
Here is example configuration for Nette DI:
Add constraint to Argument
The most common usage of constraint directives is to validate input from client without having to do it yourself in the resolve function.
Add constraint to Field
Additional usage of constraint directives is to validate output from your resolve functions.
Add constraint to Type & Interface & InputType
Special case is ObjectConstraint
which declares additional information on which fields must be filled. It is a flexible solution to the input-union problem, but can also be applied on Interface/Type to semantically indicate which values are returned.
Variance
Question of variance comes into play because field, argument, and object constraints can be declared in an interface context and then implemented by the concrete type. Traditional rules apply here.
- Covariance for Field constraints - child can restrict parent's constraint, but may not release it.
- Contravariance for Argument constraints - child can soften parent's constraint, but may not restrict it.
- Invariance for Object constraints - child must contain the same constraint as parent.
Directive options
@stringConstraint
- minLength -
Int
- maxLength -
Int
- regex -
String
- oneOf -
[String!]
- minLength -
@intConstraint
- min -
Int
- max -
Int
- oneOf -
[Int!]
- min -
@floatConstraint
- min -
Float
- max -
Float
- oneOf -
[Float!]
- min -
@listConstraint
- minItems -
Int
- maxItems -
Int
- unique -
Boolean
- innerList - object with the same arguments to recursivelly apply constraint to inner list
- minItems -
@uploadConstraint
- maxSize -
Int
- mimeType -
[String!]
- maxSize -
@objectConstraint
- atLeastOne -
[String!]
- atMostOne -
[String!]
- exactlyOne -
[String!]
- atLeast -
{count: Int!, from: [String!]!}
- atMost -
{count: Int!, from: [String!]!}
- exactly -
{count: Int!, from: [String!]!}
- atLeastOne -
All versions of graphpinator-constraint-directives with dependencies
ext-fileinfo Version *
infinityloop-dev/graphpinator Version ^1.6
infinityloop-dev/utils Version ^2.3