/** * A factory method for creating non null types so that when used with static imports allows * more readable code such as * {@code .type(nonNull(GraphQLString)) } * * @param wrappedType the type to wrap as being non null * * @return a GraphQLNonNull of that wrapped type */ public static GraphQLNonNull nonNull(GraphQLType wrappedType) { return new GraphQLNonNull(wrappedType); }
private static Value handleNonNull(Object _value, GraphQLNonNull type) { GraphQLType wrappedType = type.getWrappedType(); return astFromValue(_value, wrappedType); }
public GraphQLType effectiveType(GraphQLType variableType, Value defaultValue) { if (defaultValue == null) { return variableType; } if (isNonNull(variableType)) { return variableType; } return nonNull(variableType); }
private GraphQLOutputType getGraphQLConnection(AccessibleObject field, graphql.schema.GraphQLType type, Relay relay, Map<String, graphql.schema.GraphQLType> typeRegistry) { if (type instanceof GraphQLNonNull) { GraphQLList listType = (GraphQLList) ((GraphQLNonNull) type).getWrappedType(); return new GraphQLNonNull(internalGetGraphQLConnection(field, listType, relay, typeRegistry)); } else { return internalGetGraphQLConnection(field, (GraphQLList) type, relay, typeRegistry); } }
void replaceType(GraphQLType type) { assertNonNullWrapping(type); wrappedType = type; }
@Override public TraversalControl visitGraphQLNonNull(GraphQLNonNull node, TraverserContext<GraphQLType> context) { node.replaceType(resolvedType); return super.visitGraphQLNonNull(node, context); } }
GraphQLOutputType outputType = field.getAnnotation(NotNull.class) == null ? type : new GraphQLNonNull(type); if (outputType == GraphQLBoolean || (outputType instanceof GraphQLNonNull && ((GraphQLNonNull) outputType).getWrappedType() == GraphQLBoolean)) { if (checkIfPrefixGetterExists(field.getDeclaringClass(), "is", field.getName()) || checkIfPrefixGetterExists(field.getDeclaringClass(), "get", field.getName())) {
public GraphQLNonNull(GraphQLType wrappedType) { assertNotNull(wrappedType, "wrappedType can't be null"); assertNonNullWrapping(wrappedType); this.wrappedType = wrappedType; }
@Override public TraversalControl visitGraphQLNonNull(GraphQLNonNull node, TraverserContext<GraphQLType> context) { node.replaceType(resolvedType); return super.visitGraphQLNonNull(node, context); } }
.field(GraphQLFieldDefinition.newFieldDefinition() .name("id") .type(new GraphQLNonNull(Scalars.GraphQLID)) .dataFetcher(environment -> relay .toGlobalId(clusterType.getName(), ((StopCluster) environment.getSource()).id)) .field(GraphQLFieldDefinition.newFieldDefinition() .name("gtfsId") .type(new GraphQLNonNull(Scalars.GraphQLString)) .dataFetcher(environment -> ((StopCluster) environment.getSource()).id) .build()) .field(GraphQLFieldDefinition.newFieldDefinition() .name("name") .type(new GraphQLNonNull(Scalars.GraphQLString)) .dataFetcher(environment -> ((StopCluster) environment.getSource()).name) .build()) .field(GraphQLFieldDefinition.newFieldDefinition() .name("lat") .type(new GraphQLNonNull(Scalars.GraphQLFloat)) .dataFetcher(environment -> (float) (((StopCluster) environment.getSource()).lat)) .build()) .field(GraphQLFieldDefinition.newFieldDefinition() .name("lon") .type(new GraphQLNonNull(Scalars.GraphQLFloat)) .dataFetcher(environment -> (float) (((StopCluster) environment.getSource()).lon)) .build()) .field(GraphQLFieldDefinition.newFieldDefinition() .name("stops") .type(new GraphQLList(new GraphQLNonNull(stopType)))
private GraphQLType unwrapNonNull(GraphQLNonNull type) { if (isList(type.getWrappedType())) { //we only care about [type!]! i.e. non-null lists of non-nulls GraphQLList listType = (GraphQLList) type.getWrappedType(); if (isNonNull(listType.getWrappedType())) { return unwrapAll(listType.getWrappedType()); } else { return type.getWrappedType(); } } else { return unwrapAll(type.getWrappedType()); } }
/** * This will decorate a graphql type with the original hierarchy of non null and list'ness * it originally contained in its definition type * * @param objectType this should be a graphql type that was originally built from this raw type * @param <T> the type * * @return the decorated type */ @SuppressWarnings("TypeParameterUnusedInFormals") public <T extends GraphQLType> T decorate(GraphQLType objectType) { GraphQLType out = objectType; Stack<Class<?>> wrappingStack = new Stack<>(); wrappingStack.addAll(this.decoration); while (!wrappingStack.isEmpty()) { Class<?> clazz = wrappingStack.pop(); if (clazz.equals(NonNullType.class)) { out = nonNull(out); } if (clazz.equals(ListType.class)) { out = list(out); } } // we handle both input and output graphql types //noinspection unchecked return (T) out; }
void replaceType(GraphQLType type) { assertNonNullWrapping(type); wrappedType = type; }
/** * A factory method for creating non null types so that when used with static imports allows * more readable code such as * {@code .type(nonNull(GraphQLString)) } * * @param wrappedType the type to wrap as being non null * * @return a GraphQLNonNull of that wrapped type */ public static GraphQLNonNull nonNull(GraphQLType wrappedType) { return new GraphQLNonNull(wrappedType); }
/** * Unwraps one layer of the type or just returns the type again if its not a wrapped type * * @param type the type to unwrapOne * * @return the unwrapped type or the same type again if its not wrapped */ public static GraphQLType unwrapOne(GraphQLType type) { if (isNonNull(type)) { return ((GraphQLNonNull) type).getWrappedType(); } else if (isList(type)) { return ((GraphQLList) type).getWrappedType(); } return type; }
/** * This allows you to morph a type into a more specialized form yet return the same * parent and non-null ness, for example taking a {@link GraphQLInterfaceType} * and turning it into a specific {@link graphql.schema.GraphQLObjectType} * after type resolution has occurred * * @param newType the new type to be * * @return a new type info with the same */ public ExecutionStepInfo changeTypeWithPreservedNonNull(GraphQLOutputType newType) { assertTrue(!GraphQLTypeUtil.isNonNull(newType), "newType can't be non null"); if (isNonNullType()) { return new ExecutionStepInfo(GraphQLNonNull.nonNull(newType), fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); } else { return new ExecutionStepInfo(newType, fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); } }
public GraphQLNonNull(GraphQLType wrappedType) { assertNotNull(wrappedType, "wrappedType can't be null"); assertNonNullWrapping(wrappedType); this.wrappedType = wrappedType; }
/** * Returns a non-null list of non-null types */ public static GraphQLOutputType stdList(GraphQLType type) { return new GraphQLNonNull( new GraphQLList( new GraphQLNonNull( type ) ) ); }
public static GraphQLType unwrapNonNull(GraphQLType type) { while (type instanceof GraphQLNonNull) { type = ((GraphQLNonNull) type).getWrappedType(); } return type; }