GraphQL Basics Flashcards
What is GraphQL?
GraphQL is a query language for your API.
Compare GraphQL and REST.
- Multiple round trips (REST) vs one single request (GraphQL).
- Over fetching and under fetching (REST) vs tailor-made queries (GraphQL).
- No need to expose a new API when a UI refactor is needed.
What are the two main types requests of GraphQL?
- Query
- Mutation
What is an alias?
You can’t query for the same field with different arguments. Aliases let you rename the result of a field with anything you want.
What are fragments?
Fragments are GraphQL’s reusable units. They let you build sets of fields and then include them in multiple queries.
How query and mutation fields are executed?
Query fields are executed in parallel, mutation fields run in series, one after the other.
What GraphQL Client can do? (6 items)
- Communicate with the server (send requests and receive responses)
- Integrate with view components and update the UI
- Cache query results
- Handle errors and validate schema
- Provide local state management
- Provide pagination
What are resolvers?
The resolver function is a function that resolves a value for a type/field in the GraphQL Schema.
Four responsibilities of GraphQL Server
- Schema and Resolver Functions
- Network Layer
- GraphQL Execution Engine
- Batched Resolving
3 Field Level Directives
- @include
- @skip
- @deprecated
Can query and mutations go in one request togehter?
No, they need to go separately.
GraphiQL or Apollo playground doesn’t support it, but official documentation says it could be possible in multi-operation documents.
Is this correct
addNewSession(session: Session): Session
No, param session must be Input rather than Type
How to create a mapping between Enum and the internal model?
Just create a resolver for GraphQL enum.
In object {ENUM: ‘mappedValue’} key is GraphQL enum whereas ‘mappedValue’ is a value from the internal model.
Assuming that Session contains speakers taken via REST endpoint, that doesn’t work. What will be returned for:
query {
sessions {
title
id
speakers {
name
}
}
}
- n errors for every session (errors section)
- n sessions with speakers = null (data section)
What is a Union?
It is a construction allowing to return of two (or more) different types.
It can be used to discard the error section and return errors or data in the data section of the response.
What can we do with Apollo Studio?
Register schemas and monitor usage.