Font size
WorksheetsQuiz sur Apollo GraphQL
Total questions: 38
Worksheet time: 19mins
What is GraphQL?
A query language for REST APIs
A query language for graph-based APIs
A framework for database development
A general-purpose programming language
What is the main difference between REST and GraphQL?
GraphQL allows retrieving multiple resources in a single request
REST allows performing complex queries on databases
GraphQL is faster than REST
REST is only compatible with JavaScript
What does the term "Schema" mean in GraphQL?
A representation of the database
A configuration file for queries
The definition of data types, queries, and mutations
A description of business logic
What are scalar types in GraphQL?
Types that can contain multiple sub-types
Basic types like String, Int, Float, Boolean, and ID
Types that define resolution functions
Types specific to mutations
How do you define a GraphQL schema with Apollo Server in Node.js?
Use graphql-tools to generate a schema based on YAML files.
Define a schema using typeDefs that represent types, queries, and mutations, then associate it with resolvers.
Use JSON files to describe the types.
Define schemas only with simple JavaScript objects.
What is a "resolver" in Apollo Server?
An object containing data
A function that resolves the values of a field in a query
A file that defines the structure of the schema
A means of filtering data in the database
What is a "resolver" in Apollo Server?
It is a function that resolves user queries in the application.
It is a function that generates schemas for REST APIs.
It is a function that associates a field of a GraphQL type with a data source, often a database or an external service.
It is a function that performs calculations on the data sent by the user.
What are the correct statements about the structure of the resolvers object?
The Query and Mutation types in the schema must have corresponding keys in the resolvers object
The resolvers object can contain a maximum of 10 resolver functions
The names of the resolver functions must match the names of the fields in the schema
The resolver functions can have any name
What is the AST (Abstract Syntax Tree) in GraphQL?
A tree that defines the schema of data types
A tree representation of the structure of a GraphQL query after it has been validated
A tool for generating Apollo server code
A list of data that will be sent to the GraphQL server
What is the purpose of a "query" in GraphQL?
Modify data on the server
Retrieve data from the server
Add data to the database
Manage authentication and permissions
What is the format of the result of a GraphQL query after being transformed into an AST?
An XML file
A JSON tree representing the structure of the query and data
A string with SQL instructions
A binary file
What is the role of the AST during the validation of a GraphQL query?
It checks the syntax of the query to ensure that the fields are correctly defined
It executes the requested mutation
It optimizes the queries for the server
It converts the data to JSON before sending it
What is the structure of the response of a GraphQL request in case of an error?
An HTTP error message
An object data with a null value and an array errors
A redirection to an error page
No response, the error is directly handled by the client
In GraphQL, what does a "mutation" represent?
A data reading operation
A data modification or addition operation
In GraphQL, what does a "mutation" represent?
A data reading operation
A data modification or addition operation
A data deletion operation
An operation to obtain multiple resources in a single request
What is the default behavior of Apollo Server when an error occurs in a mutation?
Apollo Server continues the execution of the mutation and ignores the error
Apollo Server cancels the mutation and returns an error in the response
Apollo Server returns an HTTP 404 error
Apollo Server redirects to an error page
What happens in a GraphQL mutation if an error occurs during the execution of the mutation?
The error is returned in the errors field of the response
The error blocks the transaction and is not returned
The error is logged in a log file but the mutation continues
The mutation is ignored and no data is returned
What is a DataSource in Apollo Server and why is it used?
It is an abstraction for making SQL queries directly
A DataSource is a mechanism for retrieving data from different sources (REST APIs, databases, etc.)
It is a type of mutation for sending data to an external API
A DataSource is a local cache for storing GraphQL responses
How to implement a custom DataSource in Apollo Server?
By using ApolloDataSource as a base class
By calling an external REST service on each request
By creating a datasource.js file that contains a data object
By using a schema file to define resolvers
What is the advantage of using DataSources in Apollo Server for managing external API calls?
They allow centralizing error management logic
They handle caching to avoid making multiple identical requests
They manage the security of API calls
They simplify the creation of GraphQL schemas
What methods are typically present in a RESTDataSource class of Apollo Server?
get(), post(), put(), delete()
fetch(), query(), update(), remove()
query(), mutate(), subscribe()
add(), remove(), update(), fetch()
In the context of GraphQL, a cache for the DataSource can be useful for:
It helps to resolve a query that has been made for the first time much more quickly.
It helps to manage the mixing of different endpoints with different caching policies.
It helps to resolve more quickly the fields of queries that have already been retrieved.
It prevents unnecessary REST API calls for data that is not frequently updated.
What does Apollo Server do when the request is transformed into an AST?
It executes it immediately on the database
It compiles it into JavaScript code
It validates it to ensure it complies with the schema and GraphQL rules
It caches it in the local cache before resolving it
What does the error code GRAPH_VALIDATION_FAILED mean in Apollo Server?
The request is malformed or contains syntax errors
The data returned by the request is not valid
The user is not authorized to execute the request
The server failed to connect to the database
How does Apollo Server handle errors in a GraphQL request?
It only sends HTTP error codes
It captures them and returns them in an errors object in the response
It redirects the user to an error page
It automatically retries the request in case of an error
In Apollo Server, what is the format of the response for a successful mutation?
{ data: { mutationName: result } }
{ mutationName: result }
{ success: true, data: result }
{ status: 'success', data: result }
How does Apollo Server handle query resolution?
It directly executes SQL queries
It resolves the fields of queries using "resolvers"
It sends the queries to an external server
It compiles the queries into JavaScript
How does Apollo Server handle errors during the execution of a mutation?
It returns an object with errors and the modified data
It continues the execution of the mutation despite the error
It cancels all ongoing mutations
It returns only an error message without data
What role does Apollo Client play in a GraphQL application?
Manage the database
Serve GraphQL queries to a server
Manage local state and GraphQL queries from the client
Handle mutations and subscriptions
What does Apollo Client do with errors from a GraphQL request?
It hides them to avoid repeating errors
It sends a notification to the user
It passes them as error objects in the response
It stops the execution of any other request
How does Apollo Client optimize the performance of queries?
It uses real-time queries
It caches responses and uses the cache to avoid repeated queries
It compresses data before sending it to the server
It allows parallel execution of queries
How does Apollo Client manage the caching of query results in React?
Apollo Client never caches the results.
Apollo Client uses an in-memory cache to store the responses of queries and reuse them to avoid making network requests again.
Apollo Client stores all data in the browser's local storage.
Apollo Client only caches the results of mutations.
What are the differences between the useQuery and useMutation hooks?
The useQuery hook returns an array, while the useMutation hook returns an object
The useQuery hook returns an object, while the useMutation hook returns an array
The useQuery hook is used to send queries, while the useMutation hook is used to send mutations
The useQuery hook executes automatically on component render, while the useMutation hook returns a mutate function that must be called to trigger the mutation
What is the purpose of ApolloProvider in a React project?
Provide the instance of Apollo Client to the entire React application
Initialize Apollo Server
Manage mutations
Define the GraphQL schema
What is the role of ApolloProvider in a React application?
ApolloProvider initializes Apollo Server.
ApolloProvider allows the React application to communicate with the Apollo server.
ApolloProvider is used to handle errors in GraphQL queries.
ApolloProvider is used to add mutations to the schema.
What is a "query hook" in Apollo Client and how do you use it in React?
A "query hook" allows you to execute POST type requests in the React component.
A "query hook" allows you to execute GraphQL queries and manage loading, error, and data states.
A "query hook" allows you to synchronize data between multiple React components.
A "query hook" is a way to manage server-side caching.
What is the purpose of Apollo Studio?
Provide an IDE for writing Apollo code
Offer an interface to manage and monitor GraphQL APIs
Automatically create GraphQL schemas
Deploy Node.js applications
What information can you explore in Apollo Graph Studio?
The structure of the GraphQL schema
The history of HTTP requests
The server logs
User statistics
