Implementation of GraphQL in express
Create and import the database
mysqladmin -u user -p create database library
mysql -u user -p library < library.sql
Create the configuration file and fill variables
cp .env.dist .env
Serve it
npm run serve
Go to the GraphQL console and run a query
mutation {
addAuthor(name: "Killian Jornet") {
id,
name
}
addGenre(name: "Sport") {
id,
name
}
addBook(
name: "A Manual for Mountain Runners and Ski Mountaineers ",
genreId: 3,
authorIds: [3,4,5]
) {
id,
name,
genre {
id,
name
},
authors {
id,
name
}
}
}
query {
books {
id,
name,
genre {
id,
name
},
authors {
id,
name
}
},
genres {
id,
name
},
authors {
id,
name
}
book(id: 3) {
id,
name
}
author(id: 3) {
id,
name
}
}