Cheatsheet​

The types used in these queries are defined here.

In order to set up GraphQL access to the database add the following to the schema:

  1. using extension graphql;

Then create a new migration and apply it using edgedb migration create and edgedb migrate, respectively.

Select all users in the system:

  1. {
  2. User {
  3. id
  4. name
  5. image
  6. }
  7. }

Select a movie by title and release year with associated actors ordered by last name:

  1. {
  2. Movie(
  3. filter: {
  4. title: {eq: "Dune"},
  5. year: {eq: 2020}
  6. }
  7. ) {
  8. id
  9. title
  10. year
  11. description
  12. directors {
  13. id
  14. full_name
  15. }
  16. actors(order: {last_name: {dir: ASC}}) {
  17. id
  18. full_name
  19. }
  20. }
  21. }

Select movies with Keanu Reeves:

  1. {
  2. Movie(
  3. filter: {
  4. actors: {full_name: {eq: "Keanu Reeves"}}
  5. }
  6. ) {
  7. id
  8. title
  9. year
  10. description
  11. }
  12. }

Select a movie by title and year with top 3 most recent reviews (this uses MovieAlias in order to access reviews):

  1. {
  2. MovieAlias(
  3. filter: {
  4. title: {eq: "Dune"},
  5. year: {eq: 2020}
  6. }
  7. ) {
  8. id
  9. title
  10. year
  11. description
  12. reviews(
  13. order: {creation_time: {dir: DESC}},
  14. first: 3
  15. ) {
  16. id
  17. body
  18. rating
  19. creation_time
  20. author {
  21. id
  22. name
  23. }
  24. }
  25. }
  26. }

Use MovieAlias in order to find movies that have no reviews:

  1. {
  2. MovieAlias(
  3. filter: {
  4. reviews: {exists: false},
  5. }
  6. ) {
  7. id
  8. title
  9. year
  10. description
  11. }
  12. }

Use a GraphQL mutation to add a user:

  1. mutation add_user {
  2. insert_User(
  3. data: {name: "Atreides", image: "atreides.jpg"}
  4. ) {
  5. id
  6. }
  7. }

Use a GraphQL mutation to add a review by an existing user:

  1. mutation add_review {
  2. insert_Review(
  3. data: {
  4. # Since the movie already exists,
  5. # we select it using the same filter
  6. # mechanism as for queries.
  7. movie: {
  8. filter: {title: {eq: "Dune"}, year: {eq: 2020}},
  9. first: 1
  10. },
  11. body: "Yay!",
  12. rating: 5,
  13. # Similarly to the movie we select
  14. # the existing user.
  15. author: {
  16. filter: {name: {eq: "Atreides"}},
  17. first: 1
  18. }
  19. }
  20. ) {
  21. id
  22. body
  23. }
  24. }

Use a GraphQL mutation to add an actress to a movie:

  1. mutation add_actor {
  2. update_Movie(
  3. # Specify which movie needs to be updated.
  4. filter: {title: {eq: "Dune"}, year: {eq: 2020}},
  5. # Specify the movie data to be updated.
  6. data: {
  7. actors: {
  8. add: [{
  9. filter: {
  10. full_name: {eq: "Charlotte Rampling"}
  11. }
  12. }]
  13. }
  14. }
  15. ) {
  16. id
  17. actors {
  18. id
  19. }
  20. }
  21. }