Prompt

How do I generate a GraphQL API from existing REST APIs?

Technology / Developer Tools2 observationsLast seen Aug 27, 2026

Latest observation

Aug 27, 2026OpenAI APIWeb search: off

You generally do this by building a GraphQL layer (gateway/facade) on top of your existing REST endpoints, rather than “converting” REST into GraphQL automatically.

Common approaches

1. Write a GraphQL server that wraps REST

Create GraphQL types, queries, and mutations, then implement resolvers that call your REST APIs.

Example flow:

  • GraphQL query: user(id: "1")
  • Resolver calls: GET /users/1
  • Resolver maps REST response into GraphQL schema

This is the most flexible and common approach.


2. Use API composition / GraphQL gateway

If you have multiple REST services, place a single GraphQL gateway in front of them.

Benefits:

  • One GraphQL endpoint for clients
  • Aggregates data from multiple REST APIs
  • Hides backend complexity
  • Allows client-specific shaping of data

3. Use code generation / scaffolding tools

Some tools help you bootstrap GraphQL from REST/OpenAPI specs, then you customize the parts that need business logic.

Helpful if your REST APIs already have:

  • OpenAPI/Swagger definitions
  • Consistent resource models
  • Stable endpoints

Examples of useful tools/approaches:

  • GraphQL Mesh: can wrap REST/OpenAPI and expose GraphQL quickly
  • Apollo Server + custom resolvers
  • Hasura / PostGraphile are more for databases, not REST
  • Hot Chocolate (C#) / Spring for GraphQL (Java) if you want to build a gateway in those ecosystems

Typical architecture

  1. Define GraphQL schema

    • Types: User, Order, Product
    • Queries: user, orders, product
    • Mutations: createOrder, updateUser
  2. Implement resolvers

    • Each resolver calls one or more REST endpoints
    • Map REST fields to GraphQL fields
  3. Handle performance

    • Use batching/caching to avoid N+1 REST calls
    • Consider DataLoader or request-level caching
  4. Add auth and error handling

    • Forward tokens to REST services
    • Translate REST errors into GraphQL-friendly errors
  5. Expose a single GraphQL endpoint

    • Clients use GraphQL
    • REST stays behind the scenes

Simple example

GraphQL schema

type User {
  id: ID!
  name: String!
  email: String
}

type Query {
  user(id: ID!): User
}

Resolver

const resolvers = {
  Query: {
    user: async (_, { id }, { restClient }) => {
      const res = await restClient.get(`/users/${id}`);
      return res.data;
    }
  }
};

Things to watch out for

  • N+1 problem: GraphQL can trigger many REST calls if nested fields are resolved independently
  • Over-fetching/under-fetching: GraphQL helps clients, but your resolvers still need efficient backend calls
  • Schema design: Don’t mirror REST 1:1 blindly; model the API around client needs
  • Pagination: Standardize how REST pagination maps to GraphQL connections or lists
  • Versioning: GraphQL usually evolves by adding fields instead of versioning endpoints

If you want the fastest path

If you already have OpenAPI/Swagger specs, try GraphQL Mesh first. It can often generate a GraphQL layer over REST APIs with minimal code.


If you want, I can show you:

  1. a Node.js/Apollo example,
  2. a GraphQL Mesh setup, or
  3. how to do this from an OpenAPI spec.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.