Skip to content

Latest commit

 

History

History
88 lines (85 loc) · 1.43 KB

Readme.md

File metadata and controls

88 lines (85 loc) · 1.43 KB

ART

A simple GraphQL server for managing artists and artworks. An artist has a name and a set of artworks, each artwork has a title. Artwork can only belong to a single artist.

Not invented here

This repo was inspired by the great Kat Zien speech (GopherCon 2018).

GraphQl mutations are based on the Anemic Mutations, allowing users to update any field independently without optional fields

Examples:

Adding:

mutation {
  addArtwork(title: "44", artistID: 1) {
    id
    title
    artist {
      name
    }
  }
}
mutation {
  addArtist(name: "6655") {
    name
  }
}

Updating:

mutation {
  updateArtist(id: 1, actions: { setName: { name: "newname" } }) {
    name
  }
}
mutation {
  updateArtwork(
    id: 1
    actions: { setTitle: { title: "newtitle" }, setArtist: { artistID: 5 } }
  ) {
    id
    title
    artist {
      name
      id
    }
  }
}

Deleting:

mutation {
  deleteArtwork(id: 1)
}
mutation {
  deleteArtist(id: 2)
}

Querying:

To query all artists:

query {
  filterArtists(name: "") {
    name
    id
  }
}

To filter artists:

query {
  filterArtists(name: "partOfTheName") {
    name
    id
  }
}

Artist's artworks

query {
  artist(id: 1) {
    artworks {
      title
      id
    }
  }
}