You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following resolver for my AppSync subscription:
from aws_lambda_powertools.event_handler.appsync import Router
from sdapi.utils import get_logger
from petstore.app.container import AppContainer
from petstore.graphql.pet.appsync.resolvers.queries.get_pet_by_id import (
get_pet_by_id,
)
logger = get_logger()
router = Router()
@router.resolver(type_name="Subscription", field_name="updatedPet")
def updated_pet(id: str):
logger.info("Handling update pet mutation")
app_container: AppContainer = router.context.get("app_container")
tenant_id = router.context.get("tenant_id")
pet_repository = app_container.pet_repository
return get_pet_by_id(pet_repository=pet_repository, tenant_id=tenant_id, pet_id=id)
The problem is, with how subscription works, that my payload request needs to match the database field name, therefore I cannot use pet_id for my subscription definition.
Hence I need to break the spec of my schema.graphql:
directive @aws_subscribe(mutations: [String!]!) on FIELD_DEFINITION
enum Category {
DOGS
CATS
BIRDS
FISHES
REPTILES
}
type Mutation {
"""Add a new pet to the store"""
addPet(pet: PetInput!): PetType!
"""Update pet"""
updatePet(pet_id: String!, pet: PetUpdateInput!): PetType!
}
input PetInput {
name: String!
category: Category!
status: Status!
photoUrls: [String!] = []
tags: [TagInput!] = []
}
input PetUpdateInput {
name: String
category: Category
status: Status
photoUrls: [String!] = []
tags: [TagInput!] = []
}
type PetType {
id: String!
type: String!
name: String!
category: Category!
status: Status!
photoUrls: [String!]
tags: [TagType!]!
}
type Query {
"""Get all pets for a tenant"""
getPets: [PetType!]!
"""Get a pet by its ID"""
getPet(pet_id: String!): PetType!
}
enum Status {
AVAILABLE
PENDING
SOLD
}
type Subscription {
"""Buy a pet"""
updatedPet(id: String!): PetType
@aws_subscribe(mutations: ["updatePet"])
}
input TagInput {
name: String!
}
type TagType {
type: String!
name: String!
}
As you can see above, I use pet_id for queries & mutations, but by the way of how subscriptions work, I'm forced to use id here, as this is the database field name of my Pet entity.
When using powertools, is there a way to map the request, so I can use pet_id instead of id in my resolver?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have the following resolver for my AppSync subscription:
The problem is, with how subscription works, that my payload request needs to match the database field name, therefore I cannot use pet_id for my subscription definition.
Hence I need to break the spec of my schema.graphql:
As you can see above, I use pet_id for queries & mutations, but by the way of how subscriptions work, I'm forced to use id here, as this is the database field name of my Pet entity.
When using powertools, is there a way to map the request, so I can use pet_id instead of id in my resolver?
Beta Was this translation helpful? Give feedback.
All reactions