Note: If your question is regarding the AWS Amplify Console service, please log it in the
official AWS Amplify Console forum
Which Category is your question related to?
functions
api
Amplify CLI Version
You can use amplify -v to check the amplify cli version on your system
4.27.3
What AWS Services are you utilizing?
Lambda and AppSync
Provide additional details e.g. code snippets
I have created Lambda function with Go runtime. I have configured the GraphQL query to run this lambda function.
All I want to know, How lambda function written in Go, can read the payload when invoked from GraphQL query from frontend?
I cannot find any example anywhere?
Following are my code snippets to understand the scenario:
type Query {
getCustData(name: String, region: String): String
@function(name: "GetCustData-${env}")
}
In my Front-end tsx file.
const customer: any = await API.graphql(
graphqlOperation(getCustData, {
name: name,
region: region,
})
);
my Go function excepts:
type Request struct {
Name string `json:"name"`
Region string `json:"region"`
}
// HandleRequest function
//func HandleRequest(ctx context.Context, request Request) (Response, error) {
}
I want to read the payload sent by GraphQL in the Request? But I don't know, How?
I am new to Go as well.
When using @function directive, the resolver wraps all the arguments inside an event object which is documented here.
This code should provide you access to the arguments from the query getCustData
// Arguments Graphql Arguments
type Arguments struct {
Name string `json:"name"`
Region string `json:"region"`
}
// Event that is passed by the appsync
type Event struct {
TypeName string `json:"typeName"`
FieldName string `json:"fieldName"`
Arguments Arguments `json:"arguments"`
}
func handleRequest(ctx context.Context, ev Event) (string, error) {
return fmt.Sprintf("Name:%s\nRegion:%s!", ev.Arguments.Name ev.Arguments.Region), nil
}
I will give it a try.
@yuth That worked 馃憤 . Exactly What I needed.
However, I could not find it anywhere in the documentation.
Thank you.
However, I could not find it anywhere in the documentation.
We don't have anything language specific in the documentation, but the details about the event is listed here. The exact location is somewhere below as I can't hard link to it, I am attaching the scrrenshot
