├── .gitignore
├── .vscode
├── launch.json
└── tasks.json
├── CommanderGQL.csproj
├── Data
└── AppDbContext.cs
├── GraphQL
├── Commands
│ ├── AddCommandInput.cs
│ ├── AddCommandInputType.cs
│ ├── AddCommandPayload.cs
│ ├── AddCommandPayloadType.cs
│ └── CommandType.cs
├── Mutation.cs
├── Platforms
│ ├── AddPlatformInput.cs
│ ├── AddPlatformInputType.cs
│ ├── AddPlatformPayload.cs
│ ├── AddPlatformPayloadType.cs
│ └── PlatformType.cs
├── Query.cs
└── Subscription.cs
├── Migrations
├── 20210120093548_AddPlatformToDb.Designer.cs
├── 20210120093548_AddPlatformToDb.cs
├── 20210123051644_AddCommandToDB.Designer.cs
├── 20210123051644_AddCommandToDB.cs
└── AppDbContextModelSnapshot.cs
├── Models
├── Command.cs
└── Platform.cs
├── Program.cs
├── Properties
└── launchSettings.json
├── Startup.cs
├── appsettings.Development.json
├── appsettings.json
├── catalog-info.yaml
└── docker-compose.yaml
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 | [Ll]ogs/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUnit
47 | *.VisualState.xml
48 | TestResult.xml
49 | nunit-*.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # TeamCity is a build add-in
131 | _TeamCity*
132 |
133 | # DotCover is a Code Coverage Tool
134 | *.dotCover
135 |
136 | # AxoCover is a Code Coverage Tool
137 | .axoCover/*
138 | !.axoCover/settings.json
139 |
140 | # Visual Studio code coverage results
141 | *.coverage
142 | *.coveragexml
143 |
144 | # NCrunch
145 | _NCrunch_*
146 | .*crunch*.local.xml
147 | nCrunchTemp_*
148 |
149 | # MightyMoose
150 | *.mm.*
151 | AutoTest.Net/
152 |
153 | # Web workbench (sass)
154 | .sass-cache/
155 |
156 | # Installshield output folder
157 | [Ee]xpress/
158 |
159 | # DocProject is a documentation generator add-in
160 | DocProject/buildhelp/
161 | DocProject/Help/*.HxT
162 | DocProject/Help/*.HxC
163 | DocProject/Help/*.hhc
164 | DocProject/Help/*.hhk
165 | DocProject/Help/*.hhp
166 | DocProject/Help/Html2
167 | DocProject/Help/html
168 |
169 | # Click-Once directory
170 | publish/
171 |
172 | # Publish Web Output
173 | *.[Pp]ublish.xml
174 | *.azurePubxml
175 | # Note: Comment the next line if you want to checkin your web deploy settings,
176 | # but database connection strings (with potential passwords) will be unencrypted
177 | *.pubxml
178 | *.publishproj
179 |
180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
181 | # checkin your Azure Web App publish settings, but sensitive information contained
182 | # in these scripts will be unencrypted
183 | PublishScripts/
184 |
185 | # NuGet Packages
186 | *.nupkg
187 | # NuGet Symbol Packages
188 | *.snupkg
189 | # The packages folder can be ignored because of Package Restore
190 | **/[Pp]ackages/*
191 | # except build/, which is used as an MSBuild target.
192 | !**/[Pp]ackages/build/
193 | # Uncomment if necessary however generally it will be regenerated when needed
194 | #!**/[Pp]ackages/repositories.config
195 | # NuGet v3's project.json files produces more ignorable files
196 | *.nuget.props
197 | *.nuget.targets
198 |
199 | # Microsoft Azure Build Output
200 | csx/
201 | *.build.csdef
202 |
203 | # Microsoft Azure Emulator
204 | ecf/
205 | rcf/
206 |
207 | # Windows Store app package directories and files
208 | AppPackages/
209 | BundleArtifacts/
210 | Package.StoreAssociation.xml
211 | _pkginfo.txt
212 | *.appx
213 | *.appxbundle
214 | *.appxupload
215 |
216 | # Visual Studio cache files
217 | # files ending in .cache can be ignored
218 | *.[Cc]ache
219 | # but keep track of directories ending in .cache
220 | !?*.[Cc]ache/
221 |
222 | # Others
223 | ClientBin/
224 | ~$*
225 | *~
226 | *.dbmdl
227 | *.dbproj.schemaview
228 | *.jfm
229 | *.pfx
230 | *.publishsettings
231 | orleans.codegen.cs
232 |
233 | # Including strong name files can present a security risk
234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
235 | #*.snk
236 |
237 | # Since there are multiple workflows, uncomment next line to ignore bower_components
238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
239 | #bower_components/
240 |
241 | # RIA/Silverlight projects
242 | Generated_Code/
243 |
244 | # Backup & report files from converting an old project file
245 | # to a newer Visual Studio version. Backup files are not needed,
246 | # because we have git ;-)
247 | _UpgradeReport_Files/
248 | Backup*/
249 | UpgradeLog*.XML
250 | UpgradeLog*.htm
251 | ServiceFabricBackup/
252 | *.rptproj.bak
253 |
254 | # SQL Server files
255 | *.mdf
256 | *.ldf
257 | *.ndf
258 |
259 | # Business Intelligence projects
260 | *.rdl.data
261 | *.bim.layout
262 | *.bim_*.settings
263 | *.rptproj.rsuser
264 | *- [Bb]ackup.rdl
265 | *- [Bb]ackup ([0-9]).rdl
266 | *- [Bb]ackup ([0-9][0-9]).rdl
267 |
268 | # Microsoft Fakes
269 | FakesAssemblies/
270 |
271 | # GhostDoc plugin setting file
272 | *.GhostDoc.xml
273 |
274 | # Node.js Tools for Visual Studio
275 | .ntvs_analysis.dat
276 | node_modules/
277 |
278 | # Visual Studio 6 build log
279 | *.plg
280 |
281 | # Visual Studio 6 workspace options file
282 | *.opt
283 |
284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
285 | *.vbw
286 |
287 | # Visual Studio LightSwitch build output
288 | **/*.HTMLClient/GeneratedArtifacts
289 | **/*.DesktopClient/GeneratedArtifacts
290 | **/*.DesktopClient/ModelManifest.xml
291 | **/*.Server/GeneratedArtifacts
292 | **/*.Server/ModelManifest.xml
293 | _Pvt_Extensions
294 |
295 | # Paket dependency manager
296 | .paket/paket.exe
297 | paket-files/
298 |
299 | # FAKE - F# Make
300 | .fake/
301 |
302 | # CodeRush personal settings
303 | .cr/personal
304 |
305 | # Python Tools for Visual Studio (PTVS)
306 | __pycache__/
307 | *.pyc
308 |
309 | # Cake - Uncomment if you are using it
310 | # tools/**
311 | # !tools/packages.config
312 |
313 | # Tabs Studio
314 | *.tss
315 |
316 | # Telerik's JustMock configuration file
317 | *.jmconfig
318 |
319 | # BizTalk build output
320 | *.btp.cs
321 | *.btm.cs
322 | *.odx.cs
323 | *.xsd.cs
324 |
325 | # OpenCover UI analysis results
326 | OpenCover/
327 |
328 | # Azure Stream Analytics local run output
329 | ASALocalRun/
330 |
331 | # MSBuild Binary and Structured Log
332 | *.binlog
333 |
334 | # NVidia Nsight GPU debugger configuration file
335 | *.nvuser
336 |
337 | # MFractors (Xamarin productivity tool) working folder
338 | .mfractor/
339 |
340 | # Local History for Visual Studio
341 | .localhistory/
342 |
343 | # BeatPulse healthcheck temp database
344 | healthchecksdb
345 |
346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
347 | MigrationBackup/
348 |
349 | # Ionide (cross platform F# VS Code tools) working folder
350 | .ionide/
351 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to find out which attributes exist for C# debugging
3 | // Use hover for the description of the existing attributes
4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": ".NET Core Launch (web)",
9 | "type": "coreclr",
10 | "request": "launch",
11 | "preLaunchTask": "build",
12 | // If you have changed target frameworks, make sure to update the program path.
13 | "program": "${workspaceFolder}/bin/Debug/net5.0/CommanderGQL.dll",
14 | "args": [],
15 | "cwd": "${workspaceFolder}",
16 | "stopAtEntry": false,
17 | // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
18 | "serverReadyAction": {
19 | "action": "openExternally",
20 | "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
21 | },
22 | "env": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | },
25 | "sourceFileMap": {
26 | "/Views": "${workspaceFolder}/Views"
27 | }
28 | },
29 | {
30 | "name": ".NET Core Attach",
31 | "type": "coreclr",
32 | "request": "attach",
33 | "processId": "${command:pickProcess}"
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/CommanderGQL.csproj",
11 | "/property:GenerateFullPaths=true",
12 | "/consoleloggerparameters:NoSummary"
13 | ],
14 | "problemMatcher": "$msCompile"
15 | },
16 | {
17 | "label": "publish",
18 | "command": "dotnet",
19 | "type": "process",
20 | "args": [
21 | "publish",
22 | "${workspaceFolder}/CommanderGQL.csproj",
23 | "/property:GenerateFullPaths=true",
24 | "/consoleloggerparameters:NoSummary"
25 | ],
26 | "problemMatcher": "$msCompile"
27 | },
28 | {
29 | "label": "watch",
30 | "command": "dotnet",
31 | "type": "process",
32 | "args": [
33 | "watch",
34 | "run",
35 | "${workspaceFolder}/CommanderGQL.csproj",
36 | "/property:GenerateFullPaths=true",
37 | "/consoleloggerparameters:NoSummary"
38 | ],
39 | "problemMatcher": "$msCompile"
40 | }
41 | ]
42 | }
--------------------------------------------------------------------------------
/CommanderGQL.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | runtime; build; native; contentfiles; analyzers; buildtransitive
13 | all
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Data/AppDbContext.cs:
--------------------------------------------------------------------------------
1 | using CommanderGQL.Models;
2 | using Microsoft.EntityFrameworkCore;
3 |
4 | namespace CommanderGQL.Data
5 | {
6 | public class AppDbContext : DbContext
7 | {
8 | public AppDbContext(DbContextOptions options) :base(options)
9 | {
10 |
11 | }
12 |
13 | public DbSet Platforms { get; set; }
14 | public DbSet Commands { get; set; }
15 |
16 | protected override void OnModelCreating(ModelBuilder modelBuilder)
17 | {
18 | modelBuilder
19 | .Entity()
20 | .HasMany(p => p.Commands)
21 | .WithOne(p => p.Platform!)
22 | .HasForeignKey(p => p.PlatformId);
23 |
24 | modelBuilder
25 | .Entity()
26 | .HasOne(p => p.Platform)
27 | .WithMany(p => p.Commands)
28 | .HasForeignKey(p => p.PlatformId);
29 | }
30 |
31 |
32 | }
33 | }
--------------------------------------------------------------------------------
/GraphQL/Commands/AddCommandInput.cs:
--------------------------------------------------------------------------------
1 | namespace CommanderGQL.GraphQL.Commands
2 | {
3 | public record AddCommandInput(string HowTo, string CommandLine, int PlatformId);
4 | }
--------------------------------------------------------------------------------
/GraphQL/Commands/AddCommandInputType.cs:
--------------------------------------------------------------------------------
1 | using HotChocolate.Types;
2 |
3 | namespace CommanderGQL.GraphQL.Commands
4 | {
5 | public class AddCommandInputType : InputObjectType
6 | {
7 | protected override void Configure(IInputObjectTypeDescriptor descriptor)
8 | {
9 | descriptor.Description("Represents the input to add for a command.");
10 |
11 | descriptor
12 | .Field(c => c.HowTo)
13 | .Description("Represents the how-to for the command.");
14 | descriptor
15 | .Field(c => c.CommandLine)
16 | .Description("Represents the command line.");
17 | descriptor
18 | .Field(c => c.PlatformId)
19 | .Description("Represents the unique ID of the platform which the command belongs.");
20 |
21 | base.Configure(descriptor);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/GraphQL/Commands/AddCommandPayload.cs:
--------------------------------------------------------------------------------
1 | using CommanderGQL.Models;
2 |
3 | namespace CommanderGQL.GraphQL.Commands
4 | {
5 | public record AddCommandPayload(Command command);
6 | }
--------------------------------------------------------------------------------
/GraphQL/Commands/AddCommandPayloadType.cs:
--------------------------------------------------------------------------------
1 | using HotChocolate.Types;
2 |
3 | namespace CommanderGQL.GraphQL.Commands
4 | {
5 | public class AddCommandPayloadType : ObjectType
6 | {
7 | protected override void Configure(IObjectTypeDescriptor descriptor)
8 | {
9 | descriptor.Description("Represents the payload to return for an added command.");
10 |
11 | descriptor
12 | .Field(c => c.command)
13 | .Description("Represents the added command.");
14 |
15 | base.Configure(descriptor);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/GraphQL/Commands/CommandType.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using CommanderGQL.Data;
3 | using CommanderGQL.Models;
4 | using HotChocolate;
5 | using HotChocolate.Types;
6 |
7 | namespace CommanderGQL.GraphQL.Commands
8 | {
9 | public class CommandType : ObjectType
10 | {
11 | protected override void Configure(IObjectTypeDescriptor descriptor)
12 | {
13 | descriptor.Description("Represents any executable command.");
14 |
15 | descriptor
16 | .Field(c => c.Id)
17 | .Description("Represents the unique ID for the command.");
18 |
19 | descriptor
20 | .Field(c => c.HowTo)
21 | .Description("Represents the how-to for the command.");
22 |
23 | descriptor
24 | .Field(c => c.CommandLine)
25 | .Description("Represents the command line.");
26 |
27 | descriptor
28 | .Field(c => c.PlatformId)
29 | .Description("Represents the unique ID of the platform which the command belongs.");
30 |
31 | descriptor
32 | .Field(c => c.Platform)
33 | .ResolveWith(c => c.GetPlatform(default!, default!))
34 | .UseDbContext()
35 | .Description("This is the platform to which the command belongs.");
36 |
37 | }
38 |
39 | private class Resolvers
40 | {
41 | public Platform GetPlatform(Command command, [ScopedService] AppDbContext context)
42 | {
43 | return context.Platforms.FirstOrDefault(p => p.Id == command.PlatformId);
44 | }
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/GraphQL/Mutation.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using CommanderGQL.Data;
4 | using CommanderGQL.GraphQL.Commands;
5 | using CommanderGQL.GraphQL.Platforms;
6 | using CommanderGQL.Models;
7 | using HotChocolate;
8 | using HotChocolate.Data;
9 | using HotChocolate.Subscriptions;
10 |
11 | namespace CommanderGQL.GraphQL
12 | {
13 | ///
14 | /// Represents the mutations available.
15 | ///
16 | [GraphQLDescription("Represents the mutations available.")]
17 | public class Mutation
18 | {
19 | ///
20 | /// Adds a based on .
21 | ///
22 | /// The .
23 | /// The .
24 | /// The .
25 | /// The .
26 | /// The added .
27 | [UseDbContext(typeof(AppDbContext))]
28 | [GraphQLDescription("Adds a platform.")]
29 | public async Task AddPlatformAsync(
30 | AddPlatformInput input,
31 | [ScopedService] AppDbContext context,
32 | [Service] ITopicEventSender eventSender,
33 | CancellationToken cancellationToken
34 | )
35 | {
36 | var platform = new Platform{
37 | Name = input.Name
38 | };
39 |
40 | context.Platforms.Add(platform);
41 | await context.SaveChangesAsync(cancellationToken);
42 |
43 | await eventSender.SendAsync(nameof(Subscription.OnPlatformAdded), platform, cancellationToken);
44 |
45 | return new AddPlatformPayload(platform);
46 | }
47 |
48 | ///
49 | /// Adds a based on .
50 | ///
51 | /// The .
52 | /// The .
53 | /// The added .
54 | [UseDbContext(typeof(AppDbContext))]
55 | [GraphQLDescription("Adds a command.")]
56 | public async Task AddCommandAsync(AddCommandInput input,
57 | [ScopedService] AppDbContext context)
58 | {
59 | var command = new Command{
60 | HowTo = input.HowTo,
61 | CommandLine = input.CommandLine,
62 | PlatformId = input.PlatformId
63 | };
64 |
65 | context.Commands.Add(command);
66 | await context.SaveChangesAsync();
67 |
68 | return new AddCommandPayload(command);
69 | }
70 | }
71 | }
--------------------------------------------------------------------------------
/GraphQL/Platforms/AddPlatformInput.cs:
--------------------------------------------------------------------------------
1 | namespace CommanderGQL.GraphQL.Platforms
2 | {
3 | public record AddPlatformInput(string Name);
4 | }
--------------------------------------------------------------------------------
/GraphQL/Platforms/AddPlatformInputType.cs:
--------------------------------------------------------------------------------
1 | using HotChocolate.Types;
2 |
3 | namespace CommanderGQL.GraphQL.Platforms
4 | {
5 | public class AddPlatformInputType : InputObjectType
6 | {
7 | protected override void Configure(IInputObjectTypeDescriptor descriptor)
8 | {
9 | descriptor.Description("Represents the input to add for a platform.");
10 |
11 | descriptor
12 | .Field(p => p.Name)
13 | .Description("Represents the name for the platform.");
14 |
15 | base.Configure(descriptor);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/GraphQL/Platforms/AddPlatformPayload.cs:
--------------------------------------------------------------------------------
1 | using CommanderGQL.Models;
2 |
3 | namespace CommanderGQL.GraphQL.Platforms
4 | {
5 | public record AddPlatformPayload(Platform platform);
6 | }
--------------------------------------------------------------------------------
/GraphQL/Platforms/AddPlatformPayloadType.cs:
--------------------------------------------------------------------------------
1 | using HotChocolate.Types;
2 |
3 | namespace CommanderGQL.GraphQL.Platforms
4 | {
5 | public class AddPlatformPayloadType : ObjectType
6 | {
7 | protected override void Configure(IObjectTypeDescriptor descriptor)
8 | {
9 | descriptor.Description("Represents the payload to return for an added platform.");
10 |
11 | descriptor
12 | .Field(p => p.platform)
13 | .Description("Represents the added platform.");
14 |
15 | base.Configure(descriptor);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/GraphQL/Platforms/PlatformType.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using CommanderGQL.Data;
3 | using CommanderGQL.Models;
4 | using HotChocolate;
5 | using HotChocolate.Types;
6 |
7 | namespace CommanderGQL.GraphQL.Platforms
8 | {
9 | public class PlatformType : ObjectType
10 | {
11 | protected override void Configure(IObjectTypeDescriptor descriptor)
12 | {
13 | descriptor.Description("Represents any software or service that has a command line interface.");
14 |
15 | descriptor
16 | .Field(p => p.Id)
17 | .Description("Represents the unique ID for the platform.");
18 |
19 | descriptor
20 | .Field(p => p.Name)
21 | .Description("Represents the name for the platform.");
22 |
23 | descriptor
24 | .Field(p => p.LicenseKey).Ignore();
25 |
26 | descriptor
27 | .Field(p => p.Commands)
28 | .ResolveWith(p => p.GetCommands(default!, default!))
29 | .UseDbContext()
30 | .Description("This is the list of available commands for this platform.");
31 | }
32 |
33 | private class Resolvers
34 | {
35 | public IQueryable GetCommands(Platform platform, [ScopedService] AppDbContext context)
36 | {
37 | return context.Commands.Where(p => p.PlatformId == platform.Id);
38 | }
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/GraphQL/Query.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using CommanderGQL.Data;
3 | using CommanderGQL.Models;
4 | using HotChocolate;
5 | using HotChocolate.Data;
6 |
7 | namespace CommanderGQL.GraphQL
8 | {
9 | ///
10 | /// Represents the queries available.
11 | ///
12 | [GraphQLDescription("Represents the queries available.")]
13 | public class Query
14 | {
15 | ///
16 | /// Gets the queryable .
17 | ///
18 | /// The .
19 | /// The queryable .
20 | [UseDbContext(typeof(AppDbContext))]
21 | [UseFiltering]
22 | [UseSorting]
23 | [GraphQLDescription("Gets the queryable platform.")]
24 | public IQueryable GetPlatform([ScopedService] AppDbContext context)
25 | {
26 | return context.Platforms;
27 | }
28 |
29 | ///
30 | /// Gets the queryable .
31 | ///
32 | /// The .
33 | /// The queryable .
34 | [UseDbContext(typeof(AppDbContext))]
35 | [UseFiltering]
36 | [UseSorting]
37 | [GraphQLDescription("Gets the queryable command.")]
38 | public IQueryable GetCommand([ScopedService] AppDbContext context)
39 | {
40 | return context.Commands;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/GraphQL/Subscription.cs:
--------------------------------------------------------------------------------
1 | using CommanderGQL.Models;
2 | using HotChocolate;
3 | using HotChocolate.Types;
4 |
5 | namespace CommanderGQL.GraphQL
6 | {
7 | ///
8 | /// Represents the subscriptions available.
9 | ///
10 | [GraphQLDescription("Represents the queries available.")]
11 | public class Subscription
12 | {
13 | ///
14 | /// The subscription for added .
15 | ///
16 | /// The .
17 | /// The added .
18 | [Subscribe]
19 | [Topic]
20 | [GraphQLDescription("The subscription for added platform.")]
21 | public Platform OnPlatformAdded([EventMessage] Platform platform)
22 | {
23 | return platform;
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/Migrations/20210120093548_AddPlatformToDb.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using CommanderGQL.Data;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Metadata;
6 | using Microsoft.EntityFrameworkCore.Migrations;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | namespace CommanderGQL.Migrations
10 | {
11 | [DbContext(typeof(AppDbContext))]
12 | [Migration("20210120093548_AddPlatformToDb")]
13 | partial class AddPlatformToDb
14 | {
15 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
16 | {
17 | #pragma warning disable 612, 618
18 | modelBuilder
19 | .UseIdentityColumns()
20 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
21 | .HasAnnotation("ProductVersion", "5.0.2");
22 |
23 | modelBuilder.Entity("CommanderGQL.Models.Platform", b =>
24 | {
25 | b.Property("Id")
26 | .ValueGeneratedOnAdd()
27 | .HasColumnType("int")
28 | .UseIdentityColumn();
29 |
30 | b.Property("LicenseKey")
31 | .HasColumnType("nvarchar(max)");
32 |
33 | b.Property("Name")
34 | .IsRequired()
35 | .HasColumnType("nvarchar(max)");
36 |
37 | b.HasKey("Id");
38 |
39 | b.ToTable("Platforms");
40 | });
41 | #pragma warning restore 612, 618
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Migrations/20210120093548_AddPlatformToDb.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Migrations;
2 |
3 | namespace CommanderGQL.Migrations
4 | {
5 | public partial class AddPlatformToDb : Migration
6 | {
7 | protected override void Up(MigrationBuilder migrationBuilder)
8 | {
9 | migrationBuilder.CreateTable(
10 | name: "Platforms",
11 | columns: table => new
12 | {
13 | Id = table.Column(type: "int", nullable: false)
14 | .Annotation("SqlServer:Identity", "1, 1"),
15 | Name = table.Column(type: "nvarchar(max)", nullable: false),
16 | LicenseKey = table.Column(type: "nvarchar(max)", nullable: true)
17 | },
18 | constraints: table =>
19 | {
20 | table.PrimaryKey("PK_Platforms", x => x.Id);
21 | });
22 | }
23 |
24 | protected override void Down(MigrationBuilder migrationBuilder)
25 | {
26 | migrationBuilder.DropTable(
27 | name: "Platforms");
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Migrations/20210123051644_AddCommandToDB.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using CommanderGQL.Data;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Metadata;
6 | using Microsoft.EntityFrameworkCore.Migrations;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | namespace CommanderGQL.Migrations
10 | {
11 | [DbContext(typeof(AppDbContext))]
12 | [Migration("20210123051644_AddCommandToDB")]
13 | partial class AddCommandToDB
14 | {
15 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
16 | {
17 | #pragma warning disable 612, 618
18 | modelBuilder
19 | .UseIdentityColumns()
20 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
21 | .HasAnnotation("ProductVersion", "5.0.2");
22 |
23 | modelBuilder.Entity("CommanderGQL.Models.Command", b =>
24 | {
25 | b.Property("Id")
26 | .ValueGeneratedOnAdd()
27 | .HasColumnType("int")
28 | .UseIdentityColumn();
29 |
30 | b.Property("CommandLine")
31 | .IsRequired()
32 | .HasColumnType("nvarchar(max)");
33 |
34 | b.Property("HowTo")
35 | .IsRequired()
36 | .HasColumnType("nvarchar(max)");
37 |
38 | b.Property("PlatformId")
39 | .HasColumnType("int");
40 |
41 | b.HasKey("Id");
42 |
43 | b.HasIndex("PlatformId");
44 |
45 | b.ToTable("Commands");
46 | });
47 |
48 | modelBuilder.Entity("CommanderGQL.Models.Platform", b =>
49 | {
50 | b.Property("Id")
51 | .ValueGeneratedOnAdd()
52 | .HasColumnType("int")
53 | .UseIdentityColumn();
54 |
55 | b.Property("LicenseKey")
56 | .HasColumnType("nvarchar(max)");
57 |
58 | b.Property("Name")
59 | .IsRequired()
60 | .HasColumnType("nvarchar(max)");
61 |
62 | b.HasKey("Id");
63 |
64 | b.ToTable("Platforms");
65 | });
66 |
67 | modelBuilder.Entity("CommanderGQL.Models.Command", b =>
68 | {
69 | b.HasOne("CommanderGQL.Models.Platform", "Platform")
70 | .WithMany("Commands")
71 | .HasForeignKey("PlatformId")
72 | .OnDelete(DeleteBehavior.Cascade)
73 | .IsRequired();
74 |
75 | b.Navigation("Platform");
76 | });
77 |
78 | modelBuilder.Entity("CommanderGQL.Models.Platform", b =>
79 | {
80 | b.Navigation("Commands");
81 | });
82 | #pragma warning restore 612, 618
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/Migrations/20210123051644_AddCommandToDB.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Migrations;
2 |
3 | namespace CommanderGQL.Migrations
4 | {
5 | public partial class AddCommandToDB : Migration
6 | {
7 | protected override void Up(MigrationBuilder migrationBuilder)
8 | {
9 | migrationBuilder.CreateTable(
10 | name: "Commands",
11 | columns: table => new
12 | {
13 | Id = table.Column(type: "int", nullable: false)
14 | .Annotation("SqlServer:Identity", "1, 1"),
15 | HowTo = table.Column(type: "nvarchar(max)", nullable: false),
16 | CommandLine = table.Column(type: "nvarchar(max)", nullable: false),
17 | PlatformId = table.Column(type: "int", nullable: false)
18 | },
19 | constraints: table =>
20 | {
21 | table.PrimaryKey("PK_Commands", x => x.Id);
22 | table.ForeignKey(
23 | name: "FK_Commands_Platforms_PlatformId",
24 | column: x => x.PlatformId,
25 | principalTable: "Platforms",
26 | principalColumn: "Id",
27 | onDelete: ReferentialAction.Cascade);
28 | });
29 |
30 | migrationBuilder.CreateIndex(
31 | name: "IX_Commands_PlatformId",
32 | table: "Commands",
33 | column: "PlatformId");
34 | }
35 |
36 | protected override void Down(MigrationBuilder migrationBuilder)
37 | {
38 | migrationBuilder.DropTable(
39 | name: "Commands");
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Migrations/AppDbContextModelSnapshot.cs:
--------------------------------------------------------------------------------
1 | //
2 | using CommanderGQL.Data;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Metadata;
6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7 |
8 | namespace CommanderGQL.Migrations
9 | {
10 | [DbContext(typeof(AppDbContext))]
11 | partial class AppDbContextModelSnapshot : ModelSnapshot
12 | {
13 | protected override void BuildModel(ModelBuilder modelBuilder)
14 | {
15 | #pragma warning disable 612, 618
16 | modelBuilder
17 | .UseIdentityColumns()
18 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
19 | .HasAnnotation("ProductVersion", "5.0.2");
20 |
21 | modelBuilder.Entity("CommanderGQL.Models.Command", b =>
22 | {
23 | b.Property("Id")
24 | .ValueGeneratedOnAdd()
25 | .HasColumnType("int")
26 | .UseIdentityColumn();
27 |
28 | b.Property("CommandLine")
29 | .IsRequired()
30 | .HasColumnType("nvarchar(max)");
31 |
32 | b.Property("HowTo")
33 | .IsRequired()
34 | .HasColumnType("nvarchar(max)");
35 |
36 | b.Property("PlatformId")
37 | .HasColumnType("int");
38 |
39 | b.HasKey("Id");
40 |
41 | b.HasIndex("PlatformId");
42 |
43 | b.ToTable("Commands");
44 | });
45 |
46 | modelBuilder.Entity("CommanderGQL.Models.Platform", b =>
47 | {
48 | b.Property("Id")
49 | .ValueGeneratedOnAdd()
50 | .HasColumnType("int")
51 | .UseIdentityColumn();
52 |
53 | b.Property("LicenseKey")
54 | .HasColumnType("nvarchar(max)");
55 |
56 | b.Property("Name")
57 | .IsRequired()
58 | .HasColumnType("nvarchar(max)");
59 |
60 | b.HasKey("Id");
61 |
62 | b.ToTable("Platforms");
63 | });
64 |
65 | modelBuilder.Entity("CommanderGQL.Models.Command", b =>
66 | {
67 | b.HasOne("CommanderGQL.Models.Platform", "Platform")
68 | .WithMany("Commands")
69 | .HasForeignKey("PlatformId")
70 | .OnDelete(DeleteBehavior.Cascade)
71 | .IsRequired();
72 |
73 | b.Navigation("Platform");
74 | });
75 |
76 | modelBuilder.Entity("CommanderGQL.Models.Platform", b =>
77 | {
78 | b.Navigation("Commands");
79 | });
80 | #pragma warning restore 612, 618
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/Models/Command.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations;
2 |
3 | namespace CommanderGQL.Models
4 | {
5 | ///
6 | /// Represents any executable command.
7 | ///
8 | public class Command
9 | {
10 | ///
11 | /// Represents the unique ID for the command.
12 | ///
13 | [Key]
14 | public int Id { get; set; }
15 |
16 | ///
17 | /// Represents the how-to for the command.
18 | ///
19 | [Required]
20 | public string HowTo { get; set; }
21 |
22 | ///
23 | /// Represents the command line.
24 | ///
25 | [Required]
26 | public string CommandLine { get; set; }
27 |
28 | ///
29 | /// Represents the unique ID of the platform which the command belongs.
30 | ///
31 | [Required]
32 | public int PlatformId { get; set; }
33 |
34 | ///
35 | /// This is the platform to which the command belongs.
36 | ///
37 | public Platform Platform { get; set; }
38 | }
39 | }
--------------------------------------------------------------------------------
/Models/Platform.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.ComponentModel.DataAnnotations;
3 |
4 | namespace CommanderGQL.Models
5 | {
6 | ///
7 | /// Represents any software or service that has a command line interface.
8 | ///
9 | public class Platform
10 | {
11 | ///
12 | /// Represents the unique ID for the platform.
13 | ///
14 | [Key]
15 | public int Id { get; set; }
16 |
17 | ///
18 | /// Represents the name for the platform.
19 | ///
20 | [Required]
21 | public string Name { get; set; }
22 |
23 | ///
24 | /// Represents a purchased, valid license for the platform.
25 | ///
26 | public string LicenseKey { get; set; }
27 |
28 | ///
29 | /// This is the list of available commands for this platform.
30 | ///
31 | public ICollection Commands { get; set; } = new List();
32 |
33 | }
34 | }
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.Extensions.Configuration;
7 | using Microsoft.Extensions.Hosting;
8 | using Microsoft.Extensions.Logging;
9 |
10 | namespace CommanderGQL
11 | {
12 | public class Program
13 | {
14 | public static void Main(string[] args)
15 | {
16 | CreateHostBuilder(args).Build().Run();
17 | }
18 |
19 | public static IHostBuilder CreateHostBuilder(string[] args) =>
20 | Host.CreateDefaultBuilder(args)
21 | .ConfigureWebHostDefaults(webBuilder =>
22 | {
23 | webBuilder.UseStartup();
24 | });
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:50760",
7 | "sslPort": 44379
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "CommanderGQL": {
19 | "commandName": "Project",
20 | "dotnetRunMessages": "true",
21 | "launchBrowser": true,
22 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
23 | "environmentVariables": {
24 | "ASPNETCORE_ENVIRONMENT": "Development"
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using CommanderGQL.Data;
6 | using CommanderGQL.GraphQL;
7 | using CommanderGQL.GraphQL.Commands;
8 | using CommanderGQL.GraphQL.Platforms;
9 | using GraphQL.Server.Ui.Voyager;
10 | using Microsoft.AspNetCore.Builder;
11 | using Microsoft.AspNetCore.Hosting;
12 | using Microsoft.AspNetCore.Http;
13 | using Microsoft.EntityFrameworkCore;
14 | using Microsoft.Extensions.Configuration;
15 | using Microsoft.Extensions.DependencyInjection;
16 | using Microsoft.Extensions.Hosting;
17 |
18 | namespace CommanderGQL
19 | {
20 | public class Startup
21 | {
22 | private readonly IConfiguration Configuration;
23 |
24 | public Startup(IConfiguration configuration)
25 | {
26 | Configuration = configuration;
27 | }
28 |
29 | public void ConfigureServices(IServiceCollection services)
30 | {
31 | services.AddPooledDbContextFactory(opt => opt.UseSqlServer
32 | (Configuration.GetConnectionString("CommandConStr")));
33 |
34 | services
35 | .AddGraphQLServer()
36 | .AddQueryType()
37 | .AddMutationType()
38 | .AddSubscriptionType()
39 | .AddType()
40 | .AddType()
41 | .AddType()
42 | .AddType()
43 | .AddType()
44 | .AddType()
45 | .AddFiltering()
46 | .AddSorting()
47 | .AddInMemorySubscriptions();
48 |
49 | }
50 |
51 |
52 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
53 | {
54 | if (env.IsDevelopment())
55 | {
56 | app.UseDeveloperExceptionPage();
57 | }
58 |
59 | app.UseWebSockets();
60 |
61 | app.UseRouting();
62 |
63 | app.UseEndpoints(endpoints =>
64 | {
65 | endpoints.MapGraphQL();
66 | });
67 |
68 | app.UseGraphQLVoyager(new GraphQLVoyagerOptions()
69 | {
70 | GraphQLEndPoint = "/graphql",
71 | Path = "/graphql-voyager"
72 | });
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "ConnectionStrings": {
10 | "CommandConStr" : "Server=localhost,1433;Database=CommandsDB;User Id=sa;Password=pa55w0rd!"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/catalog-info.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: backstage.io/v1alpha1
2 | kind: Component
3 | metadata:
4 | name: .NET 5 GraphQL API
5 | annotations:
6 | github.com/project-slug: binarythistle/S04E01---.NET-5-GraphQL-API
7 | spec:
8 | type: other
9 | lifecycle: unknown
10 | owner: binarythistle
11 |
--------------------------------------------------------------------------------
/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 | sqlserver:
4 | image: "mcr.microsoft.com/mssql/server:2017-latest"
5 | environment:
6 | ACCEPT_EULA: "Y"
7 | SA_PASSWORD: "pa55w0rd!"
8 | MSSQL_PID: "Express"
9 | ports:
10 | - "1433:1433"
--------------------------------------------------------------------------------