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

graphql-java-support: Bump graphql-java to v17.3 #127

Merged
merged 10 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.apollographql.federation.graphqljava;

import static graphql.Directives.DeprecatedDirective;
import static graphql.com.google.common.base.Predicates.not;
import static graphql.introspection.Introspection.DirectiveLocation.ARGUMENT_DEFINITION;
import static graphql.introspection.Introspection.DirectiveLocation.ENUM_VALUE;
import static graphql.introspection.Introspection.DirectiveLocation.FIELD_DEFINITION;
import static graphql.introspection.Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION;
import static graphql.schema.visibility.DefaultGraphqlFieldVisibility.DEFAULT_FIELD_VISIBILITY;
import static graphql.util.EscapeUtil.escapeJsonString;
import static java.util.Optional.ofNullable;
Expand All @@ -11,8 +14,8 @@

import graphql.Assert;
import graphql.PublicApi;
import graphql.execution.ValuesResolver;
import graphql.language.AstPrinter;
import graphql.language.AstValueHelper;
import graphql.language.Description;
import graphql.language.Document;
import graphql.language.EnumTypeDefinition;
Expand Down Expand Up @@ -47,6 +50,8 @@
import graphql.schema.GraphQLUnionType;
import graphql.schema.GraphqlTypeComparatorEnvironment;
import graphql.schema.GraphqlTypeComparatorRegistry;
import graphql.schema.InputValueWithState;
import graphql.schema.idl.DirectiveInfo;
import graphql.schema.idl.ScalarInfo;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
Expand Down Expand Up @@ -74,9 +79,16 @@ public class FederationSdlPrinter {
private static final GraphQLDirective DeprecatedDirective4Printing =
GraphQLDirective.newDirective()
.name("deprecated")
.validLocations(FIELD_DEFINITION, ENUM_VALUE)
.validLocations(FIELD_DEFINITION, ENUM_VALUE, ARGUMENT_DEFINITION, INPUT_FIELD_DEFINITION)
.build();

/**
* This predicate excludes all directives which are specified bt the GraphQL Specification.
* Printing these directives is optional.
*/
public static final Predicate<GraphQLDirective> ExcludeGraphQLSpecifiedDirectivesPredicate =
not(DirectiveInfo::isGraphqlSpecifiedDirective);

/** Options to use when printing a schema */
public static class Options {

Expand Down Expand Up @@ -390,17 +402,17 @@ public Options includeSchemaElement(Predicate<GraphQLSchemaElement> includeSchem
this.includeDirectiveDefinitions,
this.useAstDefinitions,
this.descriptionsAsHashComments,
this.includeDirective,
includeDirective,
this.includeDirectiveDefinition,
this.includeTypeDefinition,
includeSchemaElement,
this.comparatorRegistry);
}

/**
* This flag controls whether schema printer will use the {@link graphql.schema.GraphQLType}'s
* original Ast {@link graphql.language.TypeDefinition}s when printing the type. This allows
* access to any `extend type` declarations that might have been originally made.
* This flag controls whether schema printer will use the {@link GraphQLType}'s original Ast
* {@link TypeDefinition}s when printing the type. This allows access to any `extend type`
* declarations that might have been originally made.
*
* @param flag whether to print via AST type definitions
* @return new instance of options
Expand Down Expand Up @@ -492,9 +504,8 @@ public FederationSdlPrinter(Options options) {
/**
* This can print an in memory GraphQL IDL document back to a logical schema definition. If you
* want to turn a Introspection query result into a Document (and then into a printed schema) then
* use {@link
* graphql.introspection.IntrospectionResultToSchema#createSchemaDefinition(java.util.Map)} first
* to get the {@link graphql.language.Document} and then print that.
* use {@link graphql.introspection.IntrospectionResultToSchema#createSchemaDefinition(Map)} first
* to get the {@link Document} and then print that.
*
* @param schemaIDL the parsed schema IDL
* @return the logical schema definition
Expand Down Expand Up @@ -810,8 +821,8 @@ private TypePrinter<GraphQLInputObjectType> inputObjectPrinter() {
fd -> {
printComments(out, fd, " ");
out.format(" %s: %s", fd.getName(), typeString(fd.getType()));
Object defaultValue = fd.getDefaultValue();
if (defaultValue != null) {
if (fd.hasSetDefaultValue()) {
InputValueWithState defaultValue = fd.getInputFieldDefaultValue();
String astValue = printAst(defaultValue, fd.getType());
out.format(" = %s", astValue);
}
Expand Down Expand Up @@ -854,12 +865,13 @@ private void printAsAst(
out.println();
}

private static String printAst(Object value, GraphQLInputType type) {
return AstPrinter.printAst(AstValueHelper.astFromValue(value, type));
private static String printAst(InputValueWithState value, GraphQLInputType type) {
return AstPrinter.printAst(ValuesResolver.valueToLiteral(value, type));
}

private TypePrinter<GraphQLSchema> schemaPrinter() {
return (out, schema, visibility) -> {
List<GraphQLDirective> schemaDirectives = schema.getSchemaDirectives();
GraphQLObjectType queryType = schema.getQueryType();
GraphQLObjectType mutationType = schema.getMutationType();
GraphQLObjectType subscriptionType = schema.getSubscriptionType();
Expand All @@ -881,7 +893,7 @@ private TypePrinter<GraphQLSchema> schemaPrinter() {
}

if (needsSchemaPrinted) {
out.format("schema {\n");
out.format("schema %s{\n", directivesString(GraphQLSchemaElement.class, schemaDirectives));
if (queryType != null) {
out.format(" query: %s\n", queryType.getName());
}
Expand Down Expand Up @@ -954,8 +966,8 @@ String argsString(Class<? extends GraphQLSchemaElement> parent, List<GraphQLArgu
.append(argument.getName())
.append(": ")
.append(typeString(argument.getType()));
Object defaultValue = argument.getDefaultValue();
if (defaultValue != null) {
if (argument.hasSetDefaultValue()) {
InputValueWithState defaultValue = argument.getArgumentDefaultValue();
sb.append(" = ");
sb.append(printAst(defaultValue, argument.getType()));
}
Expand Down Expand Up @@ -993,7 +1005,9 @@ String directivesString(
return "";
}
StringBuilder sb = new StringBuilder();
sb.append(" ");
if (parent != GraphQLSchemaElement.class) {
sb.append(" ");
}

GraphqlTypeComparatorEnvironment environment =
GraphqlTypeComparatorEnvironment.newEnvironment()
Expand Down Expand Up @@ -1037,16 +1051,20 @@ private String directiveString(GraphQLDirective directive) {
options.comparatorRegistry.getComparator(environment);

List<GraphQLArgument> args = directive.getArguments();
args = args.stream().sorted(comparator).collect(toList());
args =
args.stream()
.filter(arg -> arg.getArgumentValue().isSet() || arg.getArgumentDefaultValue().isSet())
.sorted(comparator)
.collect(toList());
if (!args.isEmpty()) {
sb.append("(");
for (int i = 0; i < args.size(); i++) {
GraphQLArgument arg = args.get(i);
String argValue = null;
if (arg.getValue() != null) {
argValue = printAst(arg.getValue(), arg.getType());
} else if (arg.getDefaultValue() != null) {
argValue = printAst(arg.getDefaultValue(), arg.getType());
if (arg.hasSetValue()) {
argValue = printAst(arg.getArgumentValue(), arg.getType());
} else if (arg.hasSetDefaultValue()) {
argValue = printAst(arg.getArgumentDefaultValue(), arg.getType());
}
if (!isNullOrEmpty(argValue)) {
sb.append(arg.getName());
Expand Down Expand Up @@ -1154,6 +1172,10 @@ public String print(GraphQLType type) {
return sw.toString();
}

public String print(GraphQLDirective graphQLDirective) {
return directiveDefinition(graphQLDirective);
}

private void printType(
PrintWriter out,
List<GraphQLType> typesAsList,
Expand Down Expand Up @@ -1204,7 +1226,11 @@ private void printMultiLineHashDescription(PrintWriter out, String prefix, List<

private void printMultiLineDescription(PrintWriter out, String prefix, List<String> lines) {
out.printf("%s\"\"\"\n", prefix);
lines.forEach(l -> out.printf("%s%s\n", prefix, l));
lines.forEach(
l -> {
String escapedTripleQuotes = l.replaceAll("\"\"\"", "\\\\\"\"\"");
out.printf("%s%s\n", prefix, escapedTripleQuotes);
});
out.printf("%s\"\"\"\n", prefix);
}

Expand Down
46 changes: 3 additions & 43 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@
-->
<skip.dependency.convergence>false</skip.dependency.convergence>
<cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version>
<graphql-java.version>16.1</graphql-java.version>
<graphql-java-kickstart.version>11.0.0</graphql-java-kickstart.version>
<graphql-java.version>17.3</graphql-java.version>
<java.version>1.8</java.version>
<jetbrains-annotations.version>17.0.0</jetbrains-annotations.version>
<junit.version>5.7.1</junit.version>
<junit.version>5.7.2</junit.version>
<!-- Can't upgrade to 3.2.X until https://issues.apache.org/jira/browse/MDEP-753 is fixed. -->
<maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
<!--
Expand All @@ -93,35 +92,12 @@
<maven-source-plugin.version>3.1.0</maven-source-plugin.version>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>
<slf4j.version>1.7.30</slf4j.version>
<slf4j.version>1.7.32</slf4j.version>
<spotless.version>2.12.2</spotless.version>
<spring-boot.version>2.3.6.RELEASE</spring-boot.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>${graphql-java-kickstart.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>${graphql-java-kickstart.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter-test</artifactId>
<version>${graphql-java-kickstart.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>${graphql-java-kickstart.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
Expand All @@ -144,22 +120,6 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
54 changes: 50 additions & 4 deletions spring-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,54 @@
<description>Spring Boot example of federation-graphql-java-support usage</description>

<properties>
<graphql-java-kickstart.version>11.1.0</graphql-java-kickstart.version>
<graphql-java-tools.version>11.1.2</graphql-java-tools.version>
<!-- Note that spring-example wasn't designed to be imported, so this is fine. -->
<skip.dependency.convergence>true</skip.dependency.convergence>
<fasterxml.jackson.version>2.12.0</fasterxml.jackson.version>
<fasterxml.jackson.version>2.12.5</fasterxml.jackson.version>
<spring-boot.version>2.5.4</spring-boot.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>${graphql-java-kickstart.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>${graphql-java-kickstart.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter-test</artifactId>
<version>${graphql-java-kickstart.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>${graphql-java-tools.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>
<!--
The following dependencies exist solely to override Maven's default "nearest first" strategy for transitive
dependency version conflict resolution. Note that as stated in the parent POM, we would normally use Maven
Expand All @@ -49,10 +90,15 @@
<artifactId>jackson-datatype-jdk8</artifactId>
<version>${fasterxml.jackson.version}</version>
</dependency>
<!--
There is a bug in com.graphql-java-kickstart:graphql-spring-boot-starter:11.1.0 where it depends on
artifact com.graphql-java:graphql-java-extended-scalars:16.0.1, but it really needs 17.0. This forces
us to a later version.
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.2.11.RELEASE</version>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-extended-scalars</artifactId>
<version>17.0</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down