All skills
apollographql avatar

/apollo-connectors

@55e7707 official
by Apollo GraphQLapollographql/skills115 stars
13

Guide for integrating REST APIs into GraphQL supergraphs using Apollo Connectors with @source and @connect directives. Use this skill when the user: (1) mentions "connectors", "Apollo Connectors", or "REST Connector", (2) wants to integrate a REST API into GraphQL, (3) references @source or @connect directives, (4) works with files containing "# Note to AI Friends: This is an Apollo Connectors schema".

Use this Skill: https://skilld.dev/gh/apollographql/skills/apollo-connectors

This session only. Nothing lands on disk.

referencesvariables.md

≈1.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Available Variables

You MUST NOT make up variable names - only use variables listed here.

Table of Contents

Variable Reference

Variable Description Availability
$ Root/parent reference selection, errors in @connect
$args Field arguments @connect when field has arguments
$batch Entity batch references @connect on types only
$config Router configuration Always available
$context Coprocessor context When customizations set context
$env Environment variables Always available
$request.headers Incoming request headers Always available
$response.headers Response headers selection, errors
$status HTTP response status code selection, errors in @connect
$this Parent object fields Non-root types only
@ Transformation context Within method arguments

$ - Root/Parent Reference

At the top level, $ refers to the API response body root. Within a sub-selection, $ refers to the parent value.

selection: """
# $ refers to response root
$.results {
  # Inside here, $ refers to each item in results
  id
  fullName: $.name.first
}
"""

Usage:

  • Top-level: Access response root
  • In sub-selection: Access current parent context
  • Only available in @connect's selection and errors

$args - Field Arguments

Access arguments passed to the GraphQL field.

type Query {
  user(id: ID!): User
    @connect(
      http: { GET: "/users/{$args.id}" }
      selection: "id name"
    )

  users(limit: Int, offset: Int): [User]
    @connect(
      http: {
        GET: "/users"
        queryParams: """
        limit: $args.limit
        offset: $args.offset
        """
      }
      selection: "id name"
    )
}

Usage:

  • In URL templates: "/path/{$args.id}"
  • In query params: limit: $args.limit
  • In body: "userId: $args.id"
  • Available when field has defined arguments

$batch - Entity Batching

Used to batch multiple entity resolution requests into a single API call.

type Product @connect(
  source: "api"
  http: {
    POST: "/products/batch"
    body: "ids: $batch.id"
  }
  selection: """
  id
  name
  price
  """
) {
  id: ID!
  name: String
  price: Float
}

Rules:

  • Only available on @connect attached to types
  • Fields referenced in $batch must be in the selection
  • API must support batch requests

See entities.md for detailed batching patterns.

$config - Router Configuration

Access values from router configuration file.

Router config (router.yaml):

connectors:
  sources:
    my_subgraph.my_api:
      $config:
        api_version: "v2"
        feature_flag: true

Schema usage:

@connect(
  http: { GET: "/api/{$config.api_version}/users" }
  selection: "id name"
)

Note: Prefer $env over $config when possible.

$context - Coprocessor Context

Access context set by router customizations like coprocessors.

@connect(
  http: {
    GET: "/users"
    headers: [
      { name: "X-Tenant", value: "{$context.tenantId}" }
    ]
  }
  selection: "id name"
)

Usage:

  • Only available when router customizations have set context
  • Typically used with coprocessors for multi-tenancy, auth, etc.

$env - Environment Variables

Access environment variables available to the router process.

@source(
  name: "api"
  http: {
    baseURL: "https://api.example.com"
    headers: [
      { name: "Authorization", value: "Bearer {$env.API_KEY}" }
    ]
  }
)

Common patterns:

# API keys
{ name: "X-API-Key", value: "{$env.API_KEY}" }

# Dynamic base URLs
baseURL: "{$env.API_BASE_URL}"

# Feature flags
# (use in combination with conditional logic)

Always available. Prefer this over hardcoding secrets.

$request.headers - Incoming Request Headers

Access headers from the client request to the router.

@connect(
  http: {
    GET: "/users"
    headers: [
      { name: "Authorization", value: "{$request.headers.authorization->first}" }
    ]
  }
  selection: "id name"
)

Important:

  • Headers are always arrays (can have multiple values)
  • Use ->first to get the first value
  • Use quoted syntax for headers with special characters: $request.headers.'x-my-header'->first

$response.headers - Response Headers

Access headers from the connector's HTTP response.

@connect(
  http: { GET: "/users" }
  selection: """
  id
  name
  rateLimit: $response.headers.'x-rate-limit'->first->parseInt
  """
)

Usage:

  • Available in selection and errors
  • Headers are arrays - use ->first
  • Useful for pagination cursors, rate limits, etc.

$status - HTTP Status Code

Access the numeric HTTP status code from the response.

@connect(
  http: { DELETE: "/users/{$args.id}" }
  selection: """
  success: $(true)
  """
  errors: {
    message: "$status->match([404, 'Not found'], [@, 'Error'])"
  }
)

Usage:

  • Available in selection and errors of @connect
  • Returns numeric code (200, 404, 500, etc.)
  • Useful for error handling and conditional responses

$this - Parent Object Fields

Access sibling fields from the parent object. Used for field-level connectors that need parent data.

type User {
  id: ID!
  name: String
  posts: [Post] @connect(
    http: { GET: "/users/{$this.id}/posts" }
    selection: "id title"
  )
}

Usage:

  • Only available on non-root types (not Query/Mutation)
  • Access sibling fields that have been resolved
  • Creates dependencies between fields

Example with nested access:

type Order {
  id: ID!
  customerId: ID!
  customer: Customer @connect(
    http: { GET: "/customers/{$this.customerId}" }
    selection: "id name email"
  )
}

@ - Transformation Context

The current value being transformed within a method. Changes meaning based on context.

selection: """
# In filter: @ is each array item
activeUsers: $.users->filter(@.isActive)

# In map: @ is each item being transformed
names: $.users->map(@.name)

# In echo: @ is the input value
wrapped: $.data->echo({ value: @ })

# Nested: @ refers to innermost context
items: $.list->map({ doubled: @->mul(2) })
"""

Context changes:

  • filter(@.field) - @ is each item being tested
  • map(@.field) - @ is each item being transformed
  • echo({ a: @ }) - @ is the input to echo
  • match([cond, @]) - @ is the original value

Source: SKILL.md on GitHub

1 warning6d5 checks · Risk SAFE
  • Gen Agent Trust Hub6d

    The skill is a comprehensive documentation and assistance tool for Apollo Connectors. It adheres to security best practices by using environment variables for secret management, restricted command execution via the rover CLI, and fetching resources from official vendor domains.

  • Socket6d

    No alerts

  • Snyk6d

    Risk: LOW · No issues

  • Runlayer7mo

    7/7 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 55e7707. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last week
What it can do
Runs commands
metadata
{
  "author": "apollographql",
  "version": "1.0.1"
}
All 1 allowed tools
Bash(rover:*) Read Write Edit Glob Grep
Other metadata
compatibility
Requires rover CLI installed. Works with Claude Code and similar AI coding assistants.
  • graphql
  • apollo
  • rest-api
  • connectors
  • federation
  • schema
  • integration

README badge

README badge for apollographql/skills/apollo-connectors

Integrates REST APIs into GraphQL supergraphs using Apollo Connectors with @source and @connect directives. Targets the rover CLI workflow and follows a five-step process: research the API, implement the schema, validate with rover compose, execute with rover connector run, and test coverage.

Generated from the current SKILL.md.

What versions of Apollo federation and connectors does this skill support?
The skill uses federation v2.12 and connect v0.3 by default unless you specify otherwise.
Do I need rover CLI installed to use this skill?
Yes. The skill requires rover CLI installed and uses commands like `rover supergraph compose`, `rover connector run`, and `rover connector test`.
Can this skill integrate any REST API into GraphQL?
Yes. The skill handles REST API integration using @source and @connect directives, supporting GET/POST requests, headers, batching, and response field mapping.
Does this skill handle entity relationships and N+1 query patterns?
Yes. The skill creates entity relationships when ID fields are present and converts N+1 patterns using batching with the $batch variable.
What happens if composition or connector execution fails?
The skill follows a 5-step validation process that runs `rover supergraph compose` after schema changes and `rover connector run` before testing, catching errors before they reach production.

Generated from the current SKILL.md. These answers refresh after source changes.