GRAPH QL Flashcards
What is GraphQL?
GraphQL is an open-source query language for APIs and a runtime for executing those queries with the existing data.
What are the main building blocks of GraphQL?
The main building blocks of GraphQL are:
Schema: Defines the available data types, queries, and mutations in the API.
Queries: Retrieve data from the server.
Mutations: Modify data on the server.
Subscriptions: Set up real-time communication channels with the server.
How does GraphQL handle versioning?
GraphQL does not require versioning like REST APIs. Clients can request exactly the data they need, and the server’s schema can evolve over time without breaking existing clients. Clients have control over the data they receive, reducing the need for versioning.
What are resolvers in GraphQL?
Resolvers are functions that resolve the fields specified in a GraphQL query. They define how to fetch or manipulate the data for each field in the schema. Each field in the schema corresponds to a resolver function that provides the data for that field.
How does GraphQL handle data fetching from multiple sources?
GraphQL enables data fetching from multiple sources by allowing resolvers to fetch data from different services or databases. Resolvers can orchestrate data fetching and aggregation, pulling data from various sources to fulfill a single query.
What is the difference between a query and a mutation in GraphQL?
A query is used to fetch data from the server without modifying it, while a mutation is used to modify or create data on the server. Queries are executed in parallel, but mutations are executed sequentially to maintain data consistency.
How does GraphQL handle authentication and authorization?
GraphQL itself does not handle authentication and authorization directly. It is typically implemented as a middleware or in combination with authentication and authorization mechanisms such as JWT (JSON Web Tokens), OAuth, or custom logic within the resolver functions.
What is the purpose of GraphQL subscriptions?
GraphQL subscriptions enable real-time communication between the server and clients. Clients can subscribe to specific events or data changes, and the server can push updates to the subscribed clients when relevant data changes occur.
How can errors be handled in GraphQL?
GraphQL uses a standardized error format to handle errors. In the response, along with the data, there is an optional “errors” field that contains an array of error objects. Each error object provides information about the error, such as the error message and location in the query.
What are some popular GraphQL client libraries?
Some popular GraphQL client libraries include Apollo Client, Relay, and Urql. These libraries provide convenient tools and utilities to interact with GraphQL APIs from client-side applications, making it easier to send queries, mutations, and subscriptions.