Blog
  • AI Gateway
  • AI Security
  • AIOps
  • API Security
  • API Gateway
    • API Management
    • API Development
    • API Design
    • Automation
    • Service Mesh
    • Insomnia
  1. Home
  2. Blog
  3. Engineering
  4. How to Leverage Insomnia as a GraphQL Client
Engineering
August 24, 2021
6 min read

How to Leverage Insomnia as a GraphQL Client

Garen Torikian
Topics
GraphQLInsomniaAPI Development
Share on Social

More on this topic

eBooks

Maturity Model for API Management

eBooks

API Infrastructure: ESB versus API Gateway

See Kong in action

Accelerate deployments, reduce vulnerabilities, and gain real-time visibility. 

Get a Demo

Here at Kong, we're advocates for architecting your application as a group of microservices. In this design style, individual services are responsible for handling one aspect of your application, and they communicate with other services within your network to share data. Systems like Kubernetes or the Kuma service mesh help orchestrate traffic and manage network policies so that your microservices can function together as a unified whole.

Communication between microservices is done via an API, a pattern that you're probably familiar with. Your API can be of any protocol—whether that's REST, gRPC or GraphQL. What's important is that you have established a well-defined and consistent format for both your internal needs as well as your external ones.

To test your API (outside of a CI/CD framework), you'll need a client which can make requests to the API. That's why we have Insomnia, an open source client for interacting with APIs. This post and video will show off some of the highlights of using Insomnia as a GraphQL client. We'll build a tiny GraphQL server in Node.js, and then use Insomnia both to fetch and manipulate data on it.

Designing a GraphQL Schema

Before following this guide, be sure to have the latest version of Insomnia installed. You will also need the latest version of Node installed (at least version 12.0), as well as npm.

As with any API development process, we'll first need to identify the objects that are necessary for our app. GraphQL has a strongly typed schema defined in a schema definition language (SDL), an idempotent way to describe all the objects and fields available by your GraphQL API.

For our example, we'll create an API that stores and retrieves a list of users, along with their addresses. The beginning of our schema looks like this:

Create a file called schema.graphql, and paste the above lines into it.

To retrieve data from our schema, we need to define an entry point query. For example, our GraphQL query will look something like this:

In this case, we're grabbing a user based on its id, requesting the response to show us that user’s id, name and email.

Queries are also defined in the SDL; the query field belongs to a special reserved type called Query, the main entry point for fetching objects. Add this code to the bottom of your schema.graphql file:

We also want to add a method for updating information. In GraphQL, a query that changes data is called a mutation. For example, a mutation to add a user might look like this:

In SDL, you define the name of the mutation and all the fields that you could use as inputs. Add the following lines to your schema.graphql file:

For your reference, the final schema.graphql file is available as a gist.

Connecting the Resolvers

A schema defines the shape of the stored data and how to construct queries. However, establishing a schema to fit your data model is just one part of the GraphQL server. The other part interacts with data using resolvers. A resolver is just a function that returns the underlying value of a field.

Let’s take a quick look at how our Node server implements resolvers. The intent is to solidify concepts around how resolvers operate in conjunction with schemas, so we won’t go into too much detail around data stores setup.

In the "real world," we might be fetching data through the database. For now, let’s just set up some dummy data. Create a file called server.js and paste these lines into it:

The final version of server.js is available as a gist.

GraphQL resolvers amount to a JSON hash with the key as the name of the field to be retrieved and the value corresponding to a function that returns the data. Let’s start with a barebones example of the initial user lookup by id. Add the following code to the bottom of your server.js file:

This resolver takes two arguments: an object representing the parent (often unused in the initial root query) and a JSON object containing the arguments passed to your field. Not every field will have arguments. In this case, they will because we need to retrieve our user by their id.

Building the API Server

We’ll now use Express to set up a basic API server to provide users GraphQL access to our data. Let's use npm to install the packages our server needs:

Along with the users and resolvers we’ve already added, the rest of our server.js file stands up the server and connects the resolvers with the schema. Add the following code to the bottom of the file:

Run node server.js to boot up the server on port 5000. If you're the cautious type, you can issue a curl command right now to verify that data loads correctly:

The response should be data that corresponds to Francis!

Working With Insomnia GraphQL

Working with curl is acceptable, but it can be cumbersome and limiting. Let's take a look at what Insomnia GraphQL offers.

Basic GraphQL Queries and Mutations

From within the Insomnia dashboard, create a new collection for this project.

insomnia-dashboard

From your starting collection screen, click on New Request. Set the HTTP verb to POST and the body to GraphQL. You can also set a name if you desire (here, we chose "GraphQL Sample"). Then, click Create.

new-requests

Set the URL for your request to your server’s endpoint. Then, copy-paste the query we used earlier into the editor for the GraphQL request body:

Insomnia GraphQL Dashboard

Click on "Send." You'll get Francis' data back in an easy-to-read, color-coded format.

preview-header

Let's try making a mutation next. Paste the following lines into the request body:

In Insomnia, your request will look like this:

Insomnia GraphQL Post

Click on "Send." The result shows the newly added record.

200OK-preview

For an additional verification that the mutation went through, you can take the returned id (in this case, 3) and perform another getUser query.

Insomnia GraphQL Post

The result is our newly added user:

200OK-2.14

GraphQL Schema Introspection

You can also perform a schema introspection query with Insomnia to give insight into the GraphQL schema undergirding the server. For example, we can learn about the User object and its fields with the following query:

Insomnia GraphQL Post Auth200OK-1.99

In addition, Insomnia GraphQL can fetch the schema from the server, allowing you to "show documentation:"

graphql-schema

The result is an interactive listing where you can drill down through available queries and mutations, seeing object fields and inputs.

query-schema

Auto-Complete and Suggested Fields

After Insomnia has fetched a schema, future queries and mutations you write have the added help of auto-complete. Query names, required inputs and fields for retrieval are all made available as you type or by pressing cmd/ctrl + space bar.

post-query

Plugins for Dynamic Values

Insomnia also supports various plugins for more dynamic testing. For example, we hard-wired the name and email values in our mutation request above. With Insomnia’s faker plugin installed, we can modify our mutation to use a template tag and generate a fake (random) name and email with each request:

The response shows the randomly generated name and email or our new user:

200OK-17.7ms

Another useful method for on-the-fly values is using template tags with prompts:

query-variables

When sending the request, Insomnia will pop up a modal prompting you to enter the value(s) you want to use with your request:

name

Besides these useful plugins, even more power is available from Insomnia by way of its additional features, including:

  • The ability to inspect headers
  • A label indicating how long the entire request/response cycle took
  • A complete timeline representing the request data, and the server response
  • The ability to easily provide authentication credentials

These features make it easy to issue GraphQL queries and identify areas to improve your server performance.

Getting More Information on Insomnia GraphQL

Perhaps the greatest strength of Insomnia is the fact that it's completely open source! A large community of developers and backend engineers regularly use and contribute to the project. Insomnia also works for REST and gRPC APIs, providing the same measuring and reporting tools no matter how your server communicates.

If you'd like to learn more about designing microservices, we have a document that outlines some high-level best practices for developing API gateways. We also have a blog post on successfully implementing a GraphQL server within Kong itself.

If you have any questions, ask them in the Insomnia Community on Slack and GitHub.

Once you set up Insomnia as a GraphQL client, you may find these other tutorials helpful:

  • See what's new (and coming soon) with Insomnia
  • 6 Ways to Leverage Insomnia as a gRPC Client
  • 3 Solutions for Avoiding Plain-Text Passwords in Insomnia
  • Or try testing your Kong Gateway plugins in Insomnia with these tutorials: Key Auth, Rate Limiting, OAuth2 and JWT.

Topics
GraphQLInsomniaAPI Development
Share on Social
Garen Torikian

Recommended posts

Unlocking API Analytics for Product Managers

Kong Logo
EngineeringSeptember 9, 2025

Meet Emily. She’s an API product manager at ACME, Inc., an ecommerce company that runs on dozens of APIs. One morning, her team lead asks a simple question: “Who’s our top API consumer, and which of your APIs are causing the most issues right now?”

Christian Heidenreich

Level Up Your Digital Health Platform with Kong, SMART on FHIR, Okta

Kong Logo
EngineeringSeptember 2, 2025

The healthcare industry is buzzing about FHIR (Fast Healthcare Interoperability Resources). Pronounced “fire,” this widely adopted data standard has been revolutionizing how healthcare information is exchanged. But building a truly modern, secure, a

Biswa Mohanty

Guide to API Testing: Understanding the Basics

Kong Logo
EngineeringSeptember 1, 2025

Behind every smooth user experience is a maze of APIs quietly handling requests, responses, and data flows. This makes APIs critical connectors that enable applications to communicate and share data seamlessly. When these vital conduits fail, the

Adam Bauman

How to Build a Multi-LLM AI Agent with Kong AI Gateway and LangGraph

Kong Logo
EngineeringJuly 31, 2025

In the last two parts of this series, we discussed How to Strengthen a ReAct AI Agent with Kong AI Gateway and How to Build a Single-LLM AI Agent with Kong AI Gateway and LangGraph . In this third and final part, we're going to evolve the AI Agen

Claudio Acquaviva

How to Build a Single LLM AI Agent with Kong AI Gateway and LangGraph

Kong Logo
EngineeringJuly 24, 2025

In my previous post, we discussed how we can implement a basic AI Agent with Kong AI Gateway. In part two of this series, we're going to review LangGraph fundamentals, rewrite the AI Agent and explore how Kong AI Gateway can be used to protect an LLM

Claudio Acquaviva

How to Strengthen a ReAct AI Agent with Kong AI Gateway

Kong Logo
EngineeringJuly 15, 2025

This is part one of a series exploring how Kong AI Gateway can be used in an AI Agent development with LangGraph. The series comprises three parts: Basic ReAct AI Agent with Kong AI Gateway Single LLM ReAct AI Agent with Kong AI Gateway and LangGr

Claudio Acquaviva

Build Your Own Internal RAG Agent with Kong AI Gateway

Kong Logo
EngineeringJuly 9, 2025

What Is RAG, and Why Should You Use It? RAG (Retrieval-Augmented Generation) is not a new concept in AI, and unsurprisingly, when talking to companies, everyone seems to have their own interpretation of how to implement it. So, let’s start with a r

Antoine Jacquemin

Ready to see Kong in action?

Get a personalized walkthrough of Kong's platform tailored to your architecture, use cases, and scale requirements.

Get a Demo
Powering the API world

Increase developer productivity, security, and performance at scale with the unified platform for API management, AI gateways, service mesh, and ingress controller.

Sign up for Kong newsletter

Platform
Kong KonnectKong GatewayKong AI GatewayKong InsomniaDeveloper PortalGateway ManagerCloud GatewayGet a Demo
Explore More
Open Banking API SolutionsAPI Governance SolutionsIstio API Gateway IntegrationKubernetes API ManagementAPI Gateway: Build vs BuyKong vs PostmanKong vs MuleSoftKong vs Apigee
Documentation
Kong Konnect DocsKong Gateway DocsKong Mesh DocsKong AI GatewayKong Insomnia DocsKong Plugin Hub
Open Source
Kong GatewayKumaInsomniaKong Community
Company
About KongCustomersCareersPressEventsContactPricing
  • Terms•
  • Privacy•
  • Trust and Compliance•
  • © Kong Inc. 2025