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); }
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); }
protected virtual ISelectionVisitorAction VisitChildren( IOutputField field, TContext context) { IOutputType type = field.Type; SelectionSetNode?selectionSet = context.SelectionSetNodes.Peek(); if (TryGetObjectType(type, out ObjectType? objectType) && selectionSet is not null) { IReadOnlyList <IFieldSelection> selections = context.Context.GetSelections( objectType, selectionSet, true); for (var i = 0; i < selections.Count; i++) { if (selections[i] is ISelection selection) { if (Visit(selection, context).Kind == SelectionVisitorActionKind.Break) { return(Break); } } } } return(DefaultAction); }
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 QueryableProjectionContext( IResolverContext context, IOutputType initialType, Type runtimeType) : base(context, initialType, new QueryableProjectionScope(runtimeType, "_s1")) { }
public void Analyse(IOutputType outputType) { var trackId = _interaction.GetTrackId(); var trackResults = ParseApi.GetResultsFor(trackId); outputType.Print(trackResults); }
protected override ISyntaxVisitorAction Enter( FieldNode node, MatchSelectionsContext context) { IOutputType outputType = context.Types.Peek(); Field field = GetField(context, node, outputType); if (context.Selections.TryGetValue(field.FieldName, out ISelection? selection)) { context.Count++; if (selection.Field.Type.IsCompositeType()) { Debug.Assert( selection.SelectionSet is not null, "A composite type must have a selection set."); foreach (IObjectType possibleType in context.Operation.GetPossibleTypes(selection.SelectionSet !)) { ISelectionSet selectionSet = context.Operation.GetSelectionSet(selection.SelectionSet !, possibleType); return(base.Enter(node, context.Branch(possibleType, selectionSet))); } } } return(Skip); }
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 { })
public override FieldNode OnRewriteField( NameString targetSchemaName, IOutputType outputType, IOutputField outputField, FieldNode field) { return(field.WithAlias(new NameNode("foo_bar"))); }
/// <summary> /// This method will be called after the stitching layer /// has rewritten a field and allows to add custom rewriter logic. /// </summary> /// <param name="targetSchemaName"> /// The name of the schema to which the query shall be delegated. /// </param> /// <param name="outputType"> /// The current output type on which the selection set is declared. /// </param> /// <param name="outputField"> /// The current output field on which this selection set is declared. /// </param> /// <param name="selectionSet"> /// The list of selections that shall be added to the delegation query. /// </param> public virtual FieldNode OnRewriteField( NameString targetSchemaName, IOutputType outputType, IOutputField outputField, FieldNode field) { return(field); }
/// <summary> /// This method will be called after the stitching layer /// has rewritten a selection set and allows to add custom /// rewriter logic. /// </summary> /// <param name="targetSchemaName"> /// The name of the schema to which the query shall be delegated. /// </param> /// <param name="outputType"> /// The current output type on which the selection set is declared. /// </param> /// <param name="outputField"> /// The current output field on which this selection set is declared. /// </param> /// <param name="selectionSet"> /// The list of selections that shall be added to the delegation query. /// </param> public virtual SelectionSetNode OnRewriteSelectionSet( NameString targetSchemaName, IOutputType outputType, IOutputField outputField, SelectionSetNode selectionSet) { return(selectionSet); }
protected override void OnCompleteType( ITypeInitializationContext context) { EntityType = context.GetType <T>( new TypeReference(typeof(T))); base.OnCompleteType(context); }
protected override void OnCompleteType( ITypeCompletionContext context, ObjectTypeDefinition definition) { base.OnCompleteType(context, definition); ItemType = context.GetType <IOutputType>( context.TypeInspector.GetTypeRef(typeof(T))); }
protected override void OnCompleteType( ITypeCompletionContext context, ObjectTypeDefinition definition) { base.OnCompleteType(context, definition); EntityType = context.GetType <IOutputType>( TypeReference.Create <T>()); }
protected override void OnCompleteType( ICompletionContext context, ObjectTypeDefinition definition) { base.OnCompleteType(context, definition); EntityType = context.GetType <T>( ClrTypeReference.FromSchemaType <T>()); }
public void Analyse(IOutputType outputType) { int maxTrackId = int.Parse(ConfigurationManager.AppSettings["NumTracks"]); for (int trackId = 0; trackId < maxTrackId; trackId++) { var results = ParseApi.GetResultsFor(trackId); outputType.Print(results); _ui.WaitForInteraction(); } }
protected override void OnCompleteType( ICompletionContext context, ObjectTypeDefinition definition) { base.OnCompleteType(context, definition); EntityType = context.GetType <T>( new ClrTypeReference( typeof(T), TypeContext.Output)); }
public void Accept(IObjectField field) { IOutputType type = field.Type; SelectionSetNode?selectionSet = Context.FieldSelection.SelectionSet; (type, selectionSet) = UnwrapPaging(type, selectionSet); IType elementType = type.IsListType() ? type.ElementType() : type; Closures.Push(new SelectionClosure(elementType.ToRuntimeType(), "e")); VisitSelections(type, selectionSet); }
public new void Accept(ObjectField field) { IOutputType type = field.Type; SelectionSetNode selectionSet = Context.FieldSelection.SelectionSet; (type, selectionSet) = UnwrapOffsetBasedPaging(type, selectionSet); IType elementType = type.IsListType() ? type.ElementType() : type; Closures.Push(new SelectionClosure(elementType.ToClrType(), "e")); VisitSelections(type, selectionSet); }
public void Analyse(IOutputType outputType) { int maxTrackId = int.Parse(ConfigurationManager.AppSettings["NumTracks"]); var allData = new List<TrackData>(); var loadingBar = new LoadingBar("Fetching Data", maxTrackId); loadingBar.Start(); for (int trackId = 0; trackId < maxTrackId; trackId++) { allData.Add(ParseApi.GetResultsFor(trackId)); loadingBar.Next(); } outputType.Print(allData); }
private static void WriteLine(IOutputType item) { Console.ForegroundColor = item.Type == OutputType.TestFail || item.Type == OutputType.Error ? ConsoleColor.Red : item.Type == OutputType.TestPass ? ConsoleColor.DarkGreen : item.Type == OutputType.TestSkip ? ConsoleColor.DarkYellow : ConsoleColor.White; if (item.Type == OutputType.TestFail || item.Type == OutputType.Error || item.Type == OutputType.TestPass || item.Type == OutputType.TestSkip || item.Type == OutputType.Other) { Console.WriteLine(item.ToString()); } }
public void Analyse(IOutputType outputType) { int maxTrackId = int.Parse(ConfigurationManager.AppSettings["NumTracks"]); var allData = new List <TrackData>(); var loadingBar = new LoadingBar("Fetching Data", maxTrackId); loadingBar.Start(); for (int trackId = 0; trackId < maxTrackId; trackId++) { allData.Add(ParseApi.GetResultsFor(trackId)); loadingBar.Next(); } outputType.Print(allData); }
public List <IOutputType> Process() { IOutputType result = null; if (typeof(T) == EmailMerge) { result = new MailMessage(); } // etc.. // do stuff.. return(result); }
protected ProjectionVisitorContext( IResolverContext context, IOutputType initialType, ProjectionScope <T> projectionScope) : base(context) { if (initialType is null) { throw new ArgumentNullException(nameof(initialType)); } Types.Push(initialType); Scopes = new Stack <ProjectionScope <T> >(); Scopes.Push(projectionScope); }
public OutputFieldModel( string name, string?description, IOutputField field, IOutputType type, FieldNode selection, Path path) { Name = name; Description = description; Field = field; Selection = selection; Path = path; Type = type; }
public OutputFieldModel( NameString name, string?description, IOutputField field, IOutputType type, FieldNode syntaxNode, Path path) { Name = name.EnsureNotEmpty(nameof(name)); Description = description; Field = field ?? throw new ArgumentNullException(nameof(field)); SyntaxNode = syntaxNode ?? throw new ArgumentNullException(nameof(syntaxNode)); Path = path ?? throw new ArgumentNullException(nameof(path)); Type = type ?? throw new ArgumentNullException(nameof(type)); }
public void DotNetStringType() { // arrange TypeRegistry typeRegistry = new TypeRegistry(); typeRegistry.RegisterType(typeof(StringType)); Type nativeType = typeof(string); // act TypeInspector typeInspector = new TypeInspector(); IOutputType type = typeInspector.CreateOutputType(typeRegistry, nativeType); // assert Assert.IsType <StringType>(type); }
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)); }
public void DotNetBoolType() { // arrange TypeRegistry typeRegistry = new TypeRegistry(); typeRegistry.RegisterType(typeof(BooleanType)); Type nativeType = typeof(bool); // act TypeInspector typeInspector = new TypeInspector(); IOutputType type = typeInspector.CreateOutputType(typeRegistry, nativeType); // assert Assert.IsType <BooleanType>(type); }
private (IOutputType, SelectionSetNode) UnwrapOffsetBasedPaging( IOutputType outputType, SelectionSetNode selectionSet) { if (outputType is ISearchResult) { if (TryUnwrapOffsetBasedPaging( outputType, selectionSet, out (IOutputType, SelectionSetNode)result)) { return(result); } } return(outputType, selectionSet); }