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 withGraphQLType
s
-
-
Constructor Summary
Constructors Constructor Description GraphQLTypeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isEnum(GraphQLType type)
Returns true if the given type is an enum typestatic boolean
isInput(GraphQLType type)
Returns true if the given type is an input typestatic boolean
isInterfaceOrUnion(GraphQLType type)
static boolean
isLeaf(GraphQLType type)
Returns true if the given type is a leaf type, that it cant contain any more fieldsstatic boolean
isList(GraphQLType type)
Returns true if the given type is a list typestatic boolean
isNonNull(GraphQLType type)
Returns true if the given type is a non null typestatic boolean
isNotWrapped(GraphQLType type)
Returns true if the given type is NOT a non null or list typestatic boolean
isNullable(GraphQLType type)
Returns true if the given type is a nullable typestatic boolean
isObjectType(GraphQLType type)
static boolean
isScalar(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 boolean
isWrapped(GraphQLType type)
Returns true if the given type is a non null or list type, that is a wrapped typestatic java.lang.String
simplePrint(GraphQLSchemaElement schemaElement)
static java.lang.String
simplePrint(GraphQLType type)
This will return the type in graphql SDL format, eg [typeName!]!static GraphQLUnmodifiedType
unwrapAll(GraphQLType type)
Unwraps all layers of the type or just returns the type again if it's not a wrapped typestatic <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 GraphQLType
unwrapNonNull(GraphQLType type)
Unwraps all non nullable layers of the type until it reaches a type that is notGraphQLNonNull
static <T extends GraphQLType>
TunwrapNonNullAs(GraphQLType type)
Unwraps all non nullable layers of the type until it reaches a type that is notGraphQLNonNull
and then cast to the target type.static GraphQLType
unwrapOne(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 inGraphQLNonNull
andGraphQLList
type 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- 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 notGraphQLNonNull
and 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 inGraphQLNonNull
andGraphQLList
type 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
-
-