protected override bool VisitSelections(IOutputType outputType, SelectionSetNode selectionSet) { (outputType, selectionSet) = UnwrapOffsetBasedPaging(outputType, selectionSet); if (outputType.NamedType() is ObjectType type) { foreach (IFieldSelection selection in CollectExtendedFields(type, selectionSet)) { if (EnterSelection(selection)) { LeaveSelection(selection); } } } else { throw new QueryException( ErrorBuilder.New() .SetMessage( string.Format( CultureInfo.InvariantCulture, "UseSelection is in a invalid state. Type {0} is illegal!", outputType.NamedType().Name)) .Build()); } return(true); }
public static IObjectFieldDescriptor UsePaging <TSchemaType>( this IObjectFieldDescriptor descriptor) where TSchemaType : IOutputType, new() { FieldMiddleware placeholder = next => context => Task.CompletedTask; Type middlewareDefinition = typeof(QueryableConnectionMiddleware <>); descriptor .AddPagingArguments() .Type(ConnectionType <TSchemaType> .CreateWithTotalCount()) .Use(placeholder) .Extend() .OnBeforeCompletion((context, defintion) => { var reference = new ClrTypeReference( typeof(TSchemaType), TypeContext.Output); IOutputType type = context.GetType <IOutputType>(reference); if (type.NamedType() is IHasClrType hasClrType) { Type middlewareType = middlewareDefinition .MakeGenericType(hasClrType.ClrType); FieldMiddleware middleware = FieldClassMiddlewareFactory.Create(middlewareType); int index = defintion.MiddlewareComponents.IndexOf(placeholder); defintion.MiddlewareComponents[index] = middleware; } }) .DependsOn <TSchemaType>(); return(descriptor); }
public static IObjectFieldDescriptor UsePaging <TSchemaType>( this IObjectFieldDescriptor descriptor) where TSchemaType : class, IOutputType { FieldMiddleware placeholder = next => context => default(ValueTask); Type middlewareDefinition = typeof(QueryableConnectionMiddleware <>); descriptor .AddPagingArguments() .Type <ConnectionWithCountType <TSchemaType> >() .Use(placeholder) .Extend() .OnBeforeCompletion((context, defintion) => { ITypeReference reference = context.DescriptorContext.TypeInspector.GetTypeRef(typeof(TSchemaType)); IOutputType type = context.GetType <IOutputType>(reference); if (type.NamedType() is IHasRuntimeType hasClrType) { Type middlewareType = middlewareDefinition.MakeGenericType( hasClrType.RuntimeType); FieldMiddleware middleware = FieldClassMiddlewareFactory.Create( middlewareType); int index = defintion.MiddlewareComponents.IndexOf(placeholder); defintion.MiddlewareComponents[index] = middleware; } }) .DependsOn <TSchemaType>(); return(descriptor); }
protected virtual bool VisitSelections( IOutputType outputType, SelectionSetNode?selectionSet) { (outputType, selectionSet) = UnwrapPaging(outputType, selectionSet); if (outputType.NamedType() is ObjectType type && selectionSet is { })
protected virtual ISelectionVisitorAction VisitChildren( IOutputField field, TContext context) { IOutputType type = field.Type; SelectionSetNode?selectionSet = context.SelectionSetNodes.Peek(); INamedType namedType = type.NamedType(); if (namedType.IsAbstractType()) { IReadOnlyList <ObjectType> possibleTypes = context.Context.Schema.GetPossibleTypes(field.Type.NamedType()); foreach (var possibleType in possibleTypes) { ISelectionVisitorAction result = VisitObjectType(field, possibleType, selectionSet, context); if (result != Continue) { return(result); } } } else if (namedType is ObjectType a) { return(VisitObjectType(field, a, selectionSet, context)); } return(DefaultAction); }
private Field GetField( MatchSelectionsContext context, FieldNode node, IOutputType type) { if (GetDirective(node, "_field") is DirectiveNode directive && directive.Arguments.Count == 2 && directive.Arguments.FirstOrDefault(a => a.Name.Value.Equals("type")) is { } t&& directive.Arguments.FirstOrDefault(a => a.Name.Value.Equals("name")) is { } n) { return(new Field(t.Name.Value, n.Name.Value)); } return(new Field(type.NamedType().Name, node.Name.Value)); }
private bool TryUnwrapOffsetBasedPaging( IOutputType outputType, SelectionSetNode selectionSet, out (IOutputType, SelectionSetNode) result) { result = (null, null); if (outputType.NamedType() is ObjectType type) { foreach (IFieldSelection selection in Context.CollectFields(type, selectionSet)) { IFieldSelection currentSelection = GetOffsetBasedPagingFieldOrDefault(selection); if (currentSelection != null) { result = MergeSelection(result.Item2, currentSelection); } } } return(result.Item2 != null); }