I saved the code from tutorial on: https://www.howtographql.com/graphql-js/1-getting-started/
So I can use this as a reference for further programming with GraphQL.
git clone https://github.com/andriesfilmer/hackernews-node.git
cd hackernews-node
npm install
Run node server
node src/index.js
Run prisma
npx prisma generate
Run prisma studio
npx prisma studio
query { info }
query {
user { id name }
}
query {
feed(orderBy: { createdAt: asc }) {
count
links {
id
description
url
}
}
}
With curl
curl 'http://localhost:4000/' -H 'Content-Type: application/json' \
--data-binary '{"query":"query{feed(orderBy:{createdAt:asc}){count links{id description url}}}"}'
query {
feed(filter: "an", take: 2, skip: 1) {
links {
id
description
url
postedBy {
id
name
}
}
}
}
mutation {
post(url: "www.prisma.io", description: "Prisma replaces traditional ORMs") {
id
}
}
mutation {
signup(name: "Alice", email: "[email protected]", password: "graphql") {
token
user {
id
}
}
}
When using the signup mutation or login mutation look at the response bearer
token.
Copy this TOKEN to HTTP HEADERS in the browser when running the server http://localhost:4000/
{
"Authorization": "Bearer __TOKEN__"
}
mutation {
login(email: "[email protected]", password: "graphql") {
token
user {
email
links {
url
description
}
}
}
}
Open a browser on localhost:4000
and create a subscription.
subscription {
newLink {
id
url
description
postedBy {
id
name
email
}
}
}
Open a other browser and make a mutaion, while watch the subscription in the other browser.
mutation {
post(url: "www.graphqlweekly.com", description: "Curated GraphQL content coming to your email inbox every Friday") {
id
}
}
subscription {
newVote {
id
link {
url
description
}
user {
name
email
}
}
}
mutation {
vote(linkId: "__LINK_ID__") {
link {
url
description
}
user {
name
email
}
}
}