An sample repository to showcase usage of GraphQL in ASP.NET CORE WEB API
In order to run the project follow the below mentioned steps
- Set Telemetry.DAL as startup project in visual studio.
- Go to file TemporaryDbContextFactory and replace the connection string as per your SQL server.
2.1 optionsBuilder.UseSqlServer("<<YOUR_SQL_SERVER>>"); - Navigate in command prompt to the Telemetry.DAl folder and Run "dotnet ef database update".
- This should have created the Database and added the required tables in SQL Server.
- Now set Telemetry.API as startup project.
- Right click Telemetru.API and navigate to Manager user secrets and replace the ConnectionStrings:TeleMetry to the same connection string given in step 2.
- Download and run Serilog-SEQ from https://getseq.net/Download
- press ctrl-F5.
- Browser must open the page http://localhost:49771/GraphQL/
- To get a specific device with a given device id
query TelemetryQuery($id:Int!)
{
deviceQuery {
deviceById(id:$id)
{
deviceName
}
}
}
Under query variables
{
"id" : 152
}
- To get all devices
query TelemetryQuery
{
deviceQuery {
allDevices {
deviceId,
deviceName
}
}
}
- To add a device
mutation ($CreateDeviceType:InputCreateDevice!)
{
deviceMutation{
addDevice(CreateDeviceType: $CreateDeviceType){
deviceId
deviceName
}
}
}
Under query variables
{
"CreateDeviceType":{
"deviceName": "TestDevice",
"description": "TestDescription"
}
}