Skip to content

Commit cd17811

Browse files
Merge pull request #63 from RamyaSubramaniSF4537/1007133-UG3
1007133: Updated the sample
2 parents 800e21f + 6074af0 commit cd17811

103 files changed

Lines changed: 4177 additions & 272 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk.Web">
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<PackageReference Include="HotChocolate.AspNetCore" Version="13.3.1" />
10+
<PackageReference Include="Syncfusion.Blazor.Themes" Version="*" />
11+
<!--<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
12+
<PackageReference Include="Quick.AspNetCore.Components.Web.Extensions" Version="6.0.2" />
13+
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />-->
14+
</ItemGroup>
15+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk.Web">
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<PackageReference Include="HotChocolate.AspNetCore" Version="13.3.1" />
10+
<PackageReference Include="Syncfusion.Blazor.Themes" Version="*" />
11+
<!--<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
12+
<PackageReference Include="Quick.AspNetCore.Components.Web.Extensions" Version="6.0.2" />
13+
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />-->
14+
</ItemGroup>
15+
</Project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+

2+
using ASPNetCoreGraphQlServer.Models;
3+
using System.Collections;
4+
using System.ComponentModel;
5+
using System.Dynamic;
6+
using System.Linq;
7+
using System.Linq.Expressions;
8+
using System.Reflection;
9+
10+
namespace ASPNetCoreGraphQlServer.GraphQl
11+
{
12+
public class GraphQLQuery
13+
{
14+
15+
#region OrdersData Resolver
16+
public ReturnType<Order> OrdersData(DataManagerRequest dataManager)
17+
{
18+
IEnumerable<Order> result = Orders;
19+
int count = result.Count();
20+
return dataManager.RequiresCounts ? new ReturnType<Order>() { Result = result, Count = count } : new ReturnType<Order>() { Result = result };
21+
}
22+
23+
public static List<Order> Orders { get; set; } = GetOrdersList();
24+
25+
private static List<Order> GetOrdersList()
26+
{
27+
var data = new List<Order>();
28+
data.Add(new Order() { OrderID = 1, EmployeeID = "Production Manager", CustomerID = "", OrderDate = new DateTime(2023, 08, 23), Freight = 5.7 * 2, Address = new CustomerAddress() { ShipCity = "Berlin", ShipCountry = "Denmark" } });
29+
data.Add(new Order() { OrderID = 2, EmployeeID = "Control Room", CustomerID = "1", OrderDate = new DateTime(1994, 08, 24), Freight = 6.7 * 2, Address = new CustomerAddress() { ShipCity = "Madrid", ShipCountry = "Brazil" } });
30+
data.Add(new Order() { OrderID = 3, EmployeeID = "Plant Operator", CustomerID = "1", OrderDate = new DateTime(1993, 08, 25), Freight = 7.7 * 2, Address = new CustomerAddress() { ShipCity = "Cholchester", ShipCountry = "Germany" } });
31+
data.Add(new Order() { OrderID = 4, EmployeeID = "Foreman", CustomerID = "2", OrderDate = new DateTime(1992, 08, 26), Freight = 8.7 * 2, Address = new CustomerAddress() { ShipCity = "Marseille", ShipCountry = "Austria" } });
32+
data.Add(new Order() { OrderID = 5, EmployeeID = "Foreman", CustomerID = "3", OrderDate = new DateTime(1991, 08, 27), Freight = 9.7 * 2, Address = new CustomerAddress() { ShipCity = "Tsawassen", ShipCountry = "Switzerland" } });
33+
data.Add(new Order() { OrderID = 6, EmployeeID = "Craft Personnel", CustomerID = "4", OrderDate = new DateTime(1991, 08, 27), Freight = 9.7 * 2, Address = new CustomerAddress() { ShipCity = "Tsawassen", ShipCountry = "Switzerland" } });
34+
data.Add(new Order() { OrderID = 7, EmployeeID = "Craft Personnel", CustomerID = "4", OrderDate = new DateTime(1991, 08, 27), Freight = 9.7 * 2, Address = new CustomerAddress() { ShipCity = "Tsawassen", ShipCountry = "Switzerland" } });
35+
data.Add(new Order() { OrderID = 8, EmployeeID = "Craft Personnel", CustomerID = "5", OrderDate = new DateTime(1991, 08, 27), Freight = 9.7 * 2, Address = new CustomerAddress() { ShipCity = "Tsawassen", ShipCountry = "Switzerland" } });
36+
data.Add(new Order() { OrderID = 9, EmployeeID = "Craft Personnel", CustomerID = "5", OrderDate = new DateTime(1991, 08, 27), Freight = 9.7 * 2, Address = new CustomerAddress() { ShipCity = "Tsawassen", ShipCountry = "Switzerland" } });
37+
return data;
38+
}
39+
#endregion
40+
41+
}
42+
43+
44+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
namespace ASPNetCoreGraphQlServer.Models
2+
{
3+
public class DataManagerRequest
4+
{
5+
[GraphQLName("Skip")]
6+
public int Skip { get; set; }
7+
8+
[GraphQLName("Take")]
9+
public int Take { get; set; }
10+
11+
[GraphQLName("RequiresCounts")]
12+
public bool RequiresCounts { get; set; } = false;
13+
14+
[GraphQLName("Params")]
15+
[GraphQLType(typeof(AnyType))]
16+
public IDictionary<string, object> Params { get; set; }
17+
18+
19+
[GraphQLName("Aggregates")]
20+
[GraphQLType(typeof(AnyType))]
21+
public List<Aggregate>? Aggregates { get; set; }
22+
23+
[GraphQLName("Search")]
24+
public List<SearchFilter>? Search { get; set; }
25+
26+
[GraphQLName("Sorted")]
27+
public List<Sort>? Sorted { get; set; }
28+
29+
[GraphQLName("Where")]
30+
[GraphQLType(typeof(AnyType))]
31+
public List<WhereFilter>? Where { get; set; }
32+
33+
[GraphQLName("Group")]
34+
public List<string>? Group { get; set; }
35+
36+
[GraphQLName("antiForgery")]
37+
38+
public string? antiForgery { get; set; }
39+
40+
[GraphQLName("Table")]
41+
public string? Table { get; set; }
42+
43+
[GraphQLName("IdMapping")]
44+
public string? IdMapping { get; set; }
45+
46+
[GraphQLName("Select")]
47+
public List<string>? Select { get; set; }
48+
49+
[GraphQLName("Expand")]
50+
public List<string>? Expand { get; set; }
51+
52+
[GraphQLName("Distinct")]
53+
public List<string>? Distinct { get; set; }
54+
55+
[GraphQLName("ServerSideGroup")]
56+
public bool? ServerSideGroup { get; set; }
57+
58+
[GraphQLName("LazyLoad")]
59+
public bool? LazyLoad { get; set; }
60+
61+
[GraphQLName("LazyExpandAllGroup")]
62+
public bool? LazyExpandAllGroup { get; set; }
63+
}
64+
65+
public class Aggregate
66+
{
67+
[GraphQLName("Field")]
68+
public string Field { get; set; }
69+
70+
[GraphQLName("Type")]
71+
public string Type { get; set; }
72+
}
73+
74+
public class SearchFilter
75+
{
76+
[GraphQLName("Fields")]
77+
public List<string> Fields { get; set; }
78+
79+
[GraphQLName("Key")]
80+
public string Key { get; set; }
81+
82+
[GraphQLName("Operator")]
83+
public string Operator { get; set; }
84+
85+
[GraphQLName("IgnoreCase")]
86+
public bool IgnoreCase { get; set; }
87+
}
88+
89+
public class Sort
90+
{
91+
[GraphQLName("Name")]
92+
public string Name { get; set; }
93+
94+
[GraphQLName("Direction")]
95+
public string Direction { get; set; }
96+
97+
[GraphQLName("Comparer")]
98+
[GraphQLType(typeof(AnyType))]
99+
public object Comparer { get; set; }
100+
}
101+
102+
public class WhereFilter
103+
{
104+
[GraphQLName("Field")]
105+
public string? Field { get; set; }
106+
107+
[GraphQLName("IgnoreCase")]
108+
public bool? IgnoreCase { get; set; }
109+
110+
[GraphQLName("IgnoreAccent")]
111+
public bool? IgnoreAccent { get; set; }
112+
113+
[GraphQLName("IsComplex")]
114+
public bool? IsComplex { get; set; }
115+
116+
[GraphQLName("Operator")]
117+
public string? Operator { get; set; }
118+
119+
[GraphQLName("Condition")]
120+
public string? Condition { get; set; }
121+
122+
[GraphQLName("value")]
123+
[GraphQLType(typeof(AnyType))]
124+
public object? value { get; set; }
125+
126+
[GraphQLName("predicates")]
127+
public List<WhereFilter>? predicates { get; set; }
128+
}
129+
130+
public class ReturnType<T>
131+
{
132+
public int Count { get; set; }
133+
134+
public IEnumerable<T> Result { get; set; }
135+
136+
[GraphQLType(typeof(AnyType))]
137+
public IDictionary<string, object> Aggregates { get; set; }
138+
}
139+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace ASPNetCoreGraphQlServer.Models
2+
{
3+
public class Order
4+
{
5+
[GraphQLName("OrderID")]
6+
public int? OrderID { get; set; }
7+
8+
[GraphQLName("CustomerID")]
9+
public string? CustomerID { get; set; }
10+
11+
[GraphQLName("EmployeeID")]
12+
public string EmployeeID { get; set; }
13+
14+
[GraphQLName("OrderDate")]
15+
public DateTime? OrderDate { get; set; }
16+
17+
[GraphQLName("Freight")]
18+
public double? Freight { get; set; }
19+
20+
[GraphQLName("Address")]
21+
public CustomerAddress? Address { get; set; }
22+
}
23+
24+
public class CustomerAddress
25+
{
26+
[GraphQLName("ShipCity")]
27+
public string ShipCity { get; set; }
28+
29+
[GraphQLName("ShipCountry")]
30+
public string ShipCountry { get; set; }
31+
}
32+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using ASPNetCoreGraphQlServer.GraphQl;
2+
using HotChocolate.AspNetCore;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
6+
builder.Services.AddGraphQLServer().AddQueryType<GraphQLQuery>();
7+
builder.Services.AddCors(options =>
8+
{
9+
options.AddPolicy("AllowSpecificOrigin", builder =>
10+
{
11+
builder.WithOrigins("https://localhost:7021")
12+
.AllowAnyHeader()
13+
.AllowAnyMethod()
14+
.AllowCredentials().Build();
15+
});
16+
});
17+
18+
19+
var app = builder.Build();
20+
app.UseCors("AllowSpecificOrigin");
21+
app.UseRouting();
22+
app.UseEndpoints(endpoints => endpoints.MapGraphQL());
23+
app.MapGet("/", () => "Hello World!");
24+
app.Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:33975",
7+
"sslPort": 44358
8+
}
9+
},
10+
"profiles": {
11+
"http": {
12+
"commandName": "Project",
13+
"dotnetRunMessages": true,
14+
"launchBrowser": true,
15+
"applicationUrl": "http://localhost:5251",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"https": {
21+
"commandName": "Project",
22+
"dotnetRunMessages": true,
23+
"launchBrowser": true,
24+
"applicationUrl": "https://localhost:7131;http://localhost:5251",
25+
"environmentVariables": {
26+
"ASPNETCORE_ENVIRONMENT": "Development"
27+
}
28+
},
29+
"IIS Express": {
30+
"commandName": "IISExpress",
31+
"launchBrowser": true,
32+
"environmentVariables": {
33+
"ASPNETCORE_ENVIRONMENT": "Development"
34+
}
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@namespace BlazorApplication
2+
<Router AppAssembly="@typeof(App).Assembly">
3+
<Found Context="routeData">
4+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
5+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
6+
</Found>
7+
<NotFound>
8+
<PageTitle>Not found</PageTitle>
9+
<LayoutView Layout="@typeof(MainLayout)">
10+
<p role="alert">Sorry, there's nothing at this address.</p>
11+
</LayoutView>
12+
</NotFound>
13+
</Router>
14+

0 commit comments

Comments
 (0)