Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/broadlume/graphql-validation

Simple validation of GraphQL inputs in Ruby
https://github.com/broadlume/graphql-validation

Last synced: about 2 months ago
JSON representation

Simple validation of GraphQL inputs in Ruby

Awesome Lists containing this project

README

        

[![Gem Version](https://badge.fury.io/rb/graphql-validation.svg)](https://badge.fury.io/rb/graphql-validation)
[![Build Status](https://travis-ci.org/adHawk/graphql-validation.svg?branch=master)](https://travis-ci.org/adHawk/graphql-validation)

# Graphql::Validation

A simple gem to help with common validating GraphQL input objects.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'graphql-validation'
```

And then execute:

$ bundle

## Usage

```ruby
ProductValidator = Dry::Validation.Form do
required(:amount).filled(:int?, gteq?: 0)
end

CreateProductMutation = GraphQL::Relay::Mutation.define do
input_field :product, !ProductInputType, validate_with: ProductValidator
return_field :id, types.ID
# ...
end

MutationType = GraphQL::ObjectType.define do
name 'Mutation'
description 'The mutation root of this schema'
field :createProduct, field: CreateProductMutation.field
end
```

## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).