Top GraphQL Interview Questions (2020) | CodeUsingJava








Top GraphQL Interview Questions

In this post we will look at GraphQL Interview questions. Examples are provided with explanation.
GraphQL Interview Questions

What is meant by GraphQL?

  • GraphQL is a query language for your API, and a server-side runtime for executing queries by using a type system you define for your data. GraphQL isn't tied to any specific database or storage engine and is instead backed by your existing code and data.
  • GraphQL is an open source server-side technology which was developed by Facebook to optimize RESTful API calls. It is an execution engine and a data query language. In this chapter, we discuss about the advantages of using GraphQL..

What are the features of GraphQL?

  • Increased mobile usage created a need for more efficient data loading. A variety of different clients: REST makes it difficult to build an API that satisfies their needs, as it returns a fixed data structure. Expectations for faster feature development: To make a change on the client side in REST, often we have to adjust the server side to support it, which slows product iterations.
  • Good fit for complex systems and microservices. Fetching data with a single API call. No over- and under-fetching problems. Tailoring requests to your needs. Validation and type checking out-of-the-box. Autogenerating API documentation. API evolution without versioning. Code-sharing.

What is a Resolver in GraphQL?

Resolver is a collection of functions that generate response for a GraphQL query.
In simple terms, a resolver acts as a GraphQL query handler.
greeting:() => {
   return "hello from  CodeUsingJava !!!"
}

books:() => db.books.list()

bookIdById:(root,args,context,info) => {
   return db.books.get(args.id);
}

List the key concepts of the GraphQL query language?

Key concepts of the GraphQL query language are:
  • Hierarchical
  • Product-centric
  • Strong-typing
  • Client-specified queries
  • Introspective

Explain the main difference between REST and GraphQL?

  • REST - REST (Representational State Transfer) is an API design architecture used to implement web services. REST-compliant web services allow the requesting systems to access and manipulate textual representations of web resources by using a uniform and predefined set of stateless operations. When HTTP is used, the most common operations available are GET, POST, PUT, and DELETE.
    The core concept of REST is that everything is a resource.
  • GraphQL - GraphQL is an API design architecture, but with a different approach which is much flexible. The main and most important difference is that GraphQL is does not involve interaction with dedicated resources. In GraphQL everything is considered a graph and so everything is connected. This means that we can modify the request query to what we want using GraphQL query language.

What is Mutation in GraphQL?

Mutation queries modify data in the data store and returns a value and it can be used to insert, update, or delete data.
Mutations are defined as a part of the schema.
{
   someInsertOperation(dataField:"valueOfField"):returnType
}