GraphQL Docs Flashcards

studying GraphQL docs

1
Q

What is an operation type?

A

an operation type is either a query, mutation, or subscription and describes what type of operation you’re intending to do.

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

What is an operation name?

A

similar to a function name - helps with debugging and server-side logging

**only required in multi-operation documents.*

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

What is the one important distinction between queries and mutations?

A

query fields are executed in parallel

mutation fields run in series, one after the other

ex. if we send two incrementCredits mutation fields 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.

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

True or False: GraphQL can be used with any backend framework or programming langauge.

A

True

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

GraphQL type language keywords

A
  • type
  • schema (query, mutation)
  • enum
  • interface
  • query
  • mutation
  • union
  • fragment
  • … on <Type> (inline fragment)</Type>
  • input* cant have args on their fields
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

TRUE OR FALSE: GraphQL queries always end at scalar values

A

TRUE.

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

How to think about each field in a GraphQL query

A

think of every field in a GraphQL query as a method or function of the previous type, which returns the next type.

Each field on a type is backed by a function called a resolver that is provided by the GraphQL server developer.

execution completes when a field returns a scalar value (number or string).

If a field returns an object value, the query keeps executing until every field on that object produces a scalar.

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

Root type or Query type

A

the type at the top level of every GraphQL server that represents all possible entry points into the GraphQL API

on Frontend defined as:
~~~
type Query {
human(id: ID!): Human
}
~~~

on BE Server side: (resolver)
~~~
Query: {
human(obj, args, context, info) {
return context.db.loadHumanByID(args.id).then(
userData => new Human(userData)
)
}
}
~~~

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

What arguments does a resolver function recieve?

A
  1. obj - the previous object, which for a field on the root Query type is often not used.
  2. args - the arguments provded to the field in the GraphQL query
  3. context - the value which is provided to every resolver and holds important contextual information like the currently logged in user, or access to a database **usually async, returns a Promise, Task, Deferred depending on implementation language*
  4. info - a value which holds field-specific information relevant to the current query as well as the schema details.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Trivial resolvers

A

ex.
~~~
Human: {
name(obj, args, context, info) {
return obj.name
}
}
~~~

**NOTE: many GraphQL libraries will let you omit resolvers this simple and will assume if a resolver isn’t provided for a field, that a property of the same name should be read and returned.*

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

List resolvers

A

ex.
~~~
Human: {
starships(obj, args, context, info) {
return obj.starshipIDs.map(
id => context.db.loadStarshipByID(id).then(
shipData => new Starship(shipData)
)
)
}
}
~~~

returns a list of Promises… GraphQL will wait for all Promises concurrently betfore continuing… when it has a list of objects, it will concurrently continue yet again to load the name field on each of these items.

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