Skip to content

improve query traversal and make it public#1031

Merged
andimarek merged 17 commits intomasterfrom
query-traversal-improvements
Jun 3, 2018
Merged

improve query traversal and make it public#1031
andimarek merged 17 commits intomasterfrom
query-traversal-improvements

Conversation

@andimarek
Copy link
Copy Markdown
Member

@andimarek andimarek commented May 4, 2018

This makes QueryTraversal public (it was internal before)
and improves it by having an arbitrary Node as root (not only the DocumentDefintion) and adds the SelectionSetContainer to the environment.

@andimarek andimarek requested a review from bbakerman May 4, 2018 04:00
@andimarek andimarek force-pushed the query-traversal-improvements branch from c9b2c8e to ac379fb Compare May 4, 2018 05:09
@andimarek andimarek added this to the 9.0 milestone May 4, 2018
@andimarek andimarek changed the title improve query traversal and make it public NOT READY - improve query traversal and make it public May 4, 2018
/**
* @return a deep copy of this selection
*/
T deepCopy();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this dissapear??

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it is declared in the super interface already ... just a clean up :-)

@andimarek andimarek changed the title NOT READY - improve query traversal and make it public improve query traversal and make it public May 22, 2018
@bbakerman
Copy link
Copy Markdown
Member

Are you really going to put this in 9.0 Its marked as such

QueryVisitorEnvironment thisNodeAsParent = new QueryVisitorEnvironment(env.getField(), env.getFieldDefinition(), env.getParentType(), env.getParentEnvironment(), env.getArguments());
if (valuesByParent.containsKey(thisNodeAsParent)) {
childsComplexity = valuesByParent.get(thisNodeAsParent).stream().mapToInt(Integer::intValue).sum();
Map<QueryVisitorFieldEnvironment, List<Integer>> valuesByParent = new LinkedHashMap<>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put a builder on QueryVisitorFieldEnvironment. It will allow it to evolve more easily over time.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I extracted an Interface instead.


T reduceField(QueryVisitorEnvironment reducerEnvironment, T acc);
T reduceField(QueryVisitorFieldEnvironment reducerEnvironment, T acc);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaDoc??

private final ChildrenOfSelectionProvider childrenOfSelectionProvider;
private final GraphQLObjectType rootParentType;

public QueryTraversal(GraphQLSchema schema,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a Builder on this and make the constructor private. This allows for better API evolution over time

Copy link
Copy Markdown
Member Author

@andimarek andimarek May 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mh ... I get your point but the arguments are mutually exclusive: for example operation is only valid with a Document, same with root and rooParentType etc.

Is it worth extracting a whole QueryTraversalBuilder? Other options?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think generally the graphql-java should use builders on PublicAPI elements because without it the constructor becomes public API and over loading is your only way to construct things

In this case I would do QueryTraversal.newQueryTraversal() and have an internal builder of them


import graphql.PublicApi;

@PublicApi
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaDoc??

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you talk about order here?? pre order etc...??

return "QueryVisitorFieldEnvironment{" +
"field=" + field +
", fieldDefinition=" + fieldDefinition +
", parentType=" + parentType +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a builder

return Objects.hash(fragmentSpread);
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a Builder

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted an Interface

import graphql.PublicApi;

@PublicApi
public class QueryVisitorStub implements QueryVisitor {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to do this in Java 8 is just use default methods on the interface.

I am still 50/50 on whether this is a good idea.

I do like your naming here. Better than NoopFoo

import graphql.TestUtil
import graphql.language.Document
import graphql.language.*
import graphql.parser.Parser
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • import???

Copy link
Copy Markdown
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add Builders to the places where a consumer is expected to create an object

this.rootParentType = getRootTypeFromOperation(getOperationResult.operationDefinition);
this.childrenOfSelectionProvider = new ChildrenOfSelectionProvider(fragmentsByName);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without a builder the constructor is public SPI

// {foo}
// """)
// def root = new Field()

Copy link
Copy Markdown
Member

@bbakerman bbakerman Jun 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want this commented out??? I would remove it

@andimarek andimarek merged commit 3c44f06 into master Jun 3, 2018
@andimarek andimarek deleted the query-traversal-improvements branch June 6, 2018 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants