Repository navigation
Conversation
|
Early morning here... Just read your description. Definitely sounds like an improvement from my perspective, as I can (still) easily adjust my implementation and the present one is sort of dangerous for anyone who may ned up having a recursive schema. Will test very soon (but maybe not today exactly - will try). Question though: Why do you need to "pre-normalize" at all? To me it seems that we, the |
Today the algorithm of graphql-java execution is based on the simple reference implementation A breath first descent of the AST tree. However over the years we have learnt new ways of executing queries that may be more powerful for some use cases. For example if we have a better "tree representation of the query (with types and arg values all pre rendered and resolved) then we could write an engine that did batching better. At Atlassian we are writing a graphql gateway that doesnt execute queries per se but pulls them apart and feeds them onto underlying systems We have learnt that a more optimised representation of the query allows for the engine to be easy to write and performs better. This is where the original NormalisedQuery work came from. We then learnt that the original implementation can explode out into millions of tree entries on certain schemas. So this is revisiting those early decisions Imagine we could store that in a DB - we have a pre built query ready to execute - imagine we passed not query AST to an underlying graphql service, bit partial NormalisedQuery structures say. This is en evolution to a state where perhaps a graphql query is not parsed AST but in fact a pre built NormalisedQuery with all the types and args resolved. |
| public GraphQLFieldDefinition getFieldDefinition() { | ||
| return normalizedField.getFieldDefinition(); | ||
| public List<String> getObjectTypeNames() { | ||
| return new ArrayList<>(normalizedField.getObjectTypeNames()); |
There was a problem hiding this comment.
ImmutableList.of() - no allocation if its immutable I think
There was a problem hiding this comment.
public static <E> ImmutableList<E> copyOf(Collection<? extends E> elements) {
if (elements instanceof ImmutableCollection) {
ImmutableList<E> list = ((ImmutableCollection)elements).asList();
return list.isPartialView() ? asImmutableList(list.toArray()) : list;
} else {
return construct(elements.toArray());
}
}
Yup no allocation on immutable collections
There was a problem hiding this comment.
unfortunately object types names is a mutable Set (on purpose)
| return TraversalControl.CONTINUE; | ||
| } | ||
| }); | ||
| return result; |
There was a problem hiding this comment.
Should something like this go on NormalisedQuery itself??
There was a problem hiding this comment.
maybe yes ... but I will not do it now.
bbakerman
left a comment
There was a problem hiding this comment.
I think we should do one more pass on Immutable structures here. This will improve the memory profile of this even more
Also dont rely on the iterator.next trick. (Ahh is it a Set ....maybe you have to)
What I am doing with Note that for every exposed type I have my own "mapping metadata". I also keep a graph of all types with links to their immediate/direct sub- and super-types and also have fast means to find all (not only immediate/direct) sub- and super-types as well. I can check type relationships, property declarations and inheritance, etc. very quickly. I can tell you exactly in which types a property exists in nanonseconds. Sure, this takes some memory but only "once" (per schema). |
This changes NormalizedFields to contain a list of Object type names and not just one.
The main reason for this change change is to avoid an explosion of normalized Fields when you have Interfaces implemented by many Objects. This could lead to a huge amount of normalized fields, which had significant performant impact in certain cases.
It also aligns a NormalizedField more closely with what most people expect:
For example a schema
and this query:
{pets{name}}the normalized query would contain three fields: for each Object implementing Pet one field:
Dog.nameandCat.name. Now it is only one field referencing both:[Dog, Cat].name.Breaking Changes for DataFetchingFieldSelectionSet
As a consequence the API of
DataFetchingFieldSelectionSetandSelectionSetchanged.SelctionSetwas changed to reflect multiple objects now.The API of
DataFetchingFieldSelectionSetdidn't change but the fully qualified names of aSelectionSetnow contains a List of objects if there is more than one: e.g.[Dog, Cat].nameinstead ofDog.nameandCat.name.This means some glob pattern may not work anymore as before. For example to match any
Catnamefield you need now a*Cat*.nameinstead ofCat.name.