Get started
By the end of this page you’ll have your own solution, a GraphQL API running on your machine, and a page of movies on your screen. It takes about five minutes, or ten if NuGet decides to download the internet first.
Before you start
Section titled “Before you start”You need the .NET 10 SDK. Docker is optional, but it gets you Seq for the logs and a container you can ship, so it’s worth having around.
Make it yours
Section titled “Make it yours”-
Install the template from NuGet.
Terminal window dotnet new install CleanGraphQLApi.Template -
Create a solution. The name becomes your namespace, project names and folder, so pick something you’re happy to see a lot of.
Terminal window dotnet new cleangraphqlapi --name Acme.Movies --authorName "Your Name"cd Acme.Movies -
Have a look around. Everything you need is already here.
- Acme.Movies.sln
- Dockerfile
- docker-compose.yml
Directorysrc/
DirectoryApplication/ the rules, queries and validation
- …
DirectoryInfrastructure/ the database and repositories
- …
DirectoryPresentation/ the GraphQL schema
- …
Directorytests/
DirectoryApplication.Tests.Unit/
- …
DirectoryInfrastructure.Tests.Integration/
- …
DirectoryPresentation.Tests.Integration/
- …
-
Run it. The
localenvironment seeds sample data and logs to the console, so there’s nothing to set up.Terminal window dotnet run --project ./src/Presentation -
Open Nitro, the GraphQL IDE, at http://localhost:5032/graphql. The schema is on the left, with every type and field described, and the editor autocompletes as you type. Paste this in and press play:
{movies(query: "global", first: 2) {totalCountpageInfo { hasNextPage endCursor }nodes { id title reviewCount averageStars }}} -
Or ask from the terminal.
Terminal window curl -X POST "http://localhost:5032/graphql" -H "Content-Type: application/json" \-d '{"query":"{ movies(query: \"global\", first: 2) { totalCount nodes { id title reviewCount averageStars } } }"}'Either way you get a page of movies back:
{"data": {"movies": {"totalCount": 2,"pageInfo": { "hasNextPage": false, "endCursor": "b2Zmc2V0OjI=" },"nodes": [{ "id": "30fca414-247a-779e-105a-d81aa2506f58", "title": "Assimilated global infrastructure", "reviewCount": 1, "averageStars": 1 },{ "id": "c27d6600-79a6-9346-2595-a52b7f07dc3e", "title": "Automated global alliance", "reviewCount": 3, "averageStars": 3.3 }]}}}Yes, the movies are named by a corporate buzzword generator. Assimilated global infrastructure only got one star. Critics can be harsh.
-
Run the tests while you’re here.
Terminal window dotnet test