Skip to content

Query generator #3979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 1, 2025
Merged

Query generator #3979

merged 16 commits into from
Jun 1, 2025

Conversation

felipe-gdr
Copy link
Member

A little utility function that allows people to generate queries for a certain type.

This will be useful for a use case I'm working on at the moment, where I need to generate test queries that contain as many fields as possible.

The generated-query-for-extra-large-schema-1.graphql file contains an example of a generated query for a somewhat complex type.

Let me know what y'all think!


import java.util.function.Predicate;

public class QueryGeneratorOptions {
Copy link
Member

Choose a reason for hiding this comment

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

@Expimental

this.filterFieldDefinitionPredicate = filterFieldDefinitionPredicate;
}

public int getMaxFieldCount() {
Copy link
Member

Choose a reason for hiding this comment

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

java doc

return maxFieldCount;
}

public Predicate<GraphQLFieldsContainer> getFilterFieldContainerPredicate() {
Copy link
Member

Choose a reason for hiding this comment

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

java doc

import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

public class QueryGeneratorFieldSelection {
Copy link
Member

Choose a reason for hiding this comment

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

@ExperimentlApi

public String generateQuery(
String operationFieldPath,
@Nullable String operationName,
@Nullable String arguments,
Copy link
Member

Choose a reason for hiding this comment

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

javadoc

I am unsure what arguments and typeClassifier mean

@@ -0,0 +1,82 @@
package graphql.util.querygenerator;

import com.google.common.base.Predicates;
Copy link
Member

Choose a reason for hiding this comment

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

We have a checker in the build to look for new Guava imports, and we prefer to not add new imports.

Is it possible to use the plain Java version of this instead?

@felipe-gdr felipe-gdr requested review from bbakerman and dondonz May 22, 2025 01:07
@felipe-gdr
Copy link
Member Author

Thanks @bbakerman and @dondonz I addressed your comments.

import graphql.schema.GraphQLSchema;
import graphql.schema.GraphQLUnionType;

import javax.annotation.Nullable;
Copy link
Member

Choose a reason for hiding this comment

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

Small one: could you change this to be the JSpecify Nullable annotation, rather than javax?

I'll amend the ArchUnit test so this gets automatically picked up in future

Copy link
Member Author

Choose a reason for hiding this comment

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

Done ;-)

Out of curiosity: what's the advantage of the JSpecify version of Nullable when compared to the native one?

Copy link
Member

Choose a reason for hiding this comment

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

Yep good question, it is only an annotation at the end of the day so there isn't inherently something "new" about JSpecify's "implementation", but the advantage is that it has become a standard because all the big industry players are behind it. For example, Spring have formally adopted it, even at work JSpecify (& NullAway) will soon become a standard.

@dondonz dondonz added this to the 25.x breaking changes milestone May 23, 2025
Copy link
Member

@dondonz dondonz left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@dondonz dondonz merged commit 19387ff into graphql-java:master Jun 1, 2025
1 check passed
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.

3 participants