Skip to content

Instantly share code, notes, and snippets.

@RWaltersMA
Created March 17, 2025 22:21
Show Gist options
  • Save RWaltersMA/e44813a89c748e175d6997f659162b33 to your computer and use it in GitHub Desktop.
Save RWaltersMA/e44813a89c748e175d6997f659162b33 to your computer and use it in GitHub Desktop.
Complete Apollo Connector code for AWS Lambda Connector tutorial blog
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.10"
import: ["@key"]
)
@link(
url: "https://specs.apollo.dev/connect/v0.1"
import: ["@source", "@connect"]
)
@source(
name: "lambda"
http: { baseURL: "https://lambda.us-east-1.amazonaws.com" }
)
type Product {
id: ID!
name: String
description: String
image: String
price: Price
@connect(
source: "lambda"
http: {
POST: "/2015-03-31/functions/product-price/invocations"
body: """
product_id: $this.id
"""
}
selection: """
amount: default_price
isActive: is_active
currency
recurringInterval: recurring.interval -> match(
[0,"ONE_TIME"],
[1,"DAILY"],
[2,"MONTHLY"],
[3,"ANNUALLY"],
)
recurringCount: recurring.interval_count
"""
)
}
type Price {
amount: Float
isActive: Boolean
currency: String
recurringInterval: RecurringInterval
recurringCount: Int
}
enum RecurringInterval {
ONE_TIME
DAILY
MONTHLY
ANNUALLY
}
type Query {
products: [Product]
# https://docs.aws.amazon.com/lambda/latest/api/API_Invoke.html
@connect(
source: "lambda"
http: { POST: "/2015-03-31/functions/products/invocations" }
selection: """
# JSON Example Response 👇
# https://github.com/apollographql/connectors-community/tree/main/connectors/aws/json-responses/products.json
$.body {
id
name
description
image
}
"""
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment