Replies: 3 comments 13 replies
-
|
I understand what you want and we have considered a kind of pre-validation callback before but every time we considered it - we realised two things
So really we aim for the data fetcher to be the callback layer - graphql-java is complicated enough without need more sub specialised callbacks There are a couple of things you can do here. If you are building your schema from SDL (and it looks like you do) then you can use Take a look at https://github.com/graphql-java/graphql-java-extended-validation which uses this. If you squint it a bit like yours - except it stops on validation errors - yours wants to change the argument values It uses directives on fields as validation rules and introduces a wrapper data fetcher that enforces the rules. In this case it only validates. It does not modify the input args but it could Imagine this This needs to do 2 things - look at the field and its arguments the type of the arguments for your custom directives - if they are present then continue Then this creates a new DataFetcher for the field whose job it is to sanitize the arguments and create a new DFE with those args. It then calls the original data fetcher who is none the wiser that code aspects have been wired in. This schema wiring happens are schema build time (once) and so the originally wired data fetcher is still called - but with different values Let me know if this helps or you have more questions. |
Beta Was this translation helpful? Give feedback.
-
|
ps this is more a discussion than an bug so I am moving it to discussions |
Beta Was this translation helpful? Give feedback.
-
|
Hello Brad @bbakerman and Alexey @donbeave, Thank you both for great question and brilliant answer. I tried For input objects there is no Guys, do you have some ideas? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
First of all, thank you for developing such an amazing engine. It's beautiful work and a very good innovation that will move the Java ecosystem forward.
I found one issue, but not sure if is it by design, or it's lack of my knowledge.
I have such DSL:
I would like to use
@stripHtmldirective to sanitize values, like insearchProfilethecontainsargument must remove all HTML code from the value, and the same for the fieldusernameinSignUpInput.Looks like the current version of
graphql-javaallows doing so by using custom data fetchers only, and sanitizing values customly inside the data fetcher. But this isn't an easy way, as it requires going through all mapped entities and checking does it inside a list of fields or arguments annotated with this directive.But I'm looking for an API that allows doing so somehow before, and with the sanitized results already in
DataFetchingEnvironmentclass, like this method will return sanitized values already:graphql-java/src/main/java/graphql/schema/DataFetchingEnvironment.java
Line 47 in 477d9a0
And in terms of
SignUpInput, let's imagine I'm using a plain Java DTO class for that input, and the sanitized value will be passed to the methodsetUsername(String username).@andimarek @bbakerman What do you think, is it possible to add some processor API that will allow us to post-process the value?
Beta Was this translation helpful? Give feedback.
All reactions