GraphQL 4 (27.02.2023 3M) Flashcards

1
Q

With what can directives be used?

A

A directive can be attached to a field or fragment.

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

What is mutation?

A

Mutation is operation that intended to make server-side data changes.

Technically any query could be implemented to cause a data write. However, it’s useful to establish a convention that any operations that cause writes should be sent explicitly via a mutation.

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

Do mutations return something back?

A

It may return something back, but may not.
Returning something back can be useful for fetching the new state of an object after an update.

Let’s look at a simple example mutation:

As you can see, you must explicitly ask for fields of the mutation return value. And also you must get the return value of a mutation and can’t ignore it.

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

What is the difference between having multiple fields in queries and in mutations?

A

A mutation can contain multiple fields, just like a query. There’s one important distinction between queries and mutations, other than the name:

While query fields are executed in parallel, mutation fields run in series, one after the other.

This means that if we send two incrementCredits mutations in one request, the first is guaranteed to finish before the second begins, ensuring that we don’t end up with a race condition with ourselves.

See an example of multiple mutations in attachment

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

What inline fragments are usefull for?

A

GraphQL schemas include the ability to define interfaces and union types. It means one field may contain different types and this way different subfields.

See the example image.

In this query, the hero field returns the type Character, which might be either a Human or a Droid depending on the episode argument. In the direct selection, you can only ask for fields that exist on the Character interface, such as name.

To ask for a field on the concrete type, you need to use an inline fragment with a type condition

Named fragments can also be used in the same way, since a named fragment always has a type attached.

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

What are Meta fields?

A

It is meta-information about a type. For example ‘__typename’. It returns the name of the type.

GraphQL services provide a few meta fields, the rest of which are used to expose the Introspection system.

See the example image.

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

What is special object GraphQL query and response starts from?

A

We start with a special “root” object.

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