| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d72f029 commit 873bada
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,10 +156,10 @@ public ExecutionStepInfo changeTypeWithPreservedNonNull(GraphQLType newType) { | |||
| 156 | 156 | ||
| 157 | 157 | ||
| 158 | 158 | /** | |
| 159 | - * @return the type in graphql AST format, eg [typeName!]! | ||
| 159 | + * @return the type in graphql SDL format, eg [typeName!]! | ||
| 160 | 160 | */ | |
| 161 | - public String toAst() { | ||
| 162 | - return GraphQLTypeUtil.getUnwrappedTypeName(type); | ||
| 161 | + public String simplePrint() { | ||
| 162 | + return GraphQLTypeUtil.simplePrint(type); | ||
| 163 | 163 | } | |
| 164 | 164 | ||
| 165 | 165 | @Override | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ | |||
| 19 | 19 | public class InputMapDefinesTooManyFieldsException extends GraphQLException implements GraphQLError { | |
| 20 | 20 | ||
| 21 | 21 | public InputMapDefinesTooManyFieldsException(GraphQLType graphQLType, String fieldName) { | |
| 22 | - super(String.format("The variables input contains a field name '%s' that is not defined for input object type '%s' ", fieldName, GraphQLTypeUtil.getUnwrappedTypeName(graphQLType))); | ||
| 22 | + super(String.format("The variables input contains a field name '%s' that is not defined for input object type '%s' ", fieldName, GraphQLTypeUtil.simplePrint(graphQLType))); | ||
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | 25 | @Override | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,19 +24,19 @@ public class NonNullableValueCoercedAsNullException extends GraphQLException imp | |||
| 24 | 24 | ||
| 25 | 25 | public NonNullableValueCoercedAsNullException(VariableDefinition variableDefinition, GraphQLType graphQLType) { | |
| 26 | 26 | super(format("Variable '%s' has coerced Null value for NonNull type '%s'", | |
| 27 | - variableDefinition.getName(), GraphQLTypeUtil.getUnwrappedTypeName(graphQLType))); | ||
| 27 | + variableDefinition.getName(), GraphQLTypeUtil.simplePrint(graphQLType))); | ||
| 28 | 28 | this.sourceLocations = Collections.singletonList(variableDefinition.getSourceLocation()); | |
| 29 | 29 | } | |
| 30 | 30 | ||
| 31 | 31 | public NonNullableValueCoercedAsNullException(VariableDefinition variableDefinition, String fieldName, GraphQLType graphQLType) { | |
| 32 | 32 | super(format("Field '%s' of variable '%s' has coerced Null value for NonNull type '%s'", | |
| 33 | - fieldName, variableDefinition.getName(), GraphQLTypeUtil.getUnwrappedTypeName(graphQLType))); | ||
| 33 | + fieldName, variableDefinition.getName(), GraphQLTypeUtil.simplePrint(graphQLType))); | ||
| 34 | 34 | this.sourceLocations = Collections.singletonList(variableDefinition.getSourceLocation()); | |
| 35 | 35 | } | |
| 36 | 36 | ||
| 37 | 37 | public NonNullableValueCoercedAsNullException(GraphQLInputObjectField inputTypeField) { | |
| 38 | 38 | super(format("Input field '%s' has coerced Null value for NonNull type '%s'", | |
| 39 | - inputTypeField.getName(), GraphQLTypeUtil.getUnwrappedTypeName(inputTypeField.getType()))); | ||
| 39 | + inputTypeField.getName(), GraphQLTypeUtil.simplePrint(inputTypeField.getType()))); | ||
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | 42 | @Override | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,7 +67,7 @@ public TracingContext beginField(DataFetchingEnvironment dataFetchingEnvironment | |||
| 67 | 67 | Map<String, Object> fetchMap = new LinkedHashMap<>(); | |
| 68 | 68 | fetchMap.put("path", executionStepInfo.getPath().toList()); | |
| 69 | 69 | fetchMap.put("parentType", executionStepInfo.getParent().getUnwrappedNonNullType().getName()); | |
| 70 | - fetchMap.put("returnType", executionStepInfo.toAst()); | ||
| 70 | + fetchMap.put("returnType", executionStepInfo.simplePrint()); | ||
| 71 | 71 | fetchMap.put("fieldName", executionStepInfo.getFieldDefinition().getName()); | |
| 72 | 72 | fetchMap.put("startOffset", startOffset); | |
| 73 | 73 | fetchMap.put("duration", duration); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | 8 | import java.util.Collections; | |
| 9 | 9 | import java.util.List; | |
| 10 | - import java.util.Map; | ||
| 11 | 10 | ||
| 12 | 11 | import static graphql.Assert.assertNotNull; | |
| 13 | 12 | ||
@@ -82,7 +81,7 @@ public List<GraphQLType> getChildren() { | |||
| 82 | 81 | ||
| 83 | 82 | @Override | |
| 84 | 83 | public String toString() { | |
| 85 | - return GraphQLTypeUtil.getUnwrappedTypeName(this); | ||
| 84 | + return GraphQLTypeUtil.simplePrint(this); | ||
| 86 | 85 | } | |
| 87 | 86 | ||
| 88 | 87 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,7 +43,7 @@ public GraphQLNonNull(GraphQLType wrappedType) { | |||
| 43 | 43 | ||
| 44 | 44 | private void assertNonNullWrapping(GraphQLType wrappedType) { | |
| 45 | 45 | assertTrue(!GraphQLTypeUtil.isNonNull(wrappedType), String.format("A non null type cannot wrap an existing non null type '%s'", | |
| 46 | - GraphQLTypeUtil.getUnwrappedTypeName(wrappedType))); | ||
| 46 | + GraphQLTypeUtil.simplePrint(wrappedType))); | ||
| 47 | 47 | } | |
| 48 | 48 | ||
| 49 | 49 | @Override | |
@@ -75,7 +75,7 @@ public int hashCode() { | |||
| 75 | 75 | ||
| 76 | 76 | @Override | |
| 77 | 77 | public String toString() { | |
| 78 | - return GraphQLTypeUtil.getUnwrappedTypeName(this); | ||
| 78 | + return GraphQLTypeUtil.simplePrint(this); | ||
| 79 | 79 | } | |
| 80 | 80 | ||
| 81 | 81 | @Override | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,30 +1,32 @@ | |||
| 1 | 1 | package graphql.schema; | |
| 2 | 2 | ||
| 3 | - import graphql.Internal; | ||
| 3 | + import graphql.PublicApi; | ||
| 4 | 4 | ||
| 5 | 5 | import java.util.Stack; | |
| 6 | 6 | ||
| 7 | 7 | import static graphql.Assert.assertNotNull; | |
| 8 | 8 | ||
| 9 | - @Internal | ||
| 9 | + /** | ||
| 10 | + * A utility class that helps work with {@link graphql.schema.GraphQLType}s | ||
| 11 | + */ | ||
| 12 | + @PublicApi | ||
| 10 | 13 | public class GraphQLTypeUtil { | |
| 11 | 14 | ||
| 12 | 15 | /** | |
| 13 | - * This will get the unwrapped type name that includes the non null and list wrappers | ||
| 14 | - * so it might be '[typeName!]' | ||
| 16 | + * This will return the type in graphql SDL format, eg [typeName!]! | ||
| 15 | 17 | * | |
| 16 | 18 | * @param type the type in play | |
| 17 | 19 | * | |
| 18 | - * @return the unwrapped type name | ||
| 20 | + * @return the type in graphql SDL format, eg [typeName!]! | ||
| 19 | 21 | */ | |
| 20 | - public static String getUnwrappedTypeName(GraphQLType type) { | ||
| 22 | + public static String simplePrint(GraphQLType type) { | ||
| 21 | 23 | StringBuilder sb = new StringBuilder(); | |
| 22 | 24 | if (isNonNull(type)) { | |
| 23 | - sb.append(getUnwrappedTypeName(unwrapOne(type))); | ||
| 25 | + sb.append(simplePrint(unwrapOne(type))); | ||
| 24 | 26 | sb.append("!"); | |
| 25 | 27 | } else if (isList(type)) { | |
| 26 | 28 | sb.append("["); | |
| 27 | - sb.append(getUnwrappedTypeName(unwrapOne(type))); | ||
| 29 | + sb.append(simplePrint(unwrapOne(type))); | ||
| 28 | 30 | sb.append("]"); | |
| 29 | 31 | } else { | |
| 30 | 32 | sb.append(type.getName()); | |
@@ -198,6 +200,4 @@ public static Stack<GraphQLType> unwrapType(GraphQLType type) { | |||
| 198 | 200 | } | |
| 199 | 201 | return decoration; | |
| 200 | 202 | } | |
| 201 | - | ||
| 202 | - | ||
| 203 | 203 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -400,7 +400,7 @@ private TypePrinter<GraphQLSchema> schemaPrinter() { | |||
| 400 | 400 | } | |
| 401 | 401 | ||
| 402 | 402 | String typeString(GraphQLType rawType) { | |
| 403 | - return GraphQLTypeUtil.getUnwrappedTypeName(rawType); | ||
| 403 | + return GraphQLTypeUtil.simplePrint(rawType); | ||
| 404 | 404 | } | |
| 405 | 405 | ||
| 406 | 406 | String argsString(List<GraphQLArgument> arguments) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ | |||
| 11 | 11 | import java.util.List; | |
| 12 | 12 | import java.util.Objects; | |
| 13 | 13 | ||
| 14 | - import static graphql.schema.GraphQLTypeUtil.getUnwrappedTypeName; | ||
| 14 | + import static graphql.schema.GraphQLTypeUtil.simplePrint; | ||
| 15 | 15 | import static graphql.schema.GraphQLTypeUtil.isList; | |
| 16 | 16 | import static graphql.schema.GraphQLTypeUtil.isNonNull; | |
| 17 | 17 | import static graphql.schema.GraphQLTypeUtil.unwrapOne; | |
@@ -61,8 +61,8 @@ private void checkObjectImplementsInterface(GraphQLObjectType objectType, GraphQ | |||
| 61 | 61 | } | |
| 62 | 62 | ||
| 63 | 63 | private void checkFieldTypeCompatibility(GraphQLObjectType objectType, GraphQLInterfaceType interfaceType, SchemaValidationErrorCollector validationErrorCollector, GraphQLFieldDefinition interfaceFieldDef, GraphQLFieldDefinition objectFieldDef) { | |
| 64 | - String interfaceFieldDefStr = getUnwrappedTypeName(interfaceFieldDef.getType()); | ||
| 65 | - String objectFieldDefStr = getUnwrappedTypeName(objectFieldDef.getType()); | ||
| 64 | + String interfaceFieldDefStr = simplePrint(interfaceFieldDef.getType()); | ||
| 65 | + String objectFieldDefStr = simplePrint(objectFieldDef.getType()); | ||
| 66 | 66 | ||
| 67 | 67 | if (!isCompatible(interfaceFieldDef.getType(), objectFieldDef.getType())) { | |
| 68 | 68 | validationErrorCollector.addError( | |
@@ -109,7 +109,7 @@ private String makeArgStr(GraphQLArgument argument) { | |||
| 109 | 109 | // we don't do default value checking because toString of getDefaultValue is not guaranteed to be stable | |
| 110 | 110 | return argument.getName() + | |
| 111 | 111 | ":" + | |
| 112 | - getUnwrappedTypeName(argument.getType()); | ||
| 112 | + simplePrint(argument.getType()); | ||
| 113 | 113 | ||
| 114 | 114 | } | |
| 115 | 115 | ||
@@ -146,8 +146,8 @@ boolean isCompatible(GraphQLOutputType constraintType, GraphQLOutputType objectT | |||
| 146 | 146 | } | |
| 147 | 147 | ||
| 148 | 148 | boolean isSameType(GraphQLOutputType a, GraphQLOutputType b) { | |
| 149 | - String aDefString = getUnwrappedTypeName(a); | ||
| 150 | - String bDefString = getUnwrappedTypeName(b); | ||
| 149 | + String aDefString = simplePrint(a); | ||
| 150 | + String bDefString = simplePrint(b); | ||
| 151 | 151 | return aDefString.equals(bDefString); | |
| 152 | 152 | } | |
| 153 | 153 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,8 +60,8 @@ public void checkVariable(VariableReference variableReference) { | |||
| 60 | 60 | if (!variablesTypesMatcher.doesVariableTypesMatch(variableType, variableDefinition.getDefaultValue(), expectedType)) { | |
| 61 | 61 | GraphQLType effectiveType = variablesTypesMatcher.effectiveType(variableType, variableDefinition.getDefaultValue()); | |
| 62 | 62 | String message = String.format("Variable type '%s' doesn't match expected type '%s'", | |
| 63 | - GraphQLTypeUtil.getUnwrappedTypeName(effectiveType), | ||
| 64 | - GraphQLTypeUtil.getUnwrappedTypeName(expectedType)); | ||
| 63 | + GraphQLTypeUtil.simplePrint(effectiveType), | ||
| 64 | + GraphQLTypeUtil.simplePrint(expectedType)); | ||
| 65 | 65 | addError(ValidationErrorType.VariableTypeMismatch, variableReference.getSourceLocation(), message); | |
| 66 | 66 | } | |
| 67 | 67 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments