I'm currently working on a greenfield project and finally got the chance to use AppSync. I have been playing around with the evaluate code from the SDK after reading the docs.
import { AppSyncClient, EvaluateCodeCommand, EvaluateCodeRequest } from '@aws-sdk/client-appsync'
import { describe, expect, test } from 'vitest'
import { bundleAppSyncResolver } from './bundler';
import * as path from 'path';
describe('createPost resolver', () => {
test('returns correct appsync request', async () => {
const client = new AppSyncClient({})
const ctx = {
arguments: {
post: {
title: "Hello World",
content: "This is my first post",
authorName: "John Doe",
}
},
}
const input: EvaluateCodeRequest = { // EvaluateCodeRequest
runtime: {
name: "APPSYNC_JS",
runtimeVersion: "1.0.0",
},
code: bundleAppSyncResolver(path.join(__dirname, 'createPost.ts')),
context: JSON.stringify(ctx),
function: "request",
};
const command = new EvaluateCodeCommand(input);
const response = await client.send(command);
const result = JSON.parse(response.evaluationResult!);
expect(result).toMatchSnapshot();
})
})
and I tried to write a evaluate test that uses snapshots. The thing is that util.autoKsuid() will autogenerate a new ID on every invocation. It would be a great addition to be able to mock functions like util.autoKsuid() or util.time to enable snapshot testing of requests
Hello
I'm currently working on a greenfield project and finally got the chance to use AppSync. I have been playing around with the evaluate code from the SDK after reading the docs.
I have been toying with the following example from https://blog.graphbolt.dev/improving-developer-experience-with-typescript-how-to-write-strongly-typed-appsync-resolvers
I have a resolver that looks like this:
with the following test:
and I tried to write a evaluate test that uses snapshots. The thing is that
util.autoKsuid()
will autogenerate a new ID on every invocation. It would be a great addition to be able to mock functions likeutil.autoKsuid()
orutil.time
to enable snapshot testing of requestsSnapshot: