- Newest
- Most votes
- Most comments
To create an AppSync resolver using the AWS SDK for JavaScript v3 programmatically, you're on the right track with your function. However, there are a few things to consider that might be causing the Bad Request (400) error:
-
Make sure all required parameters are provided. For a UNIT resolver, you need apiId, typeName, fieldName, and at least one of dataSourceName, requestMappingTemplate, or code.
-
The 'code' parameter should contain the resolver code that includes both request and response functions. This is required when using the APPSYNC_JS runtime.
-
Ensure the 'code' string is properly formatted and contains valid JavaScript for the APPSYNC_JS runtime.
-
The 'typeName' should match a type in your GraphQL schema. In your case, you're using 'Mutation', which is correct if you're creating a mutation resolver.
-
The 'fieldName' should match a field in your GraphQL schema. Your dynamic field name (
create${type}) should correspond to an actual field in your schema. -
Verify that the 'dataSourceName' exists in your AppSync API.
-
Double-check that the 'apiId' is correct and that you have the necessary permissions to create resolvers in that API.
Here's a slightly modified version of your function that might help:
async createCreateResolver({ apiId, dataSourceName, type, code }) { const params = { apiId, typeName: 'Mutation', fieldName: `create${type}`, dataSourceName, kind: 'UNIT', runtime: { name: 'APPSYNC_JS', runtimeVersion: '1.0.0' }, code } console.log('CreateResolver params:', JSON.stringify(params, null, 2)); const command = new CreateResolverCommand(params); try { return await this.appSyncClient.send(command); } catch (error) { console.error('Error creating resolver:', error); throw error; } }
This version includes more detailed logging and error handling, which might help you identify the specific issue. If you're still encountering problems, you may want to check the AWS CloudWatch logs for more detailed error messages.
Remember to ensure that your 'code' parameter contains valid resolver code for both request and response handling in the APPSYNC_JS runtime format.
Sources
CreateResolver - AWS AppSync
AWS AppSync JavaScript resolver function reference for HTTP - AWS AppSync
Resolver - AWS AppSync
Relevant content
asked 3 years ago
asked 3 years ago
- AWS OFFICIALUpdated 4 years ago
