Git Product home page Git Product logo

graphql-albums-api's Introduction

GraphQL-Albums-API

Albums GraphQL API with GraphQL and HotChocolate

Entities

public class Artist
{
    [Key]
    public int Id { get; set; }
    [Required]
    public string Name { get; set; }
    public string Country { get; set; }
    public ICollection<Album> Albums { get; set; }
}
public class Album
{
    [Key]
    public int Id { get; set; }
    [Required]
    public string Title { get; set; }
    [Required]
    public string Genre { get; set; }
    [Required]
    public int ArtistId { get; set; }
    public Artist Artist { get; set; }
}

Sample query request

query{
  artist{
    id
    name
    country
    albums{
      id
      title
      
    }
  }
}

Response

{
  "data": {
    "artist": [
      {
        "id": 1,
        "name": "The Doors",
        "country": "USA",
        "albums": [
          {
            "id": 1,
            "title": "LA Woman"
          },
          {
            "id": 2,
            "title": "Strange Days"
          }
        ]
      },
      {
        "id": 2,
        "name": "Country Joe and the Fish",
        "country": "USA",
        "albums": [
          {
            "id": 3,
            "title": "Here We Are Again"
          },
          {
            "id": 4,
            "title": "Together"
          }
        ]
      },
      {
        "id": 3,
        "name": "Janis Joplin",
        "country": "USA",
        "albums": [
          {
            "id": 5,
            "title": "Pearl"
          }
        ]
      },
      {
        "id": 4,
        "name": "Pink Floyd",
        "country": "UK",
        "albums": [
          {
            "id": 6,
            "title": "The Dark Side of the Moon"
          },
          {
            "id": 7,
            "title": "The Division Bell"
          }
        ]
      }
    ]
  }
}

sample mutation request

mutation {
    addAlbum (
        input: {
            artistId : 1
            genre : "Rock"
            title : "The Soft Parade"
        }
    )
    {
        album {
          id
          genre  
          title
        }
        
    }
}

Response

{
  "data": {
    "addAlbum": {
      "album": {
        "id": 3,
        "genre": "Rock",
        "title": "The Soft Parade"
      }
    }
  }
}

How to run :

1. start SQL server

docker compose up -d 

2. Update database

dotnet ef database update

3. restore n run

dotnet restore && dotnet run

License

Licence

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.