static IObjectGraphType GetTypeOf(IAbstractGraphType abstractType, object value) { foreach (var possible in abstractType.PossibleTypes.List) { if (possible.IsTypeOf != null && possible.IsTypeOf(value)) { return(possible); } } return(null); }
/// <summary> /// Returns the proper graph type for the specified object for this abstract graph type. If the abstract /// graph type implements <see cref="IAbstractGraphType.ResolveType"/>, then this method is called to determine /// the best graph type to use. Otherwise, <see cref="IObjectGraphType.IsTypeOf"/> is called on each possible /// graph type supported by the abstract graph type to determine if a match can be found. /// </summary> public static IObjectGraphType GetObjectType(this IAbstractGraphType abstractType, object value, ISchema schema) { var result = abstractType.ResolveType != null ? abstractType.ResolveType(value) : GetTypeOf(abstractType, value); if (result is GraphQLTypeReference reference) { result = schema.AllTypes[reference.TypeName] as IObjectGraphType; } return(result);
/// <summary> /// Returns true if the specified graph type is one of the possible graph types for this abstract graph type. /// </summary> public static bool IsPossibleType(this IAbstractGraphType abstractType, IGraphType type) { foreach (var possible in abstractType.PossibleTypes.List) { if (possible.Equals(type)) { return(true); } } return(false); }
public static ExecutionNode BuildExecutionNode(ExecutionNode parent, IGraphType graphType, Field field, FieldType fieldDefinition, int?indexInParentNode = null) { if (graphType is NonNullGraphType nonNullFieldType) { graphType = nonNullFieldType.ResolvedType; } return(graphType switch { ListGraphType _ => new ArrayExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode), IObjectGraphType _ => new ObjectExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode), IAbstractGraphType _ => new ObjectExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode), ScalarGraphType _ => new ValueExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode), _ => throw new InvalidOperationException($"Unexpected type: {graphType}") });
/// <summary> /// Builds an execution node with the specified parameters. /// </summary> protected ExecutionNode BuildSubscriptionExecutionNode(ExecutionNode parent, IGraphType graphType, Field field, FieldType fieldDefinition, int?indexInParentNode, object source) { if (graphType is NonNullGraphType nonNullFieldType) { graphType = nonNullFieldType.ResolvedType; } return(graphType switch { ListGraphType _ => new SubscriptionArrayExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode, source), IObjectGraphType _ => new SubscriptionObjectExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode, source), IAbstractGraphType _ => new SubscriptionObjectExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode, source), ScalarGraphType scalarGraphType => new SubscriptionValueExecutionNode(parent, scalarGraphType, field, fieldDefinition, indexInParentNode, source), _ => throw new InvalidOperationException($"Unexpected type: {graphType}") });
public static ExecutionNode BuildExecutionNode(ExecutionNode parent, IGraphType graphType, Field field, FieldType fieldDefinition, string[] path = null) { path ??= AppendPath(parent.Path, field.Name); if (graphType is NonNullGraphType nonNullFieldType) { graphType = nonNullFieldType.ResolvedType; } return(graphType switch { ListGraphType _ => new ArrayExecutionNode(parent, graphType, field, fieldDefinition, path), IObjectGraphType _ => new ObjectExecutionNode(parent, graphType, field, fieldDefinition, path), IAbstractGraphType _ => new ObjectExecutionNode(parent, graphType, field, fieldDefinition, path), ScalarGraphType _ => new ValueExecutionNode(parent, graphType, field, fieldDefinition, path), _ => throw new InvalidOperationException($"Unexpected type: {graphType}") });
public static IObjectGraphType GetTypeOf(this IAbstractGraphType abstractType, object value) { return(abstractType.PossibleTypes.FirstOrDefault(type => type.IsTypeOf != null && type.IsTypeOf(value))); }
public static bool IsPossibleType(this IAbstractGraphType abstractType, IGraphType type) { return(abstractType.PossibleTypes.Any(x => x.Equals(type))); }
public static IObjectGraphType GetObjectType(this IAbstractGraphType abstractType, object value) { return(abstractType.ResolveType != null ? abstractType.ResolveType(value) : GetTypeOf(abstractType, value)); }