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 ListType deepCopy() { return new ListType(deepCopy(type), getSourceLocation(), getComments(), getIgnoredChars()); }
@Override public ListType withNewChildren(NodeChildrenContainer newChildren) { return transform(builder -> builder .type(newChildren.getChildOrNull(CHILD_TYPE)) ); }
private Builder(ListType existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.type = existing.getType(); this.ignoredChars = existing.getIgnoredChars(); }
protected ListType createListType(GraphqlParser.ListTypeContext ctx) { ListType.Builder builder = ListType.newListType(); addCommonData(builder, ctx); builder.type(createType(ctx.type())); return builder.build(); }
public ListType build() { ListType listType = new ListType(type, sourceLocation, comments, ignoredChars); return listType; } }
private Builder(ListType 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 ListType build() { ListType listType = new ListType(type, sourceLocation, comments, ignoredChars); return listType; } }
private void checkArgValueMatchesAllowedListType(List<GraphQLError> errors, Value instanceValue, ListType allowedArgType) { if (instanceValue instanceof NullValue) { return; } if (!(instanceValue instanceof ArrayValue)) { addValidationError(errors, EXPECTED_LIST_MESSAGE, instanceValue.getClass().getSimpleName()); return; } ArrayValue arrayValue = ((ArrayValue) instanceValue); Type unwrappedAllowedType = allowedArgType.getType(); // validate each instance value in the list, all instances must match for the list to match arrayValue.getValues().forEach(value -> checkArgValueMatchesAllowedType(errors, value, unwrappedAllowedType)); }
@Override public ListType deepCopy() { return new ListType(deepCopy(type), getSourceLocation(), getComments(), getIgnoredChars()); }
protected ListType createListType(GraphqlParser.ListTypeContext ctx) { ListType.Builder builder = ListType.newListType(); addCommonData(builder, ctx); builder.type(createType(ctx.type())); return builder.build(); }
@Override public ListType withNewChildren(NodeChildrenContainer newChildren) { return transform(builder -> builder .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; }
@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 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 checkArgValueMatchesAllowedListType(List<GraphQLError> errors, Value instanceValue, ListType allowedArgType) { if (instanceValue instanceof NullValue) { return; } if (!(instanceValue instanceof ArrayValue)) { addValidationError(errors, EXPECTED_LIST_MESSAGE, instanceValue.getClass().getSimpleName()); return; } ArrayValue arrayValue = ((ArrayValue) instanceValue); Type unwrappedAllowedType = allowedArgType.getType(); // validate each instance value in the list, all instances must match for the list to match arrayValue.getValues().forEach(value -> checkArgValueMatchesAllowedType(errors, value, unwrappedAllowedType)); }