-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can I use the generated GraphQL queries in my Lambda functions? #474
Comments
Just wanted to make sure you are reference the right docs |
I'd not seen that documentation before, you guys have so much of it in so many places! That seems to be doing roughly what I'm doing now. Only difference is I'm using Axios as my http client which is similar to https://docs.amplify.aws/guides/functions/graphql-from-lambda/q/platform/js#query listed above the section you linked to. Here is my code:
Then I've my queries in another file (called queries.js) like so:
I've added the above to the Lambda Layer that my functions use as I'm requiring stuff that I don't think is available by default within a Lambda environment. Is the example you linked too using a Layer or are all those requires available out of the box for a Lambda I wonder? That might clean up my code a bit if that is the case. Back to my original query though, I wondered if I could/should reuse the auto-generated mutations from Amplify within my Lambda and if so how to get them in there? So the issues isn't how to use GraphQL within a Lambda but more how to use my auto-generated queries/mutations from Amplify within a Lambda? The above works but having my creation mutations duplicated in several spots (and having to hand roll them) makes me feel funny :) |
@PeteDuncanson Yeah, right now we don't autogenerate/codegen the mutations/queries to a specific lambda function and you'd have to manually copy the auto-generated mutations/queries to the Lambda functon directory. I'll mark this as an enhancement for our team to look at. |
aws-amplify/amplify-cli#5598 specifies this use case and potential feature request |
I had this same issue, and got round it by having a
and added it into the scripts section of package.json:
This compiles/generates the GraphQL and copies the The only downside of this is that the queries will be returning all fields, where I may only need say |
I attempted the same using babel, but was unsuccessful. We're using javascript, not ts, so the build compilation is not necessary.
Thanks for the inspiration. |
This feature should be supported once we implement the plugins based architecture, where you can specify multiple docs generation tasks where each of them writes to a different directory. Link to RFC: aws-amplify/amplify-cli#6898 |
Transferring to codegen for better assistance |
This would be really helpful. I don't suppose there's been any implementation? |
It's been over three. years. |
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.
The text was updated successfully, but these errors were encountered: