public void Resolve(GraphQLQuery graphQLQuery) { graphQLQuery.Field <StringGraphType>( name: "hello", resolve: context => "Hello World" ); }
public void Resolve(GraphQLQuery graphQLQuery) { graphQLQuery.Field <ResponseListGraphType <StringGraphType> >( "tags", resolve: context => { var tags = _tagsService.GetAvailableTagsAsync().GetAwaiter().GetResult(); return(Response(tags)); } ); }
public void Resolve(GraphQLQuery graphQLQuery) { graphQLQuery.Field <ResponseListGraphType <GroupType> >( "groups", resolve: context => { var groups = _groupsService.GetGroupsAsync().GetAwaiter().GetResult(); return(Response(groups)); } ); }
public void Resolve(GraphQLQuery graphQLQuery) { graphQLQuery.Field <ResponseListGraphType <BranchType> >( "branches", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "projectId", Description = "id of the project" } ), resolve: context => { var projectId = context.GetArgument <string>("projectId"); var list = _branchesService.GetBranchesAsync(projectId).GetAwaiter().GetResult(); return(Response(list)); } ); graphQLQuery.Field <ResponseGraphType <BranchType> >( "branch", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "projectId", Description = "id of the project" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "branchName", Description = "name of the branch" } ), resolve: context => { var projectId = context.GetArgument <string>("projectId"); var branchName = context.GetArgument <string>("branchName"); var branch = _branchesService.GetBranchAsync(projectId, branchName).GetAwaiter().GetResult(); if (branch == null) { return(NotFoundError(branchName)); } return(Response(branch)); } ); }
public void Resolve(GraphQLQuery graphQLQuery) { graphQLQuery.Field <ResponseGraphType <StringGraphType> >( "document", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "projectId", Description = "id of the project" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "branchName", Description = "name of the branch" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "fileUri", Description = "url of the file" } ), resolve: context => { var projectId = context.GetArgument <string>("projectId"); var branchName = context.GetArgument <string>("branchName"); var fileUri = context.GetArgument <string>("fileUri"); var document = _documentsService.GetDocumentAsync(projectId, branchName, fileUri).GetAwaiter().GetResult(); if (document == null) { return(NotFoundError(fileUri)); } byte[] content = document.Content; string contentType = document.ConentType; if (document.ConentType == "text/markdown") { var markdown = System.Text.Encoding.UTF8.GetString(document.Content); var html = _markdownService.ConvertToHtml(markdown); content = System.Text.Encoding.UTF8.GetBytes(html); var base64Html = Convert.ToBase64String(content); return(Response(base64Html)); } return(Error(new FileTypeNotSupportedError(document.ConentType))); } ); }
public void Resolve(GraphQLQuery graphQLQuery) { graphQLQuery.Field <ResponseListGraphType <ChapterItemType> >( "chapters", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "projectId", Description = "id of the project" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "branchName", Description = "name of the branch" } ), resolve: context => { var projectId = context.GetArgument <string>("projectId"); var branchName = context.GetArgument <string>("branchName"); var chapters = _tableOfContentsService.GetTableOfConents(projectId, branchName).GetAwaiter().GetResult(); return(Response(chapters)); } ); }
public void Resolve(GraphQLQuery graphQLQuery) { graphQLQuery.Field <StringGraphType>( name: "hello2", resolve: context => "Hello World 2" ); // graphQLQuery.Field<ItemType>( // "item", // arguments: new QueryArguments(new QueryArgument<StringGraphType> { Name = "barcode" }), // resolve: context => // { // var barcode = context.GetArgument<string>("barcode"); // return new DataSource().GetItemByBarcode(barcode); // } // ); // /* // { // "query":"{ // items { // title // sellingPrice // barcode // } // }" // } // */ // graphQLQuery.Field<ListGraphType<ItemType>>( // "items", // resolve: context => // { // return new DataSource().GetItems(); // } //); }
public void Resolve(GraphQLQuery graphQLQuery) { graphQLQuery.Field <ResponseGraphType <ProjectsResultsType> >( "projects", arguments: new QueryArguments( new QueryArgument <ListGraphType <StringGraphType> > { Name = "groups", Description = "Limit projects by project group." }, new QueryArgument <ListGraphType <StringGraphType> > { Name = "tags", Description = "Limit projects by project tags." }, new QueryArgument <StringGraphType> { Name = "query", Description = "Search projects which contains specific query." }, new QueryArgument <IntGraphType> { Name = "page", Description = "Number of page to show." }, new QueryArgument <IntGraphType> { Name = "limit", Description = "Number of rows to show on page." } ), resolve: context => { var groups = context.GetArgument <IList <string> >("groups"); var tags = context.GetArgument <IList <string> >("tags"); var query = context.GetArgument <string>("query"); int page = 0; if (context.Arguments["page"] != null) { page = context.GetArgument <int>("page", 10); } int limit = 0; if (context.Arguments["limit"] != null) { limit = context.GetArgument <int>("limit", 10); } var user = context.UserContext as ClaimsPrincipal; groups = groups.Count == 0 ? null : groups; tags = tags.Count == 0 ? null : tags; var projects = _projectsService.GetProjectsAsync( new ProjectsFilterDto { Groups = groups, Tags = tags, Query = query, Page = page, Limit = limit }, user.Identity.Name ).GetAwaiter().GetResult(); return(Response(projects)); } ); graphQLQuery.Field <ResponseGraphType <ProjectType> >( "project", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the project" } ), resolve: context => { var id = context.GetArgument <string>("id"); var project = _projectsService.GetProjectAsync(id).GetAwaiter().GetResult(); if (project == null) { return(NotFoundError(id)); } var user = context.UserContext as ClaimsPrincipal; var authorization = _authorizationService.AuthorizeAsync(user, project, Operations.Read).GetAwaiter().GetResult(); if (!authorization.Succeeded) { return(AccessDeniedError()); } return(Response(project)); } ); }