Skip to main content

Queries

Example queries to show what you can get from the API, how you can filter and order the results.

Basic authors query

The very basic query is just to get list of first 3 authors:

query {
authors(first: 3) {
edges {
node {
id
_id
firstName
lastName
}
}
}
}
Response
{
"data": {
"authors": {
"edges": [
{
"node": {
"id": "YXV0aG9yLTE=",
"_id": "1",
"firstName": "John",
"lastName": "Johnson"
}
},
{
"node": {
"id": "YXV0aG9yLTI=",
"_id": "2",
"firstName": "Martin",
"lastName": "Fowler"
}
},
{
"node": {
"id": "YXV0aG9yLTM=",
"_id": "3",
"firstName": "Jason",
"lastName": "Lengstorf"
}
}
]
}
}
}

Filter authors by first name

But let's say you want just authors whose first name starts with J:

query {
authors(firstName: "J") {
edges {
node {
id
_id
firstName
lastName
}
}
}
}
Response
{
"data": {
"authors": {
"edges": [
{
"node": {
"id": "YXV0aG9yLTE=",
"_id": "1",
"firstName": "John",
"lastName": "Johnson"
}
},
{
"node": {
"id": "YXV0aG9yLTM=",
"_id": "3",
"firstName": "Jason",
"lastName": "Lengstorf"
}
},
{
"node": {
"id": "YXV0aG9yLTk=",
"_id": "9",
"firstName": "Jamie",
"lastName": "Zawinski"
}
}
]
}
}
}

Order authors

And you want to order it by id in descending order?

query getAuthors {
authors(firstName: "J", orderBy:[
{
field: ID
direction: DESC
}
]) {
edges {
node {
id
_id
firstName
lastName
}
}
}
}
Response
{
"data": {
"authors": {
"edges": [
{
"node": {
"id": "YXV0aG9yLTMw",
"_id": "30",
"firstName": "Jeff",
"lastName": "Atwood"
}
},
{
"node": {
"id": "YXV0aG9yLTEz",
"_id": "13",
"firstName": "Joe",
"lastName": "Sondow"
}
},
{
"node": {
"id": "YXV0aG9yLTk=",
"_id": "9",
"firstName": "Jamie",
"lastName": "Zawinski"
}
}
]
}
}
}

Get author with specific ID

query {
author(id: 1) {
id
_id
firstName
lastName
}
}
Response
{
"data": {
"author": {
"id": "YXV0aG9yLTE=",
"_id": "1",
"firstName": "John",
"lastName": "Johnson"
}
}
}

Basic quotes query

query {
quotes {
edges {
node {
id
_id
text
}
}
}
}
Response
{
"data": {
"quotes": {
"edges": [
{
"node": {
"id": "cXVvdGUtMQ==",
"_id": "1",
"text": "First, solve the problem. Then, write the code."
}
},
{
"node": {
"id": "cXVvdGUtMg==",
"_id": "2",
"text": "Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
}
},
{
"node": {
"id": "cXVvdGUtMw==",
"_id": "3",
"text": "If you stop learning, then the projects you work on are stuck in whatever time period you decided to settle."
}
}
]
}
}
}