Top 50 GraphQL Interview Questions and Answers Explained

GraphQL is a general purpose query language library and can be used both in a Node server and in the browser. Learn GraphQL Questions and Answers with us and hope it will help you during you job interview.

GraphQL Interview Questions and Answers

GraphQL questions and answers with explanation

Question#1 Which of the following GraphQL architectures has the database and the GraphQL server integrated on a single node?

a) Hybrid approach

b) GraphQL server with existing system

c) GraphQL server with connected database

d) All the options

Correct Answer: GraphQL server with connected database

Question#2 GraphQL has __ endpoint(s).

a) One

b) Three

c) Many

d) Two

Correct Answer: One

Question#3 Which of the following architectures is useful for the firms that have legacy infrastructure and distinct APIs?

a) Hybrid approach

b) GraphQL server with existing system

c) GraphQL server with connected database

d) None of the options

Correct Answer: GraphQL server with existing system

Question#4 __ helps to retrieve specific information from the server.

a) Sub fields

b) Fields

c) Arguments

d) Mutations

Correct Answer: Arguments

Question#5 _ is generally seen as a contract between the client and the server in GraphQL API.

a) Mutation

b) Query

c) Schema

d) None of the options

Correct Answer: Schema

Question#6 __ allows you to ask the server for the required data.

a) Queries

b) Subscriptions

c) Mutations

d) None of the options

Correct Answer: Queries

Question#7 GraphQL can be implemented only with Python language.

a) True

b) False

Correct Answer: False

Question#8 GraphQL has a feature of querying its own schema.

a) True

b) False

Correct Answer: True

Question#9 __ is the most basic component of a GraphQL schema.

a) Field

b) Object

c) Types

d) All the options

Correct Answer: Object

Question#10 The following are default scalar types in GraphQL, except _.

a) Char

b) Boolean

c) Float

d) Int

Correct Answer: Char

Question#11 _ is the popular response format that is usually used for mobile and web applications.

a) JSON

b) XML

c) XLS

d) CSV

Correct Answer: JSON

Question#12 What are GraphQL subscriptions used for?

a) Event-based real-time functionality

b) Schema-based real-time functionality

c) To combine Queries and Mutations and to allow you to read and write data

d) To subscribe to the GraphQL weekly newsletter

Correct Answer: Event-based real-time functionality

Question#13 A resolver function is __.

a) A function that a GraphQL client uses to resolve a query on the frontend

b) A function that solves all your problems

c) A synonym for serverless functions

d) A function on a GraphQL server that is responsible for fetching the data for a single field

Correct Answer: A function on a GraphQL server that is responsible for fetching the data for a single field

Question#14 What is the significant benefit of using a GraphQL client library?

a) It saves you from writing infrastructure code for networking and caching

b) GraphQL clients do not provide actual advantages but it is always good to use third party libraries

c) It makes it easier to use animations inside your app

d) A GraphQL client is mainly used to improve security

Correct Answer: It saves you from writing infrastructure code for networking and caching

Question#15 Which of the following functions in GraphQL-tools helps you to bind schema and resolver?

a) inheritResolversFromInterfaces

b) allowIndefinedInResolve

c) resolverValidationOptions

d) makeExecutableSchema

Correct Answer: makeExecutableSchema

Question#16 GraphQL is not tied to any specific database.

a) True

b) False

Correct Answer: True

GraphQL MCQ Questions & Answers Explained

Question#17 GraphQL queries allows to pass multiple arguments.

a) True

b) False

Correct Answer: True

Question#18 _ is a collection of functions that generate response for a GraphQL query.

a) Subscriptions

b) Mutations

c) Resolver

d) Directives

Correct Answer: Resolver

Question#19 Which of the following mutations is present in GraphQL?

a) Deleting data

b) Creating data

c) Updating data

d) All the options

Correct Answer: All the options

Question#20 __ makes the queries more dynamic and flexible.

a) Fragments

b) Aliases

c) Variable names

d) Operation names

Correct Answer: Variable names

Question#21 Which transport does Apollo use to implement subscriptions?

a) WebSockets

b) TCP

c) UDP

d) HTTP 2

Correct Answer: WebSockets

Question#22 The development speed in GraphQL is faster than REST.

a) True

b) False

Correct Answer: True

Question#23 Which languages that can be used to implement GraphQL server.

a) Python

b) java

c) Go

d) All the options

Correct Answer: All the options

Question#24 _ fetching extra data for an API request.

a) Under-fetching

b) Over-fetching

c) In-fetching

d) Out-fetching

Correct Answer: Over-fetching

Question#25 Overfetching increases payload size.

a) True

b) False

Correct Answer: True

Question#26 GraphQL is a query language, but REST is not.

a) True

b) False

Correct Answer: True

Question#27 What is mutation ?

a) Mutation is used for the write operation.

b) A mutation is used for operations like add, delete and edit data.

c) Both

d) None

Correct Answer: Both

Question#28 Does GraphQL support server-side caching?

a) Yes

b) No

Correct Answer: No

Question#29 GraphQL can be used only with SQL.

a) True

b) False

Correct Answer: False

Question#30 Which of the following is a feature of GraphQL?

a) Introspective

b) Strongly typed

c) Version free

d) All the options

Correct Answer: All the options

Question#31 GraphQL was developed and open-sourced by _.

a) Apple

b) Facebook

c) Google

d) Microsoft

Correct Answer: Facebook

Question#32 GraphQL APIs are organized in terms of __.

a) Endpoints and Types

b) Fields and Endpoints

c) Fields and Types

d) All the options

Correct Answer: Fields and Types

Question#33 __ is restricted to a particular set of allowed values.

a) Enumeration type

b) Object type

c) Scalar type

d) None of the options

Correct Answer: Enumeration type

Question#34 Which of the following is a special root type present for writing the schema of an API?

a) type Subscription{…}

b) type Mutation{…}

c) type Query{…}

d) All the options

Correct Answer: All the options

Question#35 Fields repetition can be avoided by creating _ on the returned type.

a) Mutations

b) Aliases

c) Fragments

d) All the options

Correct Answer: Fragments

Question#36 The keyword _ is used to indicate mutation operation.

a) Directives

b) Subscription

c) Query

d) Mutation

Correct Answer: Mutation

Question#37 _ manipulate the information stored in the backend.

a) Queries

b) Subscriptions

c) Mutations

d) All the options

Correct Answer: Mutations

Question#38 __ requests data from the same fields with different arguments.

a) Aliases

b) Connections

c) Fragments

d) Nested Fields

Correct Answer: Aliases

Question#39 _ helps to distinguish queries from each other.

a) Nested Fields

b) Operation names

c) Aliases

d) Fragments

Correct Answer: Operation names

Question#40 Complex queries are written using multiple nested fields.

a) True

b) False

Correct Answer: True

Question#41 GraphQL is a query language for databases.

a) True

b) False

Correct Answer: False

Question#42 __ help to inform the important events immediately.

a) Fragments

b) Subscriptions

c) Queries

d) Mutations

Correct Answer: Subscriptions

Question#43 Which statement about GraphQL servers is true?

a) A GraphQL server that does not use DataLoader is not a GraphQL Server

b) A single record is never fetched more than once for a given query

c) Query fields are resolved depth-first

d) Resolvers can be defined on a field granularity

Correct Answer: Resolvers can be defined on a field granularity

Question#44 Which of the following clients use GraphQL?

a) Coursera

b) Shopify

c) GitHub

d) All the options

Correct Answer: All the options

Question#45 How are HTTP requests sent by ApolloClient authenticated?

a) By attaching an authentication token to the request with dedicated ApolloLink middleware

b) ApolloClient has nothing to do with authentication

c) The ApolloClient needs to be instantiated with an authentication token

d) ApolloClient exposes an extra method called ‘authenticate’ where you can pass an authentication token

Correct Answer: By attaching an authentication token to the request with dedicated ApolloLink middleware

Question#46 What does a GraphQL client usually do before caching the results of a query?

a) Normalize the data

b) Validate the query results against the schema

c) Make the data available in the props of a React component

d) Call a resolver function

Correct Answer: Normalize the data

Question#47 Which mechanism is used by most tools to discover a GraphQL server’s type system?

a) IDL

b) Subscriptions

c) Introspection

d) GraphiQL

Correct Answer: Introspection

Question#48 Which of the following statements is true?

a) GraphQL can only be used together with SQL

b) GraphQL was invented by Facebook

c) GraphQL was developed by Netflix and Coursera

d) GraphQL is a database technology

Correct Answer: GraphQL was invented by Facebook

Question#49 The following strategies are valid ways to defend against abusive or large queries, except _.

a) Maximum query depth

b) Timeout

c) Calculating query complexity

d) Adding more servers

Correct Answer: Adding more servers

Question#50 Directives are preceded by __ character.

a) @

b) &

c) #

d) *

Correct Answer: @

Question#51 SDL stands for _.

a) System Derived Language

b) System Definition Language

c) Schema Derived Language

d) Schema Definition Language

Correct Answer: Schema Definition Language

Question#52 The loading of data with React and Apollo can be declared __.

a) Using XMLHTTPRequest and placing the query in the body of the request

b) Using ‘fetch’ and placing the query in the body of the request

c) Using a higher-order component called ‘graphql’

d) Using the ‘’ component and passing GraphQL query as prop

Correct Answer: Using the ‘’ component and passing GraphQL query as prop

Question#53 What is the benefit of the GraphQL schema and strong type system?

a) GraphQL does not have a type system

b) It solves the n+1 request problem

c) They work well with the JavaScript type system

d) Once the schema is defined, frontend and backend teams can work independently of each other

Correct Answer: Once the schema is defined, frontend and backend teams can work independently of each other

Question#54 The following statements are true, except _.

a) GraphQL has a built-in date type

b) Aliases can be used to name the result objects for multiple queries

c) Fragments are useful for the structure and reusability of your GraphQL code

d) Every field in a GraphQL type can be associated with zero or more arguments

Correct Answer: GraphQL has a built-in date type

Question#55 _ is a response where the client doesn’t get enough data.

a) Under-fetching

b) Over-fetching

c) In-fetching

d) Out-fetching

Correct Answer: Under-fetching

Question#56 GraphQL is a query language for API.

a) True

b) False

Correct Answer: True

Question#57 Over-fetching unnecessarily increases the payload size.

a) True

b) False

Correct Answer: True

Additional GraphQL Questions and Answers for Experience

1) What is the union in GraphQL?
Answer:
In GraphQL, sometimes we have to represent multiple objects, that’s why the union is used. The user can define more than one type as return type using a union.

2) What is the use of Enums in GraphQL?
Answer:
The enum or enumeration type in GraphQL is a special kind of scalar used to define a type, including a list of allowed values.

3) What is GraphQL?
Answer:
GraphQL is a query language created by Facebook in 2012 which provides a common interface between the client and the server for data fetching and manipulations.

The client asks for various data from the GraphQL server via queries. The response format is described in the query and defined by the client instead of the server: they are called client‐specified queries.
The structure of the data is not hardcoded as in traditional REST APIs – this makes retrieving data from the server more efficient for the client.

4) What is GraphQL schema?
Answer:
Every GraphQL server has two core parts that determine how it works: a schema and resolve functions.

The schema is a model of the data that can be fetched through the GraphQL server. It defines what queries clients are allowed to make, what types of data can be fetched from the server, and what the relationships between these types are.

Consider:

type Author {
id: Int
name: String
posts: [Post]
}
type Post {
id: Int
title: String
text: String
author: Author
}
type Query {
getAuthor(id: Int): Author
getPostsByTitle(titleContains: String): [Post]
}
schema {
query: Query
}

5) What is Authentication and Authorization in GraphQL?
Answer:
Authentication and AuthorizationAuthorization are the processes used in services. Sometimes people get confused in these two terms and exchange their definitions for each other.

Authentication: Authentication is a process that is used to claim an identity. Authentication is done when you want to log in to a service with a username and password. Here, you have to authenticate yourself. In GraphQL, Authentication can be implemented with common patterns such as OAuth. OAuth is an open protocol that is used to allow secure AuthorizationAuthorization in a simple and standard method from web, mobile, and desktop applications.

Authorization: On the other hand, AuthorizationAuthorization is a process that is used to give permission rules that specify the access rights of individual users and user groups to certain parts of the system. For authorization implementation in GraphQL, it is recommended to delegate any data access logic to the business logic layer and not handle it directly.

6) Where is GraphQL useful?
Answer:
GraphQL helps where your client needs a flexible response format to avoid extra queries and/or massive data transformation with the overhead of keeping them in sync.

Using a GraphQL server makes it very easy for a client side developer to change the response format without any change on the backend.

With GraphQL, you can describe the required data in a more natural way. It can speed up development, because in application structures like top-down rendering in React, the required data is more similar to your component structure.

7) Can GraphQL API be used to handle offline usage?
Answer:
GraphQL is a query language for web APIs that is designed only to work online. The caching abilities of some GraphQL libraries such as Relay and Apollo can be used for some cases, but there is not any proper offline solution developed or available yet.

8) What do you know about GraphiQL?
Answer:
GraphiQL is used to provide UI representation for GraphQL. It is an in-browser IDE used to explore GraphQL and make GraphQl usage easy. GraphQL supports real-time error highlighting, so you can see and handle errors easily.

9) Does GraphQL support server-side caching like REST?
Answer:
No. GraphQL doesn’t support server-side caching like REST.

10) What are the main operations that GraphQL supports?
Answer:
GraphQL supports three types of operations: query, mutation, and subscription. The query is used for the request, and it is a read operation, the mutation is used for write operations, and subscription is used for listening for any data changes. The server sends a notification message to the client after any data changes, if the client is subscribed to that event.

11) Can queries be used to modify data?
Answer:
Yes. Queries can be used to modify server-side data. But according to the conventional method, it is the best practice to use mutation for any write operation.

12) What is Apollo in GraphQL?
Answer:
Apollo is a platform for the implementation of GraphQL. As we know that GraphQL is a query language, so in order to use this query language easily, we need a platform, Apollo provides that platform.

Apollo provides two open-sourced libraries to create client and server. Here, the client is used to fetch data from a GraphQL server, and the server is used to create an API for GraphQL client.

13) What do you know by Mutation in GraphQL?
Answer:
Mutation is one of the most important operations in GraphQL. It is used for write operation when you want to add delete and edit data.

14) How to do Error Handling in GraphQL?
Answer:
A successful GraphQL query is supposed to return a JSON object with a root field called “data”. If the request fails or partially fails (e.g. because the user requesting the data doesn’t have the right access permissions), a second root field called “errors” is added to the response:

{
  "data": { ... },
  "errors": [ ... ]
}

15) How to do Server-Side Caching in GraphQL?
Answer:
One common concern with GraphQL, especially when comparing it to REST, are the difficulties to maintain server-side cache. With REST, it’s easy to cache the data for each endpoint, since it’s sure that the structure of the data will not change.

With GraphQL on the other hand, it’s not clear what a client will request next, so putting a caching layer right behind the API doesn’t make a lot of sense.

Server-side caching still is a challenge with GraphQL.

16) How do you prevent nested attack on GraphQL server?

About Author


After years of Technical Work, I feel like an expert when it comes to Develop wordpress website. Check out How to Create a Wordpress Website in 5 Mins, and Earn Money Online Follow me on Facebook for all the latest updates.