GraphQL HTTP Transformer

5.2.80 · active · verified Wed Apr 22

graphql-http-transformer is an AWS Amplify component, specifically an AppSync model transform that facilitates the integration of GraphQL APIs with external HTTP/REST endpoints. It processes the `@http` GraphQL directive within a schema, automatically generating AWS AppSync HTTP data sources and VTL (Velocity Template Language) resolvers. This allows developers to seamlessly proxy GraphQL operations to existing external services without writing custom VTL or AWS CloudFormation. The package is currently at version `5.2.80` and is part of the larger `@aws-amplify/amplify-category-api` monorepo, indicating an active development lifecycle with releases tied to the broader Amplify ecosystem updates. Its key differentiators include deep integration with the Amplify CLI/CDK for streamlined deployment, automatic resource provisioning, and support for dynamic URL construction, enabling a declarative approach to connecting AppSync to diverse backend services.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates defining a GraphQL schema with the `@http` directive for an AWS Amplify project, outlining how it generates AppSync HTTP resolvers for external API integration.

/* src/schema.graphql */
# This file defines your GraphQL API schema with the @http directive.
# The graphql-http-transformer processes this directive when you use the Amplify CLI
# to provision AWS AppSync HTTP Data Sources and Resolvers automatically.

type Query {
  # Defines a GraphQL query 'getPost' that fetches data from an external HTTP API.
  # The @http directive configures the AppSync resolver to make a GET request.
  # The 'url' argument dynamically constructs the URL using the '$id' argument.
  getPost(id: ID!): Post @http(method: GET, url: "https://jsonplaceholder.typicode.com/posts/${id}")

  # Example of a mutation using a POST request to an external API.
  createTodo(input: CreateTodoInput!): Todo @http(method: POST, url: "https://api.example.com/todos")
}

type Post {
  id: ID!
  title: String
  body: String
  userId: ID
}

input CreateTodoInput {
  title: String!
  description: String
  completed: Boolean = false
}

type Todo {
  id: ID!
  title: String!
  description: String
  completed: Boolean
}

# To deploy this schema with AWS Amplify, you would typically use the Amplify CLI:
# 1. Initialize an Amplify project: `amplify init`
# 2. Add an API: `amplify add api` (choose GraphQL, then select 'Single object with fields (e.g., "Todo")' or 'Blank schema' and paste the above content)
# 3. Push changes to the cloud: `amplify push`
# The CLI will detect the @http directive, apply the transformer, and provision
# the necessary AWS resources (AppSync API, HTTP Data Sources, Resolvers).

view raw JSON →