From e2adacc3d4903291477380e7613b361f9f528cb3 Mon Sep 17 00:00:00 2001 From: Davide Angelocola Date: Sun, 30 Oct 2022 11:26:55 +0100 Subject: [PATCH 1/2] ImmutableKit cleanups - adding @SafeVarargs to ImmutableKit - dropping unused methods --- .../java/graphql/collect/ImmutableKit.java | 31 ++----------------- .../graphql/collect/ImmutableKitTest.groovy | 8 ----- 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/src/main/java/graphql/collect/ImmutableKit.java b/src/main/java/graphql/collect/ImmutableKit.java index 670869695..af74316b6 100644 --- a/src/main/java/graphql/collect/ImmutableKit.java +++ b/src/main/java/graphql/collect/ImmutableKit.java @@ -27,39 +27,10 @@ public static ImmutableMap emptyMap() { return ImmutableMap.of(); } - /** - * ImmutableMaps are hard to build via {@link Map#computeIfAbsent(Object, Function)} style. This method - * allows you to take a mutable map with mutable list of keys and make it immutable. - *

- * This of course has a cost - if the map is very large you will be using more memory. But for static - * maps that live a long life it maybe be worth it. - * - * @param startingMap the starting input map - * @param for key - * @param for victory - * - * @return and Immutable map of ImmutableList values - */ - - public static ImmutableMap> toImmutableMapOfLists(Map> startingMap) { - assertNotNull(startingMap); - ImmutableMap.Builder> map = ImmutableMap.builder(); - for (Map.Entry> e : startingMap.entrySet()) { - ImmutableList value = ImmutableList.copyOf(startingMap.getOrDefault(e.getKey(), emptyList())); - map.put(e.getKey(), value); - } - return map.build(); - } - - public static ImmutableMap addToMap(Map existing, K newKey, V newVal) { return ImmutableMap.builder().putAll(existing).put(newKey, newVal).build(); } - public static ImmutableMap mergeMaps(Map m1, Map m2) { - return ImmutableMap.builder().putAll(m1).putAll(m2).build(); - } - public static ImmutableList concatLists(List l1, List l2) { //noinspection UnstableApiUsage return ImmutableList.builderWithExpectedSize(l1.size() + l2.size()).addAll(l1).addAll(l2).build(); @@ -123,6 +94,7 @@ public static ImmutableList mapAndDropNulls(Iterable iter * * @return an Immutable list with the extra items. */ + @SafeVarargs public static ImmutableList addToList(Collection existing, T newValue, T... extraValues) { assertNotNull(existing); assertNotNull(newValue); @@ -147,6 +119,7 @@ public static ImmutableList addToList(Collection existing, T * * @return an Immutable Set with the extra items. */ + @SafeVarargs public static ImmutableSet addToSet(Collection existing, T newValue, T... extraValues) { assertNotNull(existing); assertNotNull(newValue); diff --git a/src/test/groovy/graphql/collect/ImmutableKitTest.groovy b/src/test/groovy/graphql/collect/ImmutableKitTest.groovy index e2fb0dfde..82d76bae1 100644 --- a/src/test/groovy/graphql/collect/ImmutableKitTest.groovy +++ b/src/test/groovy/graphql/collect/ImmutableKitTest.groovy @@ -13,14 +13,6 @@ class ImmutableKitTest extends Specification { ImmutableKit.emptyMap().size() == 0 } - def "can make an immutable map of lists"() { - when: - ImmutableMap> map = ImmutableKit.toImmutableMapOfLists([a: ["a", "A"]]) - then: - map.get("a") == ImmutableList.copyOf(["a", "A"]) - map.get("a") instanceof ImmutableList - } - def "can map a collections"() { when: def outputList = ImmutableKit.map(["quick", "brown", "fox"], { word -> word.reverse() }) From 6a753733683f18865b8c2d97e01cb80d72931bd4 Mon Sep 17 00:00:00 2001 From: Davide Angelocola Date: Sun, 30 Oct 2022 11:38:59 +0100 Subject: [PATCH 2/2] Migrating links to the spec to https://spec.graphql.org/October2021 --- src/main/java/graphql/ExecutionResult.java | 2 +- src/main/java/graphql/GraphQLError.java | 2 +- src/main/java/graphql/Scalars.java | 12 ++++++------ src/main/java/graphql/execution/Execution.java | 6 +++--- .../java/graphql/execution/ExecutionContext.java | 2 +- .../java/graphql/execution/ExecutionStrategy.java | 4 ++-- .../graphql/execution/NonNullableFieldValidator.java | 6 +++--- .../execution/NonNullableFieldWasNullException.java | 2 +- src/main/java/graphql/schema/GraphQLScalarType.java | 4 ++-- .../schema/impl/GraphQLTypeCollectingVisitor.java | 2 +- .../validation/rules/UniqueOperationNames.java | 2 +- src/test/groovy/graphql/NullValueSupportTest.groovy | 2 +- .../graphql/validation/SpecValidation282Test.groovy | 2 +- .../graphql/validation/SpecValidation51Test.groovy | 2 +- .../graphql/validation/SpecValidation562Test.groovy | 2 +- .../graphql/validation/SpecValidation573Test.groovy | 2 +- .../graphql/validation/SpecValidationBase.groovy | 2 +- .../graphql/validation/SpecValidationSchema.java | 2 +- .../validation/SpecValidationSchemaPojos.java | 2 +- src/test/groovy/readme/ReadmeExamples.java | 2 +- 20 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main/java/graphql/ExecutionResult.java b/src/main/java/graphql/ExecutionResult.java index c05251ecc..4870144fe 100644 --- a/src/main/java/graphql/ExecutionResult.java +++ b/src/main/java/graphql/ExecutionResult.java @@ -50,7 +50,7 @@ public interface ExecutionResult { * should be present. Certain JSON serializers may or may interpret {@link ExecutionResult} to spec, so this method * is provided to produce a map that strictly follows the specification. * - * See : http://facebook.github.io/graphql/#sec-Response-Format + * See : https://spec.graphql.org/October2021/#sec-Response-Format * * @return a map of the result that strictly follows the spec */ diff --git a/src/main/java/graphql/GraphQLError.java b/src/main/java/graphql/GraphQLError.java index 69873b591..74534bca6 100644 --- a/src/main/java/graphql/GraphQLError.java +++ b/src/main/java/graphql/GraphQLError.java @@ -38,7 +38,7 @@ public interface GraphQLError extends Serializable { /** * The graphql spec says that the (optional) path field of any error should be a list - * of path entries - http://facebook.github.io/graphql/#sec-Errors + * of path entries https://spec.graphql.org/October2021/#sec-Handling-Field-Errors * * @return the path in list format */ diff --git a/src/main/java/graphql/Scalars.java b/src/main/java/graphql/Scalars.java index 91754f568..4a72d248c 100644 --- a/src/main/java/graphql/Scalars.java +++ b/src/main/java/graphql/Scalars.java @@ -13,13 +13,13 @@ * by the graphql specification (Int, Float, String, Boolean and ID) while others are offer because they are common on * Java platforms. *

- * For more info see http://graphql.org/learn/schema/#scalar-types and more specifically http://facebook.github.io/graphql/#sec-Scalars + * For more info see http://graphql.org/learn/schema/#scalar-types and more specifically https://spec.graphql.org/October2021/#sec-Scalars */ @PublicApi public class Scalars { /** - * This represents the "Int" type as defined in the graphql specification : http://facebook.github.io/graphql/#sec-Int + * This represents the "Int" type as defined in the graphql specification : https://spec.graphql.org/October2021/#sec-Int *

* The Int scalar type represents a signed 32‐bit numeric non‐fractional value. */ @@ -27,7 +27,7 @@ public class Scalars { .name("Int").description("Built-in Int").coercing(new GraphqlIntCoercing()).build(); /** - * This represents the "Float" type as defined in the graphql specification : http://facebook.github.io/graphql/#sec-Float + * This represents the "Float" type as defined in the graphql specification : https://spec.graphql.org/October2021/#sec-Float *

* Note: The Float type in GraphQL is equivalent to Double in Java. (double precision IEEE 754) */ @@ -35,19 +35,19 @@ public class Scalars { .name("Float").description("Built-in Float").coercing(new GraphqlFloatCoercing()).build(); /** - * This represents the "String" type as defined in the graphql specification : http://facebook.github.io/graphql/#sec-String + * This represents the "String" type as defined in the graphql specification : https://spec.graphql.org/October2021/#sec-String */ public static final GraphQLScalarType GraphQLString = GraphQLScalarType.newScalar() .name("String").description("Built-in String").coercing(new GraphqlStringCoercing()).build(); /** - * This represents the "Boolean" type as defined in the graphql specification : http://facebook.github.io/graphql/#sec-Boolean + * This represents the "Boolean" type as defined in the graphql specification : https://spec.graphql.org/October2021/#sec-Boolean */ public static final GraphQLScalarType GraphQLBoolean = GraphQLScalarType.newScalar() .name("Boolean").description("Built-in Boolean").coercing(new GraphqlBooleanCoercing()).build(); /** - * This represents the "ID" type as defined in the graphql specification : http://facebook.github.io/graphql/#sec-ID + * This represents the "ID" type as defined in the graphql specification : https://spec.graphql.org/October2021/#sec-ID *

* The ID scalar type represents a unique identifier, often used to re-fetch an object or as the key for a cache. The * ID type is serialized in the same way as a String; however, it is not intended to be human‐readable. While it is diff --git a/src/main/java/graphql/execution/Execution.java b/src/main/java/graphql/execution/Execution.java index f7e97ed77..e09f13ada 100644 --- a/src/main/java/graphql/execution/Execution.java +++ b/src/main/java/graphql/execution/Execution.java @@ -155,12 +155,12 @@ private CompletableFuture executeOperation(ExecutionContext exe } result = executionStrategy.execute(executionContext, parameters); } catch (NonNullableFieldWasNullException e) { - // this means it was non null types all the way from an offending non null type - // up to the root object type and there was a a null value some where. + // this means it was non-null types all the way from an offending non-null type + // up to the root object type and there was a null value somewhere. // // The spec says we should return null for the data in this case // - // http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability + // https://spec.graphql.org/October2021/#sec-Handling-Field-Errors // result = completedFuture(new ExecutionResultImpl(null, executionContext.getErrors())); } diff --git a/src/main/java/graphql/execution/ExecutionContext.java b/src/main/java/graphql/execution/ExecutionContext.java index 26f4b575b..9c1aa2032 100644 --- a/src/main/java/graphql/execution/ExecutionContext.java +++ b/src/main/java/graphql/execution/ExecutionContext.java @@ -189,7 +189,7 @@ public ValueUnboxer getValueUnboxer() { public void addError(GraphQLError error, ResultPath fieldPath) { synchronized (this) { // - // see http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability about how per + // see https://spec.graphql.org/October2021/#sec-Handling-Field-Errors about how per // field errors should be handled - ie only once per field if it's already there for nullability // but unclear if it's not that error path // diff --git a/src/main/java/graphql/execution/ExecutionStrategy.java b/src/main/java/graphql/execution/ExecutionStrategy.java index 2286192af..81e4756dc 100644 --- a/src/main/java/graphql/execution/ExecutionStrategy.java +++ b/src/main/java/graphql/execution/ExecutionStrategy.java @@ -106,7 +106,7 @@ * and the other "completeXXX" methods. *

* The order of fields fetching and completion is up to the execution strategy. As the graphql specification - * http://facebook.github.io/graphql/#sec-Normal-and-Serial-Execution says: + * https://spec.graphql.org/October2021/#sec-Normal-and-Serial-Execution says: *

* Normally the executor can execute the entries in a grouped field set in whatever order it chooses (often in parallel). Because * the resolution of fields other than top-level mutation fields must always be side effect-free and idempotent, the @@ -746,7 +746,7 @@ protected GraphQLFieldDefinition getFieldDef(GraphQLSchema schema, GraphQLObject } /** - * See (...), + * See (...), *

* If a non nullable child field type actually resolves to a null value and the parent type is nullable * then the parent must in fact become null diff --git a/src/main/java/graphql/execution/NonNullableFieldValidator.java b/src/main/java/graphql/execution/NonNullableFieldValidator.java index 73f4f531a..af26b6900 100644 --- a/src/main/java/graphql/execution/NonNullableFieldValidator.java +++ b/src/main/java/graphql/execution/NonNullableFieldValidator.java @@ -4,10 +4,10 @@ import graphql.Internal; /** - * This will check that a value is non null when the type definition says it must be and it will throw {@link NonNullableFieldWasNullException} + * This will check that a value is non-null when the type definition says it must be and, it will throw {@link NonNullableFieldWasNullException} * if this is not the case. * - * See: http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability + * See: https://spec.graphql.org/October2021/#sec-Errors-and-Non-Nullability */ @Internal public class NonNullableFieldValidator { @@ -34,7 +34,7 @@ public NonNullableFieldValidator(ExecutionContext executionContext, ExecutionSte public T validate(ResultPath path, T result) throws NonNullableFieldWasNullException { if (result == null) { if (executionStepInfo.isNonNullType()) { - // see http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability + // see https://spec.graphql.org/October2021/#sec-Errors-and-Non-Nullability // // > If the field returns null because of an error which has already been added to the "errors" list in the response, // > the "errors" list must not be further affected. That is, only one error should be added to the errors list per field. diff --git a/src/main/java/graphql/execution/NonNullableFieldWasNullException.java b/src/main/java/graphql/execution/NonNullableFieldWasNullException.java index d21893ef2..87324bb00 100644 --- a/src/main/java/graphql/execution/NonNullableFieldWasNullException.java +++ b/src/main/java/graphql/execution/NonNullableFieldWasNullException.java @@ -7,7 +7,7 @@ import static graphql.schema.GraphQLTypeUtil.simplePrint; /** - * See (http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability), but if a non nullable field + * See (https://spec.graphql.org/October2021/#sec-Errors-and-Non-Nullability), but if a non nullable field * actually resolves to a null value and the parent type is nullable then the parent must in fact become null * so we use exceptions to indicate this special case */ diff --git a/src/main/java/graphql/schema/GraphQLScalarType.java b/src/main/java/graphql/schema/GraphQLScalarType.java index b0443281e..137a6047c 100644 --- a/src/main/java/graphql/schema/GraphQLScalarType.java +++ b/src/main/java/graphql/schema/GraphQLScalarType.java @@ -28,7 +28,7 @@ * for example, a GraphQL system could define a scalar called Time which, while serialized as a string, promises to * conform to ISO‐8601. When querying a field of type Time, you can then rely on the ability to parse the result with an ISO‐8601 parser and use a client‐specific primitive for time. *

- * From the spec : http://facebook.github.io/graphql/#sec-Scalars + * From the spec : https://spec.graphql.org/October2021/#sec-Scalars *

*

* graphql-java ships with a set of predefined scalar types via {@link graphql.Scalars} @@ -301,4 +301,4 @@ public GraphQLScalarType build() { specifiedByUrl); } } -} \ No newline at end of file +} diff --git a/src/main/java/graphql/schema/impl/GraphQLTypeCollectingVisitor.java b/src/main/java/graphql/schema/impl/GraphQLTypeCollectingVisitor.java index 7da9ab1f8..79116a6df 100644 --- a/src/main/java/graphql/schema/impl/GraphQLTypeCollectingVisitor.java +++ b/src/main/java/graphql/schema/impl/GraphQLTypeCollectingVisitor.java @@ -134,7 +134,7 @@ private void save(String name, GraphQLNamedType type) { /* - From http://facebook.github.io/graphql/#sec-Type-System + From https://spec.graphql.org/October2021/#sec-Type-System All types within a GraphQL schema must have unique names. No two provided types may have the same name. No provided type may have a name which conflicts with any built in types (including Scalar and Introspection types). diff --git a/src/main/java/graphql/validation/rules/UniqueOperationNames.java b/src/main/java/graphql/validation/rules/UniqueOperationNames.java index 3b6d1e08f..f3eecf00d 100644 --- a/src/main/java/graphql/validation/rules/UniqueOperationNames.java +++ b/src/main/java/graphql/validation/rules/UniqueOperationNames.java @@ -13,7 +13,7 @@ /** * A GraphQL document is only valid if all defined operations have unique names. - * http://facebook.github.io/graphql/October2016/#sec-Operation-Name-Uniqueness + * https://spec.graphql.org/October2021/#sec-Operation-Name-Uniqueness */ @Internal public class UniqueOperationNames extends AbstractRule { diff --git a/src/test/groovy/graphql/NullValueSupportTest.groovy b/src/test/groovy/graphql/NullValueSupportTest.groovy index 633117438..0a854cb6c 100644 --- a/src/test/groovy/graphql/NullValueSupportTest.groovy +++ b/src/test/groovy/graphql/NullValueSupportTest.groovy @@ -10,7 +10,7 @@ import spock.lang.Unroll import static graphql.ExecutionInput.newExecutionInput /* - * Taken from http://facebook.github.io/graphql/#sec-Input-Objects + * Taken from https://spec.graphql.org/October2021/#sec-Input-Objects * * diff --git a/src/test/groovy/graphql/validation/SpecValidation282Test.groovy b/src/test/groovy/graphql/validation/SpecValidation282Test.groovy index 92885e1c5..949f40ced 100644 --- a/src/test/groovy/graphql/validation/SpecValidation282Test.groovy +++ b/src/test/groovy/graphql/validation/SpecValidation282Test.groovy @@ -2,7 +2,7 @@ package graphql.validation /** * validation examples used in the spec in given section - * http://facebook.github.io/graphql/#sec-Validation + * https://spec.graphql.org/October2021/#sec-Validation * * This test checks that an inline fragment containing just a directive * is parsed correctly diff --git a/src/test/groovy/graphql/validation/SpecValidation51Test.groovy b/src/test/groovy/graphql/validation/SpecValidation51Test.groovy index 78cda9ab7..ef05fa806 100644 --- a/src/test/groovy/graphql/validation/SpecValidation51Test.groovy +++ b/src/test/groovy/graphql/validation/SpecValidation51Test.groovy @@ -1,7 +1,7 @@ package graphql.validation /** * validation examples used in the spec in given section - * http://facebook.github.io/graphql/#sec-Validation + * https://spec.graphql.org/October2021/#sec-Validation * @author dwinsor * */ diff --git a/src/test/groovy/graphql/validation/SpecValidation562Test.groovy b/src/test/groovy/graphql/validation/SpecValidation562Test.groovy index bbec32c5d..7a0f1ada7 100644 --- a/src/test/groovy/graphql/validation/SpecValidation562Test.groovy +++ b/src/test/groovy/graphql/validation/SpecValidation562Test.groovy @@ -1,7 +1,7 @@ package graphql.validation /** * validation examples used in the spec in given section - * http://facebook.github.io/graphql/#sec-Validation + * https://spec.graphql.org/October2021/#sec-Validation * @author dwinsor * */ diff --git a/src/test/groovy/graphql/validation/SpecValidation573Test.groovy b/src/test/groovy/graphql/validation/SpecValidation573Test.groovy index 01b400cc5..0d8565e22 100644 --- a/src/test/groovy/graphql/validation/SpecValidation573Test.groovy +++ b/src/test/groovy/graphql/validation/SpecValidation573Test.groovy @@ -1,7 +1,7 @@ package graphql.validation /** * validation examples used in the spec in given section - * http://facebook.github.io/graphql/#sec-Validation + * https://spec.graphql.org/October2021/#sec-Validation * */ class SpecValidation573Test extends SpecValidationBase { diff --git a/src/test/groovy/graphql/validation/SpecValidationBase.groovy b/src/test/groovy/graphql/validation/SpecValidationBase.groovy index 8d192c814..1436f4752 100644 --- a/src/test/groovy/graphql/validation/SpecValidationBase.groovy +++ b/src/test/groovy/graphql/validation/SpecValidationBase.groovy @@ -5,7 +5,7 @@ import spock.lang.Specification /** * validation examples used in the spec - * http://facebook.github.io/graphql/#sec-Validation + * https://spec.graphql.org/October2021/#sec-Validation * @author dwinsor * */ diff --git a/src/test/groovy/graphql/validation/SpecValidationSchema.java b/src/test/groovy/graphql/validation/SpecValidationSchema.java index 6e5e19613..398dd1ad3 100644 --- a/src/test/groovy/graphql/validation/SpecValidationSchema.java +++ b/src/test/groovy/graphql/validation/SpecValidationSchema.java @@ -34,7 +34,7 @@ /** * Sample schema used in the spec for validation examples - * http://facebook.github.io/graphql/#sec-Validation + * https://spec.graphql.org/October2021/#sec-Validation * * @author dwinsor */ diff --git a/src/test/groovy/graphql/validation/SpecValidationSchemaPojos.java b/src/test/groovy/graphql/validation/SpecValidationSchemaPojos.java index 9b0346b3e..da3d0c762 100644 --- a/src/test/groovy/graphql/validation/SpecValidationSchemaPojos.java +++ b/src/test/groovy/graphql/validation/SpecValidationSchemaPojos.java @@ -2,7 +2,7 @@ /** * Sample schema pojos used in the spec for validation examples - * http://facebook.github.io/graphql/#sec-Validation + * https://spec.graphql.org/October2021/#sec-Validation * * @author dwinsor */ diff --git a/src/test/groovy/readme/ReadmeExamples.java b/src/test/groovy/readme/ReadmeExamples.java index 78072b3d4..9be296d7b 100644 --- a/src/test/groovy/readme/ReadmeExamples.java +++ b/src/test/groovy/readme/ReadmeExamples.java @@ -304,7 +304,7 @@ public Review get(DataFetchingEnvironment environment) { // be maps. You can convert them to POJOs inside the data fetcher if that // suits your code better // - // See http://facebook.github.io/graphql/October2016/#sec-Input-Objects + // See https://spec.graphql.org/October2021/#sec-Input-Objects // Map episodeInputMap = environment.getArgument("episode"); Map reviewInputMap = environment.getArgument("review");