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:
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:
{User {idnameimage}}
Select a movie by title and release year with associated actors ordered by last name:
{Movie(filter: {title: {eq: "Dune"},year: {eq: 2020}}) {idtitleyeardescriptiondirectors {idfull_name}actors(order: {last_name: {dir: ASC}}) {idfull_name}}}
Select movies with Keanu Reeves:
{Movie(filter: {actors: {full_name: {eq: "Keanu Reeves"}}}) {idtitleyeardescription}}
Select a movie by title and year with top 3 most recent reviews (this uses MovieAlias in order to access reviews):
{MovieAlias(filter: {title: {eq: "Dune"},year: {eq: 2020}}) {idtitleyeardescriptionreviews(order: {creation_time: {dir: DESC}},first: 3) {idbodyratingcreation_timeauthor {idname}}}}
Use MovieAlias in order to find movies that have no reviews:
{MovieAlias(filter: {reviews: {exists: false},}) {idtitleyeardescription}}
Use a GraphQL mutation to add a user:
mutation add_user {insert_User(data: {name: "Atreides", image: "atreides.jpg"}) {id}}
Use a GraphQL mutation to add a review by an existing user:
mutation add_review {insert_Review(data: {# Since the movie already exists,# we select it using the same filter# mechanism as for queries.movie: {filter: {title: {eq: "Dune"}, year: {eq: 2020}},first: 1},body: "Yay!",rating: 5,# Similarly to the movie we select# the existing user.author: {filter: {name: {eq: "Atreides"}},first: 1}}) {idbody}}
Use a GraphQL mutation to add an actress to a movie:
mutation add_actor {update_Movie(# Specify which movie needs to be updated.filter: {title: {eq: "Dune"}, year: {eq: 2020}},# Specify the movie data to be updated.data: {actors: {add: [{filter: {full_name: {eq: "Charlotte Rampling"}}}]}}) {idactors {id}}}