private TypeInfo(Type type) { this.rawType = assertNotNull(type, "type must not be null"); while (!(type instanceof TypeName)) { if (type instanceof NonNullType) { decoration.push(NonNullType.class); type = ((NonNullType) type).getType(); } if (type instanceof ListType) { decoration.push(ListType.class); type = ((ListType) type).getType(); } } this.typeName = (TypeName) type; }
@Override public NonNullType deepCopy() { return new NonNullType(deepCopy(type), getSourceLocation(), getComments(), getIgnoredChars()); }
@Override public NonNullType withNewChildren(NodeChildrenContainer newChildren) { return transform(builder -> builder .type((Type) newChildren.getChildOrNull(CHILD_TYPE)) ); }
private Builder(NonNullType existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.type = existing.getType(); this.ignoredChars = existing.getIgnoredChars(); }
@SuppressWarnings("unchecked") private Type createTypeIndirection(Map<String, Object> type) { String kind = (String) type.get("kind"); switch (kind) { case "INTERFACE": case "OBJECT": case "UNION": case "ENUM": case "INPUT_OBJECT": case "SCALAR": return TypeName.newTypeName().name((String) type.get("name")).build(); case "NON_NULL": return NonNullType.newNonNullType().type(createTypeIndirection((Map<String, Object>) type.get("ofType"))).build(); case "LIST": return ListType.newListType().type(createTypeIndirection((Map<String, Object>) type.get("ofType"))).build(); default: return assertShouldNeverHappen("Unknown kind %s", kind); } }
public NonNullType build() { NonNullType nonNullType = new NonNullType(type, sourceLocation, comments, ignoredChars); return nonNullType; } }
private Builder(NonNullType existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.type = existing.getType(); this.ignoredChars = existing.getIgnoredChars(); }
protected NonNullType createNonNullType(GraphqlParser.NonNullTypeContext ctx) { NonNullType.Builder builder = NonNullType.newNonNullType(); addCommonData(builder, ctx); if (ctx.listType() != null) { builder.type(createListType(ctx.listType())); } else if (ctx.typeName() != null) { builder.type(createTypeName(ctx.typeName())); } else { return assertShouldNeverHappen(); } return builder.build(); }
public NonNullType build() { NonNullType nonNullType = new NonNullType(type, sourceLocation, comments, ignoredChars); return nonNullType; } }
private void checkArgValueMatchesAllowedNonNullType(List<GraphQLError> errors, Value instanceValue, NonNullType allowedArgType) { if (instanceValue instanceof NullValue) { addValidationError(errors, EXPECTED_NON_NULL_MESSAGE); return; } Type unwrappedAllowedType = allowedArgType.getType(); checkArgValueMatchesAllowedType(errors, instanceValue, unwrappedAllowedType); }
@Override public NonNullType deepCopy() { return new NonNullType(deepCopy(type), getSourceLocation(), getComments(), getIgnoredChars()); }
@SuppressWarnings("unchecked") private Type createTypeIndirection(Map<String, Object> type) { String kind = (String) type.get("kind"); switch (kind) { case "INTERFACE": case "OBJECT": case "UNION": case "ENUM": case "INPUT_OBJECT": case "SCALAR": return TypeName.newTypeName().name((String) type.get("name")).build(); case "NON_NULL": return NonNullType.newNonNullType().type(createTypeIndirection((Map<String, Object>) type.get("ofType"))).build(); case "LIST": return ListType.newListType().type(createTypeIndirection((Map<String, Object>) type.get("ofType"))).build(); default: return assertShouldNeverHappen("Unknown kind %s", kind); } }
@Override public NonNullType withNewChildren(NodeChildrenContainer newChildren) { return transform(builder -> builder .type((Type) newChildren.getChildOrNull(CHILD_TYPE)) ); }
public TypeInfo unwrapOne() { if (rawType instanceof NonNullType) { return typeInfo(((NonNullType) rawType).getType()); } if (rawType instanceof ListType) { return typeInfo(((ListType) rawType).getType()); } return this; }
protected NonNullType createNonNullType(GraphqlParser.NonNullTypeContext ctx) { NonNullType.Builder builder = NonNullType.newNonNullType(); addCommonData(builder, ctx); if (ctx.listType() != null) { builder.type(createListType(ctx.listType())); } else if (ctx.typeName() != null) { builder.type(createTypeName(ctx.typeName())); } else { return assertShouldNeverHappen(); } return builder.build(); }
public TypeName getUnmodifiedType(Type type) { if (type instanceof ListType) { return getUnmodifiedType(((ListType) type).getType()); } else if (type instanceof NonNullType) { return getUnmodifiedType(((NonNullType) type).getType()); } else if (type instanceof TypeName) { return (TypeName) type; } return Assert.assertShouldNeverHappen(); }
private String type(Type type) { if (type instanceof NonNullType) { NonNullType inner = (NonNullType) type; return wrap("", type(inner.getType()), "!"); } else if (type instanceof ListType) { ListType inner = (ListType) type; return wrap("[", type(inner.getType()), "]"); } else { TypeName inner = (TypeName) type; return inner.getName(); } }
public static GraphQLType getTypeFromAST(GraphQLSchema schema, Type type) { GraphQLType innerType; if (type instanceof ListType) { innerType = getTypeFromAST(schema, ((ListType) type).getType()); return innerType != null ? list(innerType) : null; } else if (type instanceof NonNullType) { innerType = getTypeFromAST(schema, ((NonNullType) type).getType()); return innerType != null ? nonNull(innerType) : null; } return schema.getType(((TypeName) type).getName()); } }
private TypeInfo(Type type) { this.rawType = assertNotNull(type, "type must not be null"); while (!(type instanceof TypeName)) { if (type instanceof NonNullType) { decoration.push(NonNullType.class); type = ((NonNullType) type).getType(); } if (type instanceof ListType) { decoration.push(ListType.class); type = ((ListType) type).getType(); } } this.typeName = (TypeName) type; }
private void checkArgValueMatchesAllowedNonNullType(List<GraphQLError> errors, Value instanceValue, NonNullType allowedArgType) { if (instanceValue instanceof NullValue) { addValidationError(errors, EXPECTED_NON_NULL_MESSAGE); return; } Type unwrappedAllowedType = allowedArgType.getType(); checkArgValueMatchesAllowedType(errors, instanceValue, unwrappedAllowedType); }