bagasprstyadi

bagasprstyadi

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.

Showing Posts 1 to 9

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 OP

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 OP

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 OP

Wow thank you, I will check it!

bagasprstyadi

bagasprstyadi OP

“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? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews