public ConnectionBuilder <TSourceType> Connection <TNodeType, TEdgeType, TConnectionType>() where TNodeType : IGraphType where TEdgeType : EdgeType <TNodeType> where TConnectionType : ConnectionType <TNodeType, TEdgeType> { var builder = ConnectionBuilder.Create <TNodeType, TEdgeType, TConnectionType, TSourceType>(); AddField(builder.FieldType); return(builder); }
public void SqlWhere_WithQuery_SetsQueryOnFieldType() { void Where(WhereBuilder where, IReadOnlyDictionary <string, object> arguments, IResolveFieldContext context, SqlTable sqlAStNode) { } var builder = ConnectionBuilder.Create <ObjectGraphType, object>().SqlWhere(Where); builder.FieldType.GetSqlWhere().Should().Be((WhereDelegate)Where); }
public void SqlJoin_WithJoin_SetsJoinOnFieldType() { void Join(JoinBuilder join, IReadOnlyDictionary <string, object> arguments, IResolveFieldContext context, Node sqlAstNode) { } var builder = ConnectionBuilder.Create <ObjectGraphType, object>().SqlJoin(Join); builder.FieldType.GetSqlJoin().Should().Be((JoinDelegate)Join); }
void AddQueryableConnection <TSource, TGraph, TReturn>( IComplexGraphType graph, string name, Func <ResolveEfFieldContext <TDbContext, TSource>, IQueryable <TReturn> >?resolve, IEnumerable <QueryArgument>?arguments, int pageSize, string?description) where TGraph : IGraphType where TReturn : class { var builder = ConnectionBuilder.Create <TGraph, TSource>(); builder.Name(name); if (description != null) { builder.Description(description); } builder.PageSize(pageSize).Bidirectional(); if (resolve != null) { builder.Resolve( context => { var efFieldContext = BuildContext(context); var query = resolve(efFieldContext); if (disableTracking) { query = query.AsNoTracking(); } query = includeAppender.AddIncludes(query, context); var names = GetKeyNames <TReturn>(); query = query.ApplyGraphQlArguments(context, names, true); return(query .ApplyConnectionContext( context.First, context.After, context.Last, context.Before, context, context.CancellationToken, efFieldContext.Filters)); }); } // TODO: works around https://github.com/graphql-dotnet/graphql-dotnet/pull/2581/ builder.FieldType.Type = typeof(NonNullGraphType <ConnectionType <TGraph, EdgeType <TGraph> > >); var field = graph.AddField(builder.FieldType); var hasId = keyNames.ContainsKey(typeof(TReturn)); field.AddWhereArgument(hasId, arguments); }
ConnectionBuilder <FakeGraph, TSource> BuildQueryConnectionField <TSource, TReturn>( string name, Func <ResolveEfFieldContext <TDbContext, TSource>, IQueryable <TReturn> > resolve, int pageSize, Type?graphType) where TReturn : class { Guard.AgainstNullWhiteSpace(nameof(name), name); Guard.AgainstNull(nameof(resolve), resolve); Guard.AgainstNegative(nameof(pageSize), pageSize); //lookup the graph type if not explicitly specified graphType ??= GraphTypeFinder.FindGraphType <TReturn>(); //create a ConnectionBuilder<graphType, TSource> type by invoking the static Create method on the generic type var fieldType = GetFieldType <TSource>(name, graphType); //create a ConnectionBuilder<FakeGraph, TSource> which will be returned from this method var builder = ConnectionBuilder <FakeGraph, TSource> .Create(name); //set the page size builder.PageSize(pageSize); //using reflection, override the private field type property of the ConnectionBuilder<FakeGraph, TSource> to be the ConnectionBuilder<graphType, TSource> object SetField(builder, fieldType); //set the resolve function (note: this is not async capable) builder.Resolve( context => { //obtain the ef context var efFieldContext = BuildContext(context); //run the resolve function, then include the related tables on the returned query var withIncludes = includeAppender.AddIncludes(resolve(efFieldContext), context); //get field names of the table's primary key(s) var names = GetKeyNames <TReturn>(); //apply any query filters specified in the arguments var withArguments = withIncludes.ApplyGraphQlArguments(context, names); //apply skip/take to query as appropriate, and return the query return(withArguments .ApplyConnectionContext( context.First, context.After, context.Last, context.Before, context, context.CancellationToken, efFieldContext.Filters)); //note: does not apply global filters }); //return the field to be added to the graph return(builder); }
ConnectionBuilder <TSource> BuildQueryConnectionField <TSource, TReturn>( string name, Func <ResolveEfFieldContext <TDbContext, TSource>, IQueryable <TReturn> >?resolve, int pageSize, Type?itemGraphType, string?description) where TReturn : class { Guard.AgainstNullWhiteSpace(nameof(name), name); Guard.AgainstNegative(nameof(pageSize), pageSize); itemGraphType ??= GraphTypeFinder.FindGraphType <TReturn>(); var fieldType = GetFieldType <TSource>(name, itemGraphType); var builder = ConnectionBuilder <TSource> .Create <FakeGraph>(name); SetField(builder, fieldType); if (description != null) { builder.Description(description); } builder.PageSize(pageSize).Bidirectional(); if (resolve != null) { builder.Resolve( context => { var efFieldContext = BuildContext(context); var query = resolve(efFieldContext); if (disableTracking) { query = query.AsNoTracking(); } query = includeAppender.AddIncludes(query, context); var names = GetKeyNames <TReturn>(); query = query.ApplyGraphQlArguments(context, names, true); return(query .ApplyConnectionContext( context.First, context.After, context.Last, context.Before, context, context.CancellationToken, efFieldContext.Filters)); }); } return(builder); }
void AddEnumerableConnection <TSource, TGraph, TReturn>( ComplexGraphType <TSource> graph, string name, Func <ResolveEfFieldContext <TDbContext, TSource>, IEnumerable <TReturn> >?resolve, int pageSize, string?description, IEnumerable <QueryArgument>?arguments, IEnumerable <string>?includeNames) where TGraph : IGraphType where TReturn : class { var builder = ConnectionBuilder.Create <TGraph, TSource>(); builder.Name(name); if (description is not null) { builder.Description(description); } builder.PageSize(pageSize).Bidirectional(); IncludeAppender.SetIncludeMetadata(builder.FieldType, name, includeNames); var hasId = keyNames.ContainsKey(typeof(TReturn)); if (resolve is not null) { builder.ResolveAsync(async context => { var efFieldContext = BuildContext(context); var enumerable = resolve(efFieldContext); enumerable = enumerable.ApplyGraphQlArguments(hasId, context); enumerable = await efFieldContext.Filters.ApplyFilter(enumerable, context.UserContext); var page = enumerable.ToList(); return(ConnectionConverter.ApplyConnectionContext( page, context.First, context.After, context.Last, context.Before)); }); } // TODO: works around https://github.com/graphql-dotnet/graphql-dotnet/pull/2581/ builder.FieldType.Type = typeof(NonNullGraphType <ConnectionType <TGraph, EdgeType <TGraph> > >); var field = graph.AddField(builder.FieldType); field.AddWhereArgument(hasId, arguments); }
static async Task Main(string[] args) { try { LoginModelView loginModelView = new LoginModelView() { Email = args[0], Password = "******" }; var authorizationResult = await HttpRestClient.LoginAsync(loginModelView); Connection connection = await ConnectionBuilder.Create(authorizationResult); await connection.Session.Initialization(connection.User); connection.IncomingCall += async(sender, delegateArgs) => { Console.WriteLine("Połączenie przychodzące od {0}", delegateArgs.User); Console.WriteLine("Czy zgadzasz sie na połączenie T/N"); var answer = Console.ReadLine(); if (answer == "T") { await connection.CallAcceptedIncoming(delegateArgs.User); } else if (answer == "N") { await connection.CallDeclinedIncoming(delegateArgs.User); } }; foreach (var friend in connection.Friends) { Console.WriteLine(friend.Key + ": " + friend.Value); } if (args[0] == "*****@*****.**") { await connection.Call("*****@*****.**"); } Console.ReadKey(); connection.Close(); } catch (Exception e) { Console.WriteLine(e); throw; } }
ConnectionBuilder <FakeGraph, TSource> BuildListConnectionField <TSource, TReturn>( string name, Func <ResolveEfFieldContext <TDbContext, TSource>, IEnumerable <TReturn> > resolve, IEnumerable <string> includeName, int pageSize, Type graphType) where TReturn : class { Guard.AgainstNullWhiteSpace(nameof(name), name); Guard.AgainstNull(nameof(resolve), resolve); Guard.AgainstNegative(nameof(pageSize), pageSize); //lookup the graph type if not explicitly specified graphType = graphType ?? GraphTypeFinder.FindGraphType <TReturn>(); //create a ConnectionBuilder<graphType, TSource> type by invoking the static Create method on the generic type var fieldType = GetFieldType <TSource>(name, graphType); //create a ConnectionBuilder<FakeGraph, TSource> which will be returned from this method var builder = ConnectionBuilder <FakeGraph, TSource> .Create(name); //set the page size builder.PageSize(pageSize); //using reflection, override the private field type property of the ConnectionBuilder<FakeGraph, TSource> to be the ConnectionBuilder<graphType, TSource> object SetField(builder, fieldType); //add the metadata for the tables to be included in the query to the ConnectionBuilder<graphType, TSource> object IncludeAppender.SetIncludeMetadata(builder.FieldType, name, includeName); //set the custom resolver builder.ResolveAsync(async context => { var efFieldContext = BuildContext(context); //run the specified resolve function var enumerable = resolve(efFieldContext); //apply any query filters specified in the arguments enumerable = enumerable.ApplyGraphQlArguments(context); //apply the global filter on each individually enumerated item enumerable = await efFieldContext.Filters.ApplyFilter(enumerable, context.UserContext); //pagination does NOT occur server-side at this point, as the query has already executed var page = enumerable.ToList(); //return the proper page of data return(ConnectionConverter.ApplyConnectionContext( page, context.First, context.After, context.Last, context.Before)); }); //return the field to be added to the graph return(builder); }
public static ConnectionBuilder <TSourceType> Connection <TNodeType, TGraphType, TSourceType>( this ComplexGraphType <TNodeType> _this, IGraphTypesCache entityDtoCache, TGraphType itemType, string prefixName) where TGraphType : IGraphType { var type = entityDtoCache.GetOrCreateConnection(itemType, prefixName); var connectionBuilder = ConnectionBuilder <TSourceType> .Create <TGraphType>( $"{prefixName}{CommonConstants.GraphQlConnectionSuffix}"); connectionBuilder.FieldType.ResolvedType = type; _this.AddField(connectionBuilder.FieldType); return(connectionBuilder); }
ConnectionBuilder <TSource> BuildListConnectionField <TSource, TReturn>( string name, Func <ResolveEfFieldContext <TDbContext, TSource>, IEnumerable <TReturn> >?resolve, IEnumerable <string>?includeName, int pageSize, Type?itemGraphType, string?description) where TReturn : class { Guard.AgainstNullWhiteSpace(nameof(name), name); Guard.AgainstNegative(nameof(pageSize), pageSize); itemGraphType ??= GraphTypeFinder.FindGraphType <TReturn>(); var fieldType = GetFieldType <TSource>(name, itemGraphType); var builder = ConnectionBuilder <TSource> .Create <FakeGraph>(name); if (description != null) { builder.Description(description); } builder.PageSize(pageSize); SetField(builder, fieldType); IncludeAppender.SetIncludeMetadata(builder.FieldType, name, includeName); if (resolve != null) { builder.ResolveAsync(async context => { var efFieldContext = BuildContext(context); var enumerable = resolve(efFieldContext); enumerable = enumerable.ApplyGraphQlArguments(context); enumerable = await efFieldContext.Filters.ApplyFilter(enumerable, context.UserContext); var page = enumerable.ToList(); return(ConnectionConverter.ApplyConnectionContext( page, context.First, context.After, context.Last, context.Before)); }); } return(builder); }
ConnectionBuilder <FakeGraph, TSource> BuildQueryConnectionField <TSource, TReturn>( string name, Func <ResolveEfFieldContext <TDbContext, TSource>, IQueryable <TReturn> > resolve, int pageSize, Type graphType) where TReturn : class { Guard.AgainstNullWhiteSpace(nameof(name), name); Guard.AgainstNull(nameof(resolve), resolve); Guard.AgainstNegative(nameof(pageSize), pageSize); graphType = GraphTypeFinder.FindGraphType <TReturn>(graphType); var fieldType = GetFieldType <TSource>(name, graphType); var builder = ConnectionBuilder <FakeGraph, TSource> .Create(name); builder.PageSize(pageSize); SetField(builder, fieldType); builder.Resolve( context => { var efFieldContext = BuildEfContextFromGraphQlContext(context); var withIncludes = includeAppender.AddIncludes(resolve(efFieldContext), context); var names = GetKeyNames <TReturn>(); var withArguments = withIncludes.ApplyGraphQlArguments(context, names); return(withArguments .ApplyConnectionContext( context.First, context.After, context.Last, context.Before, context, context.CancellationToken, filters)); }); return(builder); }
private async void MainForm_Load(object sender, EventArgs e) { _resourceManager = Properties.Resources.ResourceManager; _imageStatusList = new ImageList(); // ReSharper disable once ResourceItemNotResolved _imageCloseTabPage = (Bitmap)_resourceManager.GetObject("close"); _imageNameList = new List <string>() { "False", "True" }; foreach (var imageName in _imageNameList) { _imageStatusList.Images.Add((Bitmap)_resourceManager?.GetObject(imageName)); } listViewFriends.SmallImageList = _imageStatusList; LoginForm loginForm = new LoginForm(); if (loginForm.ShowDialog() == DialogResult.OK) { _connection = await ConnectionBuilder.Create(loginForm.AuthorizationResult); await _connection.Session.Initialization(loginForm.AuthorizationResult.User); foreach (var friend in _connection.Friends) { if (friend.Value == true) { listViewFriends.Items.Add(friend.Key, friend.Key, 1); } else { listViewFriends.Items.Add(friend.Key, friend.Key, 0); } } } _connection.ChangeStatusFriend += (o, args) => { if (args.Status == true) { listViewFriends.Items[args.UserName].ImageIndex = 1; if (TabControlChat.Controls.Count != 0) { if (TabControlChat.SelectedTab == TabControlChat.TabPages[args.UserName]) { sendMessageButton.Enabled = true; } } } else { listViewFriends.Items[args.UserName].ImageIndex = 0; if (TabControlChat.Controls.Count != 0) { if (TabControlChat.SelectedTab == TabControlChat.TabPages[args.UserName]) { sendMessageButton.Enabled = false; } } } }; _connection.SendMessage += (o, args) => { TabPage page = TabControlChat.TabPages[args.UserName]; RichTextBox richTextBox = page.Controls[0] as RichTextBox; richTextBox?.AppendText("\r\n"); richTextBox?.AppendText("Ja :" + args.Message); }; _connection.ReceiveMessage += (o, args) => { if (TabControlChat.TabPages[args.UserName] == null) { TabPage page = new TabPage(args.UserName) { Name = args.UserName }; RichTextBox richTextBox = new RichTextBox { Text = args.UserName + @": " + args.Message, Dock = DockStyle.Fill, ReadOnly = true }; page.Controls.Add(richTextBox); TabControlChat.Controls.Add(page); } else { var page = TabControlChat.TabPages[args.UserName]; RichTextBox richTextBox = page.Controls[0] as RichTextBox; richTextBox?.AppendText("\r\n"); richTextBox?.AppendText(args.UserName + @": " + args.Message); } }; _connection.IncomingCall += (o, args) => { buttonCall.Visible = false; buttonCancel.Visible = false; buttonCallDeclined.Visible = true; buttonCallAccepted.Visible = true; userName = args.User; }; }
public void SqlPaginate_WhenCalled_SetsPaginateOnFieldType() { var builder = ConnectionBuilder.Create <ObjectGraphType, object>().SqlPaginate(true); builder.FieldType.GetSqlPaginate().Should().BeTrue(); }