Open gxxcastillo opened 2 years ago
Hey @gxxcastillo :wave: thanks for raising this! I'm able to reproduce this by adding a custom resolver and query to my schema and attempt to call it during mock
type Query {
listSpecialTodos: [Todo]
}
import * as cdk from 'aws-cdk-lib'
import * as AmplifyHelpers from '@aws-amplify/cli-extensibility-helper'
import { AmplifyDependentResourcesAttributes } from '../../types/amplify-dependent-resources-ref'
import { Construct } from 'constructs'
import * as appsync from 'aws-cdk-lib/aws-appsync'
const queryListSpecialTodosReqVtl = `$util.error("It was called!!")`
export class cdkStack extends cdk.Stack {
constructor(
scope: Construct,
id: string,
props?: cdk.StackProps,
amplifyResourceProps?: AmplifyHelpers.AmplifyResourceProps
) {
super(scope, id, props)
/* Do not remove - Amplify CLI automatically injects the current deployment environment in this input parameter */
new cdk.CfnParameter(this, 'env', {
type: 'String',
description: 'Current Amplify CLI env name',
})
// Access other Amplify Resources
const retVal: AmplifyDependentResourcesAttributes =
AmplifyHelpers.addResourceDependency(
this,
amplifyResourceProps.category,
amplifyResourceProps.resourceName,
[
{
category: 'api',
resourceName: 'a12032',
},
]
)
const requestFunction = new appsync.CfnFunctionConfiguration(
this,
'function1',
{
apiId: cdk.Fn.ref(retVal.api.a12032.GraphQLAPIIdOutput),
dataSourceName: 'NONE_DS', // DataSource name
functionVersion: '2018-05-29',
name: 'function1',
requestMappingTemplate: queryListSpecialTodosReqVtl,
responseMappingTemplate: queryListSpecialTodosReqVtl,
}
)
const resolver = new appsync.CfnResolver(this, 'custom-resolver', {
// apiId: retVal.api.new.GraphQLAPIIdOutput,
// https://github.com/aws-amplify/amplify-cli/issues/9391#event-5843293887
// If you use Amplify you can access the parameter via Ref since it's a CDK parameter passed from the root stack.
// Previously the ApiId is the variable Name which is wrong , it should be variable value as below
apiId: cdk.Fn.ref(retVal.api.a12032.GraphQLAPIIdOutput),
fieldName: 'listSpecialTodos',
typeName: 'Query',
kind: 'PIPELINE',
pipelineConfig: {
functions: [requestFunction.attrFunctionId],
},
requestMappingTemplate: queryListSpecialTodosReqVtl,
responseMappingTemplate: queryListSpecialTodosReqVtl,
// requestMappingTemplate: requestVTL,
// responseMappingTemplate: responseVTL,
dataSourceName: 'TodoTable', // DataSource name
})
}
}
Marking as a bug
Before opening, please confirm:
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
v16.17.1
Amplify CLI Version
10.0.0
What operating system are you using?
M1 Mac w/ rosetta terminal
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
Amplify Categories
custom, api
Amplify Commands
add
Describe the bug
I've created a resolver for a custom query but it does not execute when using the mock api server. After doing a
amplify push
I've confirmed that the resolver does execute when I run my custom query on the AWS AppSync admin page.I am creating a custom resolver using
amplify add custom
as described in the amplify cli docs. I am using vtl files as apposed to inlining the resolvers and have confirmed that the contents of the vtl file hydrated into the cdk-stack.js file when I runamplify build
.This other issue seems related: https://github.com/aws-amplify/amplify-category-api/issues/113
Expected behavior
I would expect the resolver to execute when I run my custom query against the mock api server.
Reproduction steps
amplify int
->amplify add api
amplify add custom
to create custom resolver$util.error("It was called!!")
amplify mock api
If you do
amplify push
and test on the AppSync admin page it should work.GraphQL schema(s)
Log output
Additional information
No response