Package graphql.schema
Class GraphQLTypeUtil
- java.lang.Object
-
- graphql.schema.GraphQLTypeUtil
-
@PublicApi public class GraphQLTypeUtil extends java.lang.Object
A utility class that helps work withGraphQLTypes
-
-
Constructor Summary
Constructors Constructor Description GraphQLTypeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisEnum(GraphQLType type)Returns true if the given type is an enum typestatic booleanisInput(GraphQLType type)Returns true if the given type is an input typestatic booleanisInterfaceOrUnion(GraphQLType type)static booleanisLeaf(GraphQLType type)Returns true if the given type is a leaf type, that it cant contain any more fieldsstatic booleanisList(GraphQLType type)Returns true if the given type is a list typestatic booleanisNonNull(GraphQLType type)Returns true if the given type is a non null typestatic booleanisNotWrapped(GraphQLType type)Returns true if the given type is NOT a non null or list typestatic booleanisNullable(GraphQLType type)Returns true if the given type is a nullable typestatic booleanisObjectType(GraphQLType type)static booleanisScalar(GraphQLType type)Returns true if the given type is a scalar typestatic java.util.function.Predicate<GraphQLNamedSchemaElement>isSystemElement()This predicate returns true if the schema element is an inbuilt schema element such as the system scalars and directives or introspection typesstatic booleanisWrapped(GraphQLType type)Returns true if the given type is a non null or list type, that is a wrapped typestatic java.lang.StringsimplePrint(GraphQLSchemaElement schemaElement)static java.lang.StringsimplePrint(GraphQLType type)This will return the type in graphql SDL format, eg [typeName!]!static GraphQLUnmodifiedTypeunwrapAll(GraphQLType type)Unwraps all layers of the type or just returns the type again if it's not a wrapped type NOTE: This method does not support GraphQLTypeReference as input and will lead to a ClassCastExceptionstatic <T extends GraphQLType>
TunwrapAllAs(GraphQLType type)Unwraps all layers of the type or just returns the type again if it's not a wrapped type and then cast to the target type.static GraphQLTypeunwrapNonNull(GraphQLType type)Unwraps all non nullable layers of the type until it reaches a type that is notGraphQLNonNullstatic <T extends GraphQLType>
TunwrapNonNullAs(GraphQLType type)Unwraps all non nullable layers of the type until it reaches a type that is notGraphQLNonNulland then cast to the target type.static GraphQLTypeunwrapOne(GraphQLType type)Unwraps one layer of the type or just returns the type again if it's not a wrapped typestatic <T extends GraphQLType>
TunwrapOneAs(GraphQLType type)Unwraps one layer of the type or just returns the type again if it's not a wrapped type and then cast to the target type.static java.util.Stack<GraphQLType>unwrapType(GraphQLType type)graphql types can be wrapped inGraphQLNonNullandGraphQLListtype wrappers so this method will unwrap the type down to the raw unwrapped type and return that wrapping as a stack, with the top of the stack being the raw underling type.
-
-
-
Method Detail
-
simplePrint
public static java.lang.String simplePrint(GraphQLType type)
This will return the type in graphql SDL format, eg [typeName!]!- Parameters:
type- the type in play- Returns:
- the type in graphql SDL format, eg [typeName!]!
-
simplePrint
public static java.lang.String simplePrint(GraphQLSchemaElement schemaElement)
-
isNonNull
public static boolean isNonNull(GraphQLType type)
Returns true if the given type is a non null type- Parameters:
type- the type to check- Returns:
- true if the given type is a non null type
-
isNullable
public static boolean isNullable(GraphQLType type)
Returns true if the given type is a nullable type- Parameters:
type- the type to check- Returns:
- true if the given type is a nullable type
-
isList
public static boolean isList(GraphQLType type)
Returns true if the given type is a list type- Parameters:
type- the type to check- Returns:
- true if the given type is a list type
-
isWrapped
public static boolean isWrapped(GraphQLType type)
Returns true if the given type is a non null or list type, that is a wrapped type- Parameters:
type- the type to check- Returns:
- true if the given type is a non null or list type
-
isNotWrapped
public static boolean isNotWrapped(GraphQLType type)
Returns true if the given type is NOT a non null or list type- Parameters:
type- the type to check- Returns:
- true if the given type is NOT a non null or list type
-
isScalar
public static boolean isScalar(GraphQLType type)
Returns true if the given type is a scalar type- Parameters:
type- the type to check- Returns:
- true if the given type is a scalar type
-
isEnum
public static boolean isEnum(GraphQLType type)
Returns true if the given type is an enum type- Parameters:
type- the type to check- Returns:
- true if the given type is an enum type
-
isLeaf
public static boolean isLeaf(GraphQLType type)
Returns true if the given type is a leaf type, that it cant contain any more fields- Parameters:
type- the type to check- Returns:
- true if the given type is a leaf type
-
isInput
public static boolean isInput(GraphQLType type)
Returns true if the given type is an input type- Parameters:
type- the type to check- Returns:
- true if the given type is an input type
-
unwrapOne
public static GraphQLType unwrapOne(GraphQLType type)
Unwraps one layer of the type or just returns the type again if it's not a wrapped type- Parameters:
type- the type to unwrapOne- Returns:
- the unwrapped type or the same type again if it's not wrapped
-
unwrapOneAs
public static <T extends GraphQLType> T unwrapOneAs(GraphQLType type)
Unwraps one layer of the type or just returns the type again if it's not a wrapped type and then cast to the target type.- Type Parameters:
T- for two- Parameters:
type- the type to unwrapOne- Returns:
- the unwrapped type or the same type again if it's not wrapped
-
unwrapAll
public static GraphQLUnmodifiedType unwrapAll(GraphQLType type)
Unwraps all layers of the type or just returns the type again if it's not a wrapped type NOTE: This method does not support GraphQLTypeReference as input and will lead to a ClassCastException- Parameters:
type- the type to unwrapOne- Returns:
- the underlying type
-
unwrapAllAs
public static <T extends GraphQLType> T unwrapAllAs(GraphQLType type)
Unwraps all layers of the type or just returns the type again if it's not a wrapped type and then cast to the target type.- Type Parameters:
T- for two- Parameters:
type- the type to unwrapOne- Returns:
- the underlying type
-
unwrapNonNull
public static GraphQLType unwrapNonNull(GraphQLType type)
Unwraps all non nullable layers of the type until it reaches a type that is notGraphQLNonNull- Parameters:
type- the type to unwrap- Returns:
- the underlying type that is not
GraphQLNonNull
-
unwrapNonNullAs
public static <T extends GraphQLType> T unwrapNonNullAs(GraphQLType type)
Unwraps all non nullable layers of the type until it reaches a type that is notGraphQLNonNulland then cast to the target type.- Type Parameters:
T- for two- Parameters:
type- the type to unwrap- Returns:
- the underlying type that is not
GraphQLNonNull
-
unwrapType
public static java.util.Stack<GraphQLType> unwrapType(GraphQLType type)
graphql types can be wrapped inGraphQLNonNullandGraphQLListtype wrappers so this method will unwrap the type down to the raw unwrapped type and return that wrapping as a stack, with the top of the stack being the raw underling type.- Parameters:
type- the type to unwrap- Returns:
- a stack of the type wrapping which will be at least 1 later deep
-
isInterfaceOrUnion
public static boolean isInterfaceOrUnion(GraphQLType type)
-
isObjectType
public static boolean isObjectType(GraphQLType type)
-
isSystemElement
public static java.util.function.Predicate<GraphQLNamedSchemaElement> isSystemElement()
This predicate returns true if the schema element is an inbuilt schema element such as the system scalars and directives or introspection types- Returns:
- true if it's a system schema element
-
-