private boolean checkTypeCondition(FieldCollectorParameters parameters, GraphQLType conditionType) { GraphQLObjectType type = parameters.getObjectType(); if (conditionType.equals(type)) { return true; } if (conditionType instanceof GraphQLInterfaceType) { List<GraphQLObjectType> implementations = parameters.getGraphQLSchema().getImplementations((GraphQLInterfaceType) conditionType); return implementations.contains(type); } else if (conditionType instanceof GraphQLUnionType) { return ((GraphQLUnionType) conditionType).getTypes().contains(type); } return false; }
/** * Returns true if a specified concrete type is a possible type of a provided abstract type. * If the provided abstract type is: * - an interface, it checks whether the concrete type is one of its implementations. * - a union, it checks whether the concrete type is one of its possible types. * * @param abstractType abstract type either interface or union * @param concreteType concrete type * * @return true if possible type, false otherwise. */ public boolean isPossibleType(GraphQLType abstractType, GraphQLObjectType concreteType) { if (abstractType instanceof GraphQLInterfaceType) { return getImplementations((GraphQLInterfaceType) abstractType).stream() .map(GraphQLType::getName) .anyMatch(name -> concreteType.getName().equals(name)); } else if (abstractType instanceof GraphQLUnionType) { return ((GraphQLUnionType) abstractType).getTypes().stream() .map(GraphQLType::getName) .anyMatch(name -> concreteType.getName().equals(name)); } return assertShouldNeverHappen("Unsupported abstract type %s. Abstract types supported are Union and Interface.", abstractType.getName()); }
private List<? extends GraphQLType> getPossibleType(GraphQLType type) { List<? extends GraphQLType> possibleConditionTypes = null; if (type instanceof GraphQLObjectType) { possibleConditionTypes = Collections.singletonList(type); } else if (type instanceof GraphQLInterfaceType) { possibleConditionTypes = getValidationContext().getSchema().getImplementations((GraphQLInterfaceType) type); } else if (type instanceof GraphQLUnionType) { possibleConditionTypes = ((GraphQLUnionType) type).getTypes(); } else { Assert.assertShouldNeverHappen(); } return possibleConditionTypes; }
private boolean checkTypeCondition(FieldCollectorParameters parameters, GraphQLType conditionType) { GraphQLObjectType type = parameters.getObjectType(); if (conditionType.equals(type)) { return true; } if (conditionType instanceof GraphQLInterfaceType) { List<GraphQLObjectType> implementations = parameters.getGraphQLSchema().getImplementations((GraphQLInterfaceType) conditionType); return implementations.contains(type); } else if (conditionType instanceof GraphQLUnionType) { return ((GraphQLUnionType) conditionType).getTypes().contains(type); } return false; }
/** * Returns true if a specified concrete type is a possible type of a provided abstract type. * If the provided abstract type is: * - an interface, it checks whether the concrete type is one of its implementations. * - a union, it checks whether the concrete type is one of its possible types. * * @param abstractType abstract type either interface or union * @param concreteType concrete type * * @return true if possible type, false otherwise. */ public boolean isPossibleType(GraphQLType abstractType, GraphQLObjectType concreteType) { if (abstractType instanceof GraphQLInterfaceType) { return getImplementations((GraphQLInterfaceType) abstractType).stream() .map(GraphQLType::getName) .anyMatch(name -> concreteType.getName().equals(name)); } else if (abstractType instanceof GraphQLUnionType) { return ((GraphQLUnionType) abstractType).getTypes().stream() .map(GraphQLType::getName) .anyMatch(name -> concreteType.getName().equals(name)); } return assertShouldNeverHappen("Unsupported abstract type %s. Abstract types supported are Union and Interface.", abstractType.getName()); }
private List<? extends GraphQLType> getPossibleType(GraphQLType type) { List<? extends GraphQLType> possibleConditionTypes = null; if (type instanceof GraphQLObjectType) { possibleConditionTypes = Collections.singletonList(type); } else if (type instanceof GraphQLInterfaceType) { possibleConditionTypes = getValidationContext().getSchema().getImplementations((GraphQLInterfaceType) type); } else if (type instanceof GraphQLUnionType) { possibleConditionTypes = ((GraphQLUnionType) type).getTypes(); } else { Assert.assertShouldNeverHappen(); } return possibleConditionTypes; }