GraphQL 3 (24.02.2023 3M) Flashcards

1
Q

What are benifits of using variables?

A
  • In our client code, we can simply pass a different variable rather than needing to construct an entirely new operation.
  • This is also in general a good practice for denoting which arguments in our query are expected to be dynamic.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What types can variables have?

A

All declared variables must be either scalars, enums, or input object types. So if you want to pass a complex object into a field, you need to know what input type that matches on the server.

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

How to make varible optional or required?

A

Variable definitions can be optional (nullable) or required (not-nullable).

For example, $episode is optional, $withFriends is required
($episode: Episode, $withFriends: Boolean!)

Notice: if the field you are passing the variable into requires a non-null argument, then the variable has to be required as well.

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

Describe default values for variables.

A

Default values can also be assigned to the variables in the operation by adding the default value after the variable declaration.

See the example image.

When a default value is provided for the variable. You can omit value in the variables dictionary.

When default values are provided for all variables, you can call the query without passing any variables.

If a value for a variable with a default parameter is passed as part of the variables dictionary, it will override the defaults.

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

What directives are intended for?

A

Directives allow us to dynamically change the structure and shape of our queries (operations) using variables.

Directives can be useful to get out of situations where you otherwise would need to do string manipulation to add and remove fields in your query.

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

What two directives are required to be presented by any spec-compliant GraphQL server implementation? Are they only possible directives?

A
    • @include(if: Boolean) only include the body of directive in the result if the argument is true.
    • @skip(if: Boolean) Skip the body of directive if the argument is true.
  1. No, different servers can have their own set of directives, that procced as server desire
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Give an example of @include directive.

A

See the image

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

Give an example of @skip directive.

A

See the image.

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