GraphQL Flashcards

1
Q

SDL

A

SDL (Schema definition Language)

  • instead of functions to create schema, use string based syntax for schemas
  • easier to read
  • can be composable
  • supported by all tools
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Scalar and Object Types

A
  • describe resources used in queries/mutations
  • Scalar types are built in primitives
    • string
    • int
    • float
    • boolean
    • ID
  • Object types are custom shapes with fields that are either scalar or other object types
  • object type fields also describe any arguments and or validations
  • types are target of all requests
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Query and Mutation types

A
  • Query type describes different queries your API is capable of
  • Query operation is just name with possible arguments that eventually returns a type
  • Mutation is exact same thing but with intent of mutating the DB vs just reading
  • Query and mutations are basically like routes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Mutations

A
  • graphql’s method of using put, post, delete methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fields in GraphQL

A

You can think of each field in a GraphQL query as a function or method of the previous type which returns the next type. In fact, this is exactly how GraphQL works. Each field on each type is backed by a function called theresolverwhich is provided by the GraphQL server developer. When a field is executed, the correspondingresolveris called to produce the next value.

If a field produces a scalar value like a string or number, then the execution completes. However if a field produces an object value then the query will contain another selection of fields which apply to that object. This continues until scalar values are reached. GraphQL queries always end at scalar values.

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

Architectural Use Cases

A
  1. GraphQL server with a connected database
  2. GraphQL server to integrate existing system
  3. Hybrid approach with connected DB and integration of existing system
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Imperative data fetching

A
  • Construct and send HTTP request (e.g with fetch in javascript)
  • Receive and parse server response
  • Store Data locally
  • Display information in UI
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Declarative Data fetching

A
  • Describe data requirements
    • displays information in UI
    • everything else will be handled by graphql client (networking and storing data is abstracted away)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

GraphQL Client Side

A
  • used to solve UI related problems
  • alternative to REST endpoints
  • One single endpoint
  • Send queries instead of reaching a particular endpoint
  • REST API forces us to retrieve unnecessary data that we don’t need and make multiple calls
  • GraphQL makes a specific query to get specific information you need
  • Allows you to specific information and nested info without having to call server more than once
  • Makes it easier/lightweight for frontend
  • sits in front of any existing API
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

REST vs GraphQL

A
  • GraphQL only has one endpoint and doesn’t need resource url + verb combo
  • in REST, shape and size of data resource is determined by server, Graphql is determined by the query(request)
  • in REST, multiple API calls need to be made to retrieve relational data, but GraphQL can start with entry resource and traverse all connections in one request
  • in REST, shape of response determined by whom created server, in GraphQL the shape is determined by query
  • in REST, single request will execute on controller on server but in GraphQL a request might execute many resolvers on server
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Query

A

A type on a schema that defines operations clients can perform to access data that resembles the shape of other Types in the schema

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

Creating Query

A
  • create Query type in schema using SDL
  • Add fields to Query Type
  • Create resolvers for that field
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Creating Resolvers

A
  • resolver names must match exact field name on schema types
  • resolvers must return value type declared for matching field
  • resolvers can be async
  • can retrieve data from any source
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Resolvers

A
  • functions that are responsible for returning values for fields that exist on type in schema
  • resolvers execution is dependent on incoming client query
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Mutations

A
  • type on schema that defines operations clients can perform to mutate data (create, update, delete)
  • define mutation type on schema using SDL
  • add fields for mutation type
  • add arguments for mutation fields
  • create resolvers for mutation fields
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Enums

A

set of discrete values that can be used in place of scalars. An enum field must resolve to one of the values in the enum. Great for limitng a field to only a few different options

17
Q

Interfaces

A

Abstract types that can’t be used as field values but used as foundations for explicit types

18
Q

Unions

A

like interfaces but without an defined common fields among types. useful when need to access more than one disjoint type from one query