mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
* feat(appsync): execute APPSYNC_JS resolvers via a Node sidecar A field with a resolver resolved to null: no data fetchers were registered, so graphql-java fell through to its property fetcher on an empty root. This runs the resolver instead, for UNIT and PIPELINE alike, over NONE, AWS_LAMBDA, RELATIONAL_DATABASE and AMAZON_DYNAMODB data sources. Resolver JavaScript runs in a Node sidecar container rather than in process. Floci's published image is a Mandrel native executable, which carries no Truffle languages, so there is no in-process JavaScript to embed; running real Node also means a bundle executes as written, ES modules and all. @aws-appsync/utils is a shim the sidecar writes at boot rather than the published package, so a resolver call never depends on npm being reachable. The pipeline follows AppSync's: ctx.stash threads through every stage, each stage sees the last as ctx.prev.result, runtime.earlyReturn stops everything, util.error fails the field with the type the resolver chose, and util.appendError returns its errors beside the data. A data source failure does not fail the field on its own: the stage's response() handler is called with ctx.error set and decides whether to re-raise or suppress, which is why resolvers carry an explicit if (ctx.error) branch. VTL mapping templates are not executed. A VTL stage fails its field saying so rather than resolving to null, since a null that means "not implemented" is indistinguishable from a null that means "no rows". Carries model/FunctionConfiguration and AppSyncService so it builds and tests standalone; both are identical to the copies in the AppSync CloudFormation change and collapse on merge. * feat(appsync): enforce the APPSYNC_JS subset before evaluating resolver code The sidecar is real Node, so it accepted JavaScript AWS rejects: async functions, promises, classes, try/catch, while loops, this, and imports of Node builtins. For an emulator that is the worst failure available, since a local run green-lights resolver code that cannot deploy. Imports are restricted by a module resolve hook rather than a source scan, so a dynamic import of a builtin cannot slip past either. An async handler is caught before it runs and a handler returning a promise after. The remaining constructs are found by scanning the source with comments, strings and template text blanked first, so the same keywords inside them are not flagged. A rejected resolver fails its field with errorType UnsupportedFeature and the line. Enforcement is on by default and can be turned off with floci.services.appsync.js-runtime.enforce-appsync-subset, which exists only so a false positive cannot block someone whose code AWS does accept. Checking real resolvers against it found a gap of the same kind in the other direction: @aws-appsync/utils/dynamodb is a real module the shim did not provide, so valid code was being rejected. It now implements get, put and remove; the helpers that compile a condition or update expression throw by name rather than returning something the data source would mishandle. Also from review: cap the /evaluate request body, keep integer precision in the DynamoDB NS branch as the N branch already did, reject two SQL parameters bound to the same name instead of letting the Data API report it, drop the container id and close the log follower in reset(), and bound the docker probe in the integration test so an unresponsive daemon cannot hang CI. * feat(appsync): add the js-runtime url knob and stop the sidecar through ContainerTeardown Follows the sidecar contract the other managed containers use. floci.services.appsync. js-runtime.url points the runtime at a Node server that is already running, in which case ensureStarted skips container management entirely: nothing is created, adopted or stopped, and the URL is probed with the short adopt budget so a wrong one says so instead of holding the first resolver for the full start timeout. Same shape and meaning as floci.services.duck.url. NodeAppSyncJsRuntime now implements ContainerTeardown, so EmulatorLifecycle stops the sidecar with the other process-bound containers at a deterministic point rather than only through @PreDestroy, which the interface documents as running too late for the final storage flush. Teardown is a no-op for a pre-configured URL, since that server is not ours to stop. * fix(appsync): serialize reset() and stop the sidecar it gives up on reset() touched started, baseUrl, containerId and logStream without holding the monitor that ensureStarted() and stopManagedContainers() both take. A failed evaluation could therefore clear those fields in the window after a container had been created and its id recorded but before started was set, dropping the only handle to a live container: teardown then saw a null id, treated the sidecar as never started, and the container was leaked rather than stopped. reset() is now synchronized on the same monitor, and reentrant so the callers already holding it are unaffected. The failure path in post() goes through discardSidecar(), which stops and removes the container before clearing the fields instead of forgetting it, since forgetting is what leaks: nothing else holds the id. A pre-configured url owns no container, so teardown there stays a no-op. The regression races eight failing evaluations against startup and asserts every container the runtime created was also stopped. It needs a transport-level failure to reach the path: a 500 is rethrown as an AwsException before it, so the stub drops the connection instead. Against the previous reset() it fails with expected <[container-1]> but was <[]>. * refactor(appsync): run resolvers through the GraphQL sidecar callback out of Floci, which left this branch building DataFetchers for a schema that no longer has any. Resolver execution moves onto the sidecar's batched resolver callback instead, so the engine stays in the sidecar and the resolvers, the data sources and the Node runtime stay here. /v1/execute now carries a resolve block naming every planned coordinate that has a resolver, with a callback URL and a token minted for that one operation. The sidecar batches each execution level into one POST /appsync-resolve, which runs the field's resolver and answers with a value or an error. denyFields still win, so a denied coordinate is never listed and never reaches a resolver, and the token stops working as soon as the operation returns. AppSyncResolverExecutor takes a ResolverInvocation record instead of a DataFetchingEnvironment. Every value it read off the environment is on the record, so the pipeline, the data source invokers and the JS runtime are unchanged. ResolverDataFetcher is gone: fields with no resolver are the sidecar's own property fetcher again, and a resolver that disappears mid-operation falls back to the source property rather than failing. One AppSync behaviour does not fit the callback response, which carries a value or an error per field and never both. util.appendError means report this and keep the data, so those errors come back on the operation's session and are merged into the response envelope, which keeps data and appended errors together as AppSync returns them. Also gives the sidecar container host.docker.internal on Linux, since it now has to reach Floci back, moves the JS runtime image pin into application.yml so CI prefetches it the way it does the sidecar pins, and puts the Docker integration test on the shared AppSyncGraphqlSidecarProfile so it is namespaced and gated like the other AppSync integration tests. * ci(appsync): prefetch the Node image only on the shard that starts it The js-runtime prefetch matched /appsync/, so all four shards pulled node:22-alpine although only the shard carrying AppSyncJsResolverDockerIntegrationTest starts that container. Every other test in the package is a unit test. Matching the class name instead is three fewer Docker Hub pulls per run, which is what this script exists to avoid. * fix(appsync): keep null arguments and move the resolver callback under _floci Two review points from #3422. ResolverInvocation copied arguments and variables with Map.copyOf, which rejects a null value, so getMessages(nextToken: null) threw out of the callback and answered 500. That failed every field in the batch, not only the field carrying the null. Both copies are now null tolerant, and an explicit null stays distinguishable from an absent argument: it is present in ctx.args and null, where an absent one is not there at all. The callback moves from /appsync-resolve to /_floci/appsync/resolve, with the EKS webhooks. A bare path is reachable as a path-style S3 request for a bucket of that name, and an S3 bucket name cannot begin with an underscore, so the prefix cannot be shadowed. The null case is covered both ways: a unit test in ResolverCallbackResourceTest that fails with a NullPointerException against the previous code, and three queries in the Docker round trip covering an explicit null, its value reaching ctx.args, and an absent argument for contrast.