GraphQL module#72 Flashcards

1
Q

How many endpoints does GraphQL expose?

A

GraphQL exposes a single endpoint.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the QL stand for anyway

A

Query Language, which is really just a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is one of the biggest differences between GraphQL and REST?

A

GraphQL unlike REST does not rely on HTTP verbs in order to determine the request type.

With REST you cannot pick and choose what the server returns. Using a GraphQL query though, you can.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does GraphQL reduce demands on the network and processing power?

A

By requiring the client to specify exactly what information they want to be returned, it reduces processing and payload sizes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s considered an “argument” within a GraphQL query?

A

As in JavaScript it’s the item that is passed in parenthesis. Example:

{
  person(id: "1") {
    name
  }
}
id: "1" is the parameter/argument
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can subsets of data also have arguements?

A

Yep, as long as the API permits. Example:

{
  person(id: "1") {
    name
    friends(limit: 100)
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are aliases in GraphQL and how are they written?

A

Aliases are a way of returning data with a naming convention of your own choosing. It is a custom request that give your data a certain name. Example:

{
  owner: person(id: "1") {
    fullname: name
  }
}
Which returns the custom name for "name" as "fullname"
{
  "data": {
    "owner": {
      "fullname": "Tony"
    }
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are fragments in GraphQL?

A

Fragments allow for the specification of the structure of a dataset 1 time. Example

{
  owner: person(id: "1") {
    ...personFields
  }
  first_employee: person(id: "2") {
    ...personFields
  }
}

fragment personFields on person {
fullname: name
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why and how are variables used in GraphQL?

A

They are used when we need to dynamically specify a value in a query.

Translation: Sometimes values will change so the best way to represent them is with a variable.

Here’s a standard query followed by a the same query written with variables:

{
  owner: person(id: "1") {
    fullname: name
  }
}
query GetOwner($id: String) {
  owner: person(id: $id) {
    fullname: name
  }
}

{
“id”: “1”
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the equivalent form of a named query or a query that is using variables in the request?

A

It is equivalent to a named function. We do this to differentiate it from other queries when there are many to our application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Variables can be specified as required in our program. How is it written?

A

By using the ! Bang symbol. Here’s the example:

query GetOwner($id: String = “1”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When using GraphQL directives can be set. What are the used for and how to write them?

A

Directives let you include or exclude a field based on whether a variable returns true or false.

Here we have a variable that ends up false so this field will be excluded.

query GetPerson($id: String) {
  person(id: $id) {
    fullname: name,
    address: @include(if: $getAddress) {
      city
      street
      country
    }
  }
}

{
“id”: “1”,
“getAddress”: false
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

There are two kinds of directives available to us, what are they?

A

@include (if true)

@skip(if:Boolean)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly