bagasprstyadi

bagasprstyadi

Validate graphql query/mutation arguments on Elixir

I’m looking for a module or something that can be used for validating a graphql query/mutation on Elixir. I’ve researched for it and stumble across a cool middleware called yup-middleware: GitHub - JCMais/graphql-yup-middleware: Add validation to your mutations arguments using yup! · GitHub but it is not for elixir

Is there a same module to in elixir that can be used to validate? I know I can use Absinthe.Middleware but I was just wondering if there is such a module that is easier to use.

First 9 of 9 Posts! Switch mode

abitdodgy

abitdodgy

Can’t you use Ecto changesets? A quick search yielded Kronky. But I’m not sure if this is what you are looking for.

Virviil

Virviil

GraphQL seems to be a strong typed query language, so absinthe will validate all the parameters for you.
So, when you say “validate” what does that mean? Validate upon business logic? This probably should be done in Ecto Changesets or resolvers.

sorentwo

sorentwo

Oban Core Team

GraphQL types can be leveraged for data validation to a large degree, provided you make use of the tools it provides (i.e. enums). You can get additional validation through custom types like email or url, but you’ll need to write the parsing and dumping yourself, and in a way that emits helpful errors.

There are plenty of places where GraphQL/Absinthe can’t help you though. For example, if you want to enforce a string is a certain size, or that a particular field is filled in but another isn’t, or a provided ID actually exists in the database. You’ll need to fall back to validating with Ecto and your application’s business rules.

bagasprstyadi

bagasprstyadi

If using changeset what I concern is that, there will be a lot of business logic before entering the schema right? What if I want to validate like a lot of formating for example name, email, url. I think Kronky is some module that helps you to return error message back to graphql

bagasprstyadi

bagasprstyadi

Yes Graphql already provided with basic validate parameters as in :string, or :integer. But what I need is something a bit more like String is must be length of with format x. Like that

joaquinalcerro

joaquinalcerro

Bagasprstyadi,

Check-out this talk where the presenter uses Ecto Changeset to create a validation layer.

https://youtu.be/k_xDi7zAcNM

Hope this helps.

Best regards,

Joaquin Alcerro

Virviil

Virviil

It may be not so obvious, but you don’t need string to be with minimum length. You need password to be minimum length.

And this leads us two 2 different solutons:

  1. You can create GraphQL type Password, it’s easily achieved with Absinthe library itself.

  2. You can pass password as string, but validate it on your business logic. This can be done with your Ecto structures.

bagasprstyadi

bagasprstyadi

Wow thank you, I will check it!

bagasprstyadi

bagasprstyadi

“You can create GraphQL type Password

This is interesting, so I can create custom type right, and then the graphql will validate it? Awesome, Im gonna look into that

— All posts loaded —

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement