aws-amplify / aws-amplify/amplify-codegen

Can I use the generated GraphQL queries in my Lambda functions?

Open
#474 11 comments 4 reactions 0 assignees View on GitHub
feature-request
Dominant language
TypeScript
Stars
59
Forks
64
PR merge metrics
No merged PRs in 30d

Description

I want to keep everything DRY as I can so would like my Lambda functions to be able to reuse my GraphQL queries. Trouble is I'm not sure how to do that!

I think that my functions when I add them are just uploaded separately in isolation of the rest of my code when I do a `amplify push`, by that I mean if I change my schema and regenerate everything I don't expect that to get pushed up to my functions but I could be wrong.

I'm currently using a Lambda Layer for shared code so I thought I would be the right place to put my queries but how to get them in there? Copy them to the \amplify\backend\function\myAmazingLayer\opt\ folder of my Layer? Could hook up a build step for that I guess?

It could be I've got work to do and I'm just missing the right imports or even to know which imports to use and their path. Or none of this is automagically available and I have to manually include it in my Layer somehow?

Again gaps in knowledge are telling here as I can't seem to find any information on how to do this. There is stuff out there on how to talk to DynamoDB direct (https://dev.to/dabit3/lambda-function-graphql-resolvers-11cd) in a Lambda but I'd rather go through my GraphQL API I think as I've been bitten before when I've pushed strings of data in to Dynamo directly for it to then blow up one of my AWS GraphQL types when I try to pull it back out via the GraphQL API. As a result I'd like everything to go through the "front door" of my GraphQL API. This doc (https://docs.amplify.aws/lib/graphqlapi/query-data/q/platform/js) covers how to talk to GraphQL in my front-end client code but I'd like to use this in my Lambda too...ideas?

Please can someone enlighten me.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.