Skip to content
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

Changes in schema directive printing AND the comment formats #1609

Merged

Conversation

bbakerman
Copy link
Member

See #1587

Will now ONLY show descriptions (and never captured comments other than ones turned into descriptions by SchemaGen

@bbakerman bbakerman requested a review from andimarek July 22, 2019 08:08
@@ -62,17 +62,27 @@

static {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated comment.

Is there a reason for this to be in a static block versus just building it directly into the static variable using the builder, for example:

static final DirectiveDefinition DEPRECATED_DIRECTIVE_DEFINITION = DirectiveDefinition.newDirectiveDefinition().name("deprecated")
    .directiveLocation(createLocation(DirectiveLocation.FIELD_DEFINITION))
    ...
    .inputValueDefinition(...)
    .build();

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah not sure - looks like it could have been a chained builder call.

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

@@ -113,6 +115,24 @@ class SchemaPrinterTest extends Specification {
argStr == "(arg1: [Int!] = 10, arg2: String, arg3: String = \"default\")"
}

def "argsString_comments"() {
def argument1 = new GraphQLArgument("arg1", "A multiline\ncomment", list(nonNull(Scalars.GraphQLInt)), 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we support new line characters for window systems? \r\n

Copy link
Member Author

Choose a reason for hiding this comment

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

Nominally yes - but we build and dev on Mac / Linux only. That is we dont run the tests on Windows per se.

I have forgotten my \n rules on Windows but for some reason I recall it working as expected in many circumstances

src/main/java/graphql/schema/GraphQLSchema.java Outdated Show resolved Hide resolved
src/main/java/graphql/schema/idl/SchemaPrinter.java Outdated Show resolved Hide resolved
src/main/java/graphql/schema/idl/SchemaPrinter.java Outdated Show resolved Hide resolved
out.format(" %s%s\n", enumValueDefinition.getName(), directivesString(GraphQLEnumValueDefinition.class, enumValueDefinition.getDirectives()));
List<GraphQLDirective> enumValueDirectives = enumValueDefinition.getDirectives();
if (enumValueDefinition.isDeprecated()) {
enumValueDirectives = addDeprecatedDirectiveIfNeeded(enumValueDirectives);
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you have this private method to help adding the deprecated directive to the list if it does not exist. Is there a reason why this is a list instead of a set in which case this private method wouldn't be needed.

@@ -458,7 +511,7 @@ private static String printAst(Object value, GraphQLInputType type) {

// when serializing a GraphQL schema using the type system language, a
// schema definition should be omitted if only uses the default root type names.
boolean needsSchemaPrinted = options.includeSchemaDefinition;
boolean needsSchemaPrinted = options.isIncludeSchemaDefinition();
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for adding the is at the start, seems to flow easier without it.

Copy link
Member Author

Choose a reason for hiding this comment

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

one was a field - this is now the public method. Not sure why I changed it. Consistency elsewhere?? Not sure

private boolean hasDeprecatedDirective(List<GraphQLDirective> directives) {
return directives.stream()
.filter(this::isDeprecatedDirective)
.count() == 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Considering this is a list and not a set, can we ever have count > 1, in which case should this be count() >= 1 to work for all these scenarios? Or have we built enough invariants for this class that this shouldn't happen?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm good point - the rest of the code base puts List<GraphQLDirective> everywhere and hence its influenced this code as well

I think other parts of the code stop multiple named directives

}

private AstDescriptionAndComments getDescriptionAndComments(Object descriptionHolder) {
private String getDescription(Object descriptionHolder) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be a static function? does it need references to this?

Copy link
Member Author

Choose a reason for hiding this comment

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

could be - but almost no other method is static in this class - so its consistent in that regard

bbakerman and others added 5 commits September 7, 2019 16:25
Co-Authored-By: Jaiden Ashmore <jaidenkyleashmore@gmail.com>
Co-Authored-By: Jaiden Ashmore <jaidenkyleashmore@gmail.com>
Co-Authored-By: Jaiden Ashmore <jaidenkyleashmore@gmail.com>
@andimarek andimarek added the breaking change requires a new major version to be relased label Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change requires a new major version to be relased
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants