These are chat archives for graphql-java/graphql-java

22nd
Jun 2017
quangnn1209
@quangnn1209
Jun 22 2017 06:07
hi all, is there any way to "validate input parameters" by "my own business" "before execute"?
Brad Baker
@bbakerman
Jun 22 2017 06:08
no - the type safety of graphql types etc… are pre-checked
but the business meaning of each “field” and its “arguments” are data fetcher specific
quangnn1209
@quangnn1209
Jun 22 2017 06:08
i'm using AsyncStrategy to send multiple requests in parallel then validation in DataFetcher is not good
Brad Baker
@bbakerman
Jun 22 2017 06:09
you can get the “field sub selection” in a data fetcher before you send the back end requests
{
   toplevelfield(id : 123)
       lowerlevel(arg:3212)
quangnn1209
@quangnn1209
Jun 22 2017 06:10
i see but suppose i have 3 requests, #1 has invalid parameters, i want to stop all request including #2 & #3
Brad Baker
@bbakerman
Jun 22 2017 06:11
then I suggest a custom excution strategy
it is called to “execute” a validated query
it could have all the “query specific logic” that validates the args in business terms
such a “execution strategy” would be highly coupled to your schema design of course
it can then delegate to an undelying common one
quangnn1209
@quangnn1209
Jun 22 2017 06:14
now what i'm having is AsynchronousExecutionStrategy extends ExecutionStrategy
you mean i need another CustomeExecutionStrategy which wrap my AsynchronousExecutionStrategy?
Brad Baker
@bbakerman
Jun 22 2017 06:15
I mean JUST before you dispatch the query - validate the args - you would have to parse the nodes and understand its structure though
quangnn1209
@quangnn1209
Jun 22 2017 06:17
i see
Brad Baker
@bbakerman
Jun 22 2017 06:17
graphql.language.OperationDefinition which is in the execution context is the parse tree of the query

eg:

 ```

{
toplevelfield(id : 123)
lowerlevel(arg:3212)
```

{
   toplevelfield(id : 123)
       lowerlevel(arg:3212)
but in Java node form
graphql is not really designed to be run like this
if you do
   field1 (arg : x)
   field2(arg :Y)
then field1 is meant to be run AND field 2 is meant to be run and the error list contains both
sets of problems
field1 is NOT dependant on field2 in graphql ethos
which allows for parralel execution
(mutations are the exception are are always run serially for that reason)
so having a situation where field2 is dependant on field1 being correct — is a bit anti graphql
quangnn1209
@quangnn1209
Jun 22 2017 06:20
:D
i understood
what does response become if there is one request returns error?
Brad Baker
@bbakerman
Jun 22 2017 06:23
lets say field1 works and field2 has errors
then the ExecutionREsult has values in er.getData() for field1 and er.getErrors() contains errors
it designed like that to allow partial information
imagine you are retrieving a document and its comments
the client can still work without the comments say
it has to handle that error - sure - but the document retrieval worked say
    document(arg : 123) {
       comments {
           text
      }
document(arg : 123) {
text
author
comments {
text
}
document(arg : 123) {
       text
      author
       comments {
           text
      }
sorry (bad formatting)
the first fetcher for document might have succeed but the comments did not
say
data” : {“doc” { “author” : “Brad”, “text: “blah pal”}}, “errors” : [ { “error text here for comments” }]
quangnn1209
@quangnn1209
Jun 22 2017 06:27
i see
Brad Baker
@bbakerman
Jun 22 2017 06:28
this is very different to REST right
where document would be 1 call to a resource and comments would be another
(say)
quangnn1209
@quangnn1209
Jun 22 2017 06:28
so that is graphql's spirit, looks like errors ignorant :D
quangnn1209
@quangnn1209
Jun 22 2017 06:36
thank you verymuch @bbakerman
Maximilian Vogel
@muetzerich
Jun 22 2017 12:15
Hi everybody! I want to integrate the graphiQL-tool. The basic functions are working, but graphiql is sending a introspection query on startup to the graphql-server to run autocompletion and more. Is there a way to run a introspection query on the schema to archieve the full graphiQL functionality?
Brad Baker
@bbakerman
Jun 22 2017 12:16
the graphql-java library supports full introspection (as the spec mandates)
so let the query go to the backing server and it will “just work"
works with graphiql tools out of the box
(it doesnt serve graphiql itself - but standalone tools can be pointed to it)
(I used this one a lot : https://github.com/skevy/graphiql-app)
Maximilian Vogel
@muetzerich
Jun 22 2017 12:23
ok, thank you very much! very nice that it works out of the box.
Brad Baker
@bbakerman
Jun 22 2017 12:23
thank the spec for making introspection mandatory
:)
Maximilian Vogel
@muetzerich
Jun 22 2017 12:24
:D okay thanks spec!
Bojan Tomić
@kaqqao
Jun 22 2017 19:16
I was looking into making a PR that would make exception-to-error translation more straight forward (as discussed with @bbakerman ), but... I can not get into the situation that @_bkern_twitter , @Vi-dot and many others were describing, where you end up with a full strack trace in the result
nor can I understad how could this ever happen. All exceptions thrown from a DataFetcher get wrapped into ExceptionWhileDataFetching, which only exposes getMessage, only giving the original exception's message, not track trace, getLocations, giving a line and column number, and getErrorType which is an enum. So... how could it ever end up with a stack trace in the result? Yet, many people are complaining, so there's got to be something I'm missing...
Could someone who was struggling with this help me understand their use-case?
Brad Baker
@bbakerman
Jun 22 2017 21:50
@kaqqao - are you turning the object back into JSON? JSON serialisers do all Java bean field
    public ExceptionWhileDataFetching(ExecutionPath path, Throwable exception) {
        this.path = assertNotNull(path);
        this.exception = assertNotNull(exception);
    }

    public Throwable getException() {
        return exception;
    }
that get exception will expand via the JSON serialisaer
and then
    public StackTraceElement[] getStackTrace() {
        return getOurStackTrace().clone();
    }
Daniel Ocampo
@danielocampo2
Jun 22 2017 23:59
@bbakerman created new issue for what we talked about previously. hopefully at some point we can figure out a solution for it
graphql-java/graphql-java-annotations#90