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

22nd
May 2017
Brad Baker
@bbakerman
May 22 2017 00:04
@OlegIlyenko - does your https://github.com/graphql-cats/graphql-cats project publish maven artefacts? eg: how would a consumer of this spec get the yaml?
Bojan Tomić
@kaqqao
May 22 2017 02:11
Is there a way to get the GraphQLFieldDefinition for the currently resolved field in DataFetcherEnvironment? I mean, I understand I can get the parent type, cast it and get the field by name, but is that the way?
Brad Baker
@bbakerman
May 22 2017 02:15
    /**
 * @return the list of fields currently in query context
 */
List<Field> getFields();
turns out that this is an array of the same field
sorry list
because fragements and fields can resolve to a field fetch
so getFields().get(0) is what you want
Bojan Tomić
@kaqqao
May 22 2017 02:16
Oops, sorry, I meant to say GraphQLFieldDefinition (fixed now)
Brad Baker
@bbakerman
May 22 2017 02:41
ahh no - there is an issue for that on the backlog
seems like an oversight more than anything?
Johannes Schüth
@Jotschi
May 22 2017 15:41
I was wondering.. is the context just a map which is accessible everywhere? I would like to inherit some context values within a specific branch of my query..
{
  blub(someArg: "enemene") {
       # the dataFetcher for blub2 can access enemene from context 
       blub2 
  }
 another: blub(someArg: "totallydifferent") {
    # the dataFetcher for blub2 can access totallydifferent from context
    blub2
 }
}
I think i can't just store the someArg value with the same key in the context. Once the query is run multithreaded that would cause problems (I assume)
Johannes Schüth
@Jotschi
May 22 2017 15:46
The only think i can think of is passing along a container object which contains this information. I could just return this object via the regular dataFetchers and access it via getSource()
ΘLΞG
@OlegIlyenko
May 22 2017 16:32
@bbakerman not yet, but we definitely plan to publish it to maven central and other language-specific repos, like npm, ruby gem, etc
Thomas Lovett
@tlovett-rmn
May 22 2017 16:33
NonNullableFieldWasNullException#getErrorType() returns (ErrorType) null -- would anyone be able to give me a quick run through of why? It happens to be giving me an NPE at the moment, but I'm not sure our exception handler should be handling that error at all
https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/execution/NonNullableFieldWasNullException.java#L40-L43
Thomas Lovett
@tlovett-rmn
May 22 2017 16:49
(Update: We're not handling that error, just the NPE thrown when converting that GraphQLError to our ErrorDto api response type)
Bojan Tomić
@kaqqao
May 22 2017 17:08
@Jotschi If you can return ​an object containing everything you need and just get to it via getSource, do that as it's by far the cleanest. If you can't, pass via context, but make sure it's thread-safe. If your context is a map, use ConcurrentHashMap, if it's an object, make sure the field is volatile or otherwise safe. Since the resolution of a sub-field by definition happens after the parent is resolved, basic thread visibility is all you need.
Johannes Schüth
@Jotschi
May 22 2017 17:16
I think I'll just use a container object as you described. Thanks for the feedback.
Bojan Tomić
@kaqqao
May 22 2017 17:20
No prob. Btw, stating the obvious here, but you can of course just expect extra arguments to blub2 fetcher in the query (and schema) itself.
Johannes Schüth
@Jotschi
May 22 2017 17:21
Yes i know. But I don't want the users of my api to repeat the argument all over the query
Bojan Tomić
@kaqqao
May 22 2017 17:22
Yup, I get it.
Johannes Schüth
@Jotschi
May 22 2017 17:22
That would be a bit much verbose for my taste..
Brad Baker
@bbakerman
May 22 2017 22:31
@Jotschi - note you will passed in the arguments on the DataFetchingEvironment and hence dont need to be stateful with context in your example
    /**
     * @return the arguments that have been passed in via the graphql query
     */
    Map<String, Object> getArguments();
Bojan Tomić
@kaqqao
May 22 2017 22:33
he needs the arguments of the parent field... he won't have access to those in the child field fetcher
Brad Baker
@bbakerman
May 22 2017 22:34
ahh right - interpreted it wrong
Bojan Tomić
@kaqqao
May 22 2017 22:35
no worries :)
btw, is it intentional that the new DataFetcherEnvironment#getSelectionSet returns an empty map when the field is of list type? I'm trying to get how it works...
Brad Baker
@bbakerman
May 22 2017 22:37
the code says
    public static DataFetchingFieldSelectionSet newCollector(ExecutionContext executionContext, GraphQLType fieldType, List<Field> fields) {
        if (fieldType instanceof GraphQLObjectType) {
            return new DataFetchingFieldSelectionSetImpl(executionContext, (GraphQLObjectType) fieldType, fields);
        } else {
            // we can only collect fields on object types.  Scalars, Interfaces, Unions etc... cant be done.
            // we will be called back once they are resolved however
            return NOOP;
        }
    }
but it maybe that we did not unwrap the List / NonNull types from the object and hence this is not correct
I would file a bug
I think it should be fieldType is object or list[object] or non null[object]
Bojan Tomić
@kaqqao
May 22 2017 22:38
that is what I was thinking... sounds like lists and non-null should unwrapped...
also, shouldn't interfaces be there as well?
basically, everything except unions (as they need a condition always, right?), enums and scalars , I'd guess
Brad Baker
@bbakerman
May 22 2017 22:40
perhaps… need to look at it in more detail