Repository navigation
How to work around a significant DataFetchingFieldSelectionSet performance issue with many types #2309
|
Hi! I am playing with GraphQL-Java and have had really good progress really fast. Perhaps too fast. I've landed on an issue where Yes, this is "deep" but quite a simple query otherwise. My gut feeling about what sets this off is that we have over a hundred various types (interfaces and objects) that any parent can be be of and I haven't found a way to simply ask for "give me what is stated, don't try to resolve this to per-type fields" which causes huge repetition - each field is listed many times, one per type it exists in, for all possible types, at each level. I cannot change the data model - this is a complex, large application and the types in it exist for good reasons. Dividing this time into smaller chunks wouldn't be helpful either, as it would still be spent, just differently. How can I get what is requested by the client at "face value" and no processing/resolving at all? |
Replies: 12 comments 4 replies
|
Can you please share you schema? If you don't want to share it publicly please have a look at https://github.com/graphql-java/graphql-anonymizer. Thanks |
|
Here. |
|
Can you also please share the query you are executing? |
|
Note that the schema is built programmatically. What I attached is the anonymized version of what IntelliJ IDEA GraphQL plugin obtains from the servlet. The query is at the bottom, I did anonymize it too. |
|
It is at the bottom of the file: |
|
I have some means to generate the schema differently but the type hierarchy is extensive. I presently convert concrete leaf types to GraphQL object types and all others are interfaces. My code is trying to do what is described here: https://www.graphql-java.com/blog/deep-dive-merged-fields/ ... at large scale. I already have the code that prefetches everything it needs upfront... but is held up / delayed by getImmediateFields(). If it helps, the code is roughly (unrolled from actual): |
|
Note - I am trying to rework the schema a bit so that the collection fields use more specific types. That isn't trivial as many types are navigable from many others (i.e. it is a many-to-many type-to-type relationship). This will actually essentially triple the number of GraphQL schema over what I really have in the system but each field will only yield a smaller subset. That subset may still be significant, but will be lesser than what you can see in this schema. I think that should help a bit but it may not be enough. I could try to help but I am anxious about doing so as I don't know enough about what is going on in there and this feels like it is important enough to get done "right" having in mind whatever future you have envisioned for this... |
|
Any suggestions here? I did attempt to focus/constrain the relationships but there are multiple kinds of them that would require that and I only did one. How can I get a field selection without having it normalized? |
|
After constraining relationships, now my proof of concept is facing a different issue. I need to be able to specify subtypes to access some properties, i.e.: {
things {
id
parent {
id
name
... on ParentSubtype1 {
subtypeOnlyField1
subtypeOnlyField2
}
}
}
}But I don't know how to get the information as presented. I'd expect/like the equivalent of a collection/map as follows: 1. Properties requested for the base type - immediate ... on ParentBaseType { # implied
id
name
}2. Properties requested for the ... on ParentSubtype1 {
subtypeOnlyField1
subtypeOnlyField2
}... and not a "normalized" exploded version that I am able to get (imagine if parent {
# id
... on ParentBaseType { id }
# ... then repeated for all subypes of ParentBaseType...
... on ParentSubtype1 { id }
... on ParentSubtype2 { id }
#...
... on ParentSubtypeN { id }
# name
... on ParentBaseType { name }
# ... then repeated for all subypes of ParentBaseType...
... on ParentSubtype1 { name }
... on ParentSubtype2 { name }
#...
... on ParentSubtypeN { name }
# ... on ParentSubtype1 { subtypeOnlyField1 }
... on ParentSubtype1 { subtypeOnlyField1 }
# ... then repeated for all subypes of ParentSubtype1...
... on ParentSubtype3 { subtypeOnlyField1 }
#...
... on ParentSubtypeX { subtypeOnlyField1 }
# ... on ParentSubtype1 { subtypeOnlyField2 }
... on ParentSubtype1 { subtypeOnlyField2 }
# ... then repeated for all subypes of ParentSubtype1...
... on ParentSubtype3 { subtypeOnlyField2 }
#...
... on ParentSubtypeX { subtypeOnlyField2 }
} |



Seems related: #2185