Skip to content

Commit

Permalink
864801: GraphQLSample
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiruthika-3470 committed Jan 3, 2024
1 parent b280346 commit 0965f16
Show file tree
Hide file tree
Showing 191 changed files with 203,624 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASPNetCoreGraphQlServer", "ASPNetCoreGraphQlServer\ASPNetCoreGraphQlServer.csproj", "{E72A3609-D956-46FB-9B4B-22C6A39E5E22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E72A3609-D956-46FB-9B4B-22C6A39E5E22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E72A3609-D956-46FB-9B4B-22C6A39E5E22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E72A3609-D956-46FB-9B4B-22C6A39E5E22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E72A3609-D956-46FB-9B4B-22C6A39E5E22}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {76E90D33-6F64-48FF-8B69-FC5DD21951EF}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HotChocolate.AspNetCore" Version="13.3.1" />
<!--<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Quick.AspNetCore.Components.Web.Extensions" Version="6.0.2" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />-->
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

using ASPNetCoreGraphQlServer.Models;
using System.Collections;
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;

namespace ASPNetCoreGraphQlServer.GraphQl
{
public class GraphQLQuery
{

#region OrdersData Resolver
public ReturnType<Order> OrdersData(DataManagerRequest dataManager)
{
IEnumerable<Order> result = Orders;
int count = result.Count();
return dataManager.RequiresCounts ? new ReturnType<Order>() { Result = result, Count = count } : new ReturnType<Order>() { Result = result };
}

public static List<Order> Orders { get; set; } = GetOrdersList();

private static List<Order> GetOrdersList()
{
var data = new List<Order>();
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" } });
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" } });
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" } });
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" } });
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" } });
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" } });
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" } });
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" } });
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" } });
return data;
}
#endregion

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
namespace ASPNetCoreGraphQlServer.Models
{
public class DataManagerRequest
{
[GraphQLName("Skip")]
public int Skip { get; set; }

[GraphQLName("Take")]
public int Take { get; set; }

[GraphQLName("RequiresCounts")]
public bool RequiresCounts { get; set; } = false;

[GraphQLName("Params")]
[GraphQLType(typeof(AnyType))]
public IDictionary<string, object> Params { get; set; }


[GraphQLName("Aggregates")]
[GraphQLType(typeof(AnyType))]
public List<Aggregate>? Aggregates { get; set; }

[GraphQLName("Search")]
public List<SearchFilter>? Search { get; set; }

[GraphQLName("Sorted")]
public List<Sort>? Sorted { get; set; }

[GraphQLName("Where")]
[GraphQLType(typeof(AnyType))]
public List<WhereFilter>? Where { get; set; }

[GraphQLName("Group")]
public List<string>? Group { get; set; }

[GraphQLName("antiForgery")]

public string? antiForgery { get; set; }

[GraphQLName("Table")]
public string? Table { get; set; }

[GraphQLName("IdMapping")]
public string? IdMapping { get; set; }

[GraphQLName("Select")]
public List<string>? Select { get; set; }

[GraphQLName("Expand")]
public List<string>? Expand { get; set; }

[GraphQLName("Distinct")]
public List<string>? Distinct { get; set; }

[GraphQLName("ServerSideGroup")]
public bool? ServerSideGroup { get; set; }

[GraphQLName("LazyLoad")]
public bool? LazyLoad { get; set; }

[GraphQLName("LazyExpandAllGroup")]
public bool? LazyExpandAllGroup { get; set; }
}

public class Aggregate
{
[GraphQLName("Field")]
public string Field { get; set; }

[GraphQLName("Type")]
public string Type { get; set; }
}

public class SearchFilter
{
[GraphQLName("Fields")]
public List<string> Fields { get; set; }

[GraphQLName("Key")]
public string Key { get; set; }

[GraphQLName("Operator")]
public string Operator { get; set; }

[GraphQLName("IgnoreCase")]
public bool IgnoreCase { get; set; }
}

public class Sort
{
[GraphQLName("Name")]
public string Name { get; set; }

[GraphQLName("Direction")]
public string Direction { get; set; }

[GraphQLName("Comparer")]
[GraphQLType(typeof(AnyType))]
public object Comparer { get; set; }
}

public class WhereFilter
{
[GraphQLName("Field")]
public string? Field { get; set; }

[GraphQLName("IgnoreCase")]
public bool? IgnoreCase { get; set; }

[GraphQLName("IgnoreAccent")]
public bool? IgnoreAccent { get; set; }

[GraphQLName("IsComplex")]
public bool? IsComplex { get; set; }

[GraphQLName("Operator")]
public string? Operator { get; set; }

[GraphQLName("Condition")]
public string? Condition { get; set; }

[GraphQLName("value")]
[GraphQLType(typeof(AnyType))]
public object? value { get; set; }

[GraphQLName("predicates")]
public List<WhereFilter>? predicates { get; set; }
}

public class ReturnType<T>
{
public int Count { get; set; }

public IEnumerable<T> Result { get; set; }

[GraphQLType(typeof(AnyType))]
public IDictionary<string, object> Aggregates { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace ASPNetCoreGraphQlServer.Models
{
public class Order
{
[GraphQLName("OrderID")]
public int? OrderID { get; set; }

[GraphQLName("CustomerID")]
public string? CustomerID { get; set; }

[GraphQLName("EmployeeID")]
public string EmployeeID { get; set; }

[GraphQLName("OrderDate")]
public DateTime? OrderDate { get; set; }

[GraphQLName("Freight")]
public double? Freight { get; set; }

[GraphQLName("Address")]
public CustomerAddress? Address { get; set; }
}

public class CustomerAddress
{
[GraphQLName("ShipCity")]
public string ShipCity { get; set; }

[GraphQLName("ShipCountry")]
public string ShipCountry { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using ASPNetCoreGraphQlServer.GraphQl;
using HotChocolate.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddGraphQLServer().AddQueryType<GraphQLQuery>();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigin", builder =>
{
builder.WithOrigins("https://localhost:7021")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials().Build();
});
});


var app = builder.Build();
app.UseCors("AllowSpecificOrigin");
app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapGraphQL());
app.MapGet("/", () => "Hello World!");
app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:33975",
"sslPort": 44358
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5251",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7131;http://localhost:5251",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Loading

0 comments on commit 0965f16

Please sign in to comment.