Skip to content

Conversation

@iverc
Copy link
Contributor

@iverc iverc commented Jul 4, 2025

Relevant issue(s)

Resolves #3812

Description

This PR adds WASM support to the playground. Now there are two modes: wasm (runs in browser) and remote (connects to DefraDB node).

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

Tested in browser with common queries like addSchema, patchSchema, addView, and execRequest.

Specify the platform(s) on which this was tested:

  • MacOS / Chrome browser

@iverc iverc requested a review from a team July 4, 2025 00:41
@iverc iverc self-assigned this Jul 4, 2025
@iverc iverc added feature New feature or request platforms Related to platform deployment labels Jul 4, 2025
@codecov
Copy link

codecov bot commented Jul 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.27%. Comparing base (46d0870) to head (b907793).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3813      +/-   ##
===========================================
- Coverage    76.36%   76.27%   -0.09%     
===========================================
  Files          425      425              
  Lines        39301    39301              
===========================================
- Hits         30012    29976      -36     
- Misses        7375     7399      +24     
- Partials      1914     1926      +12     
Flag Coverage Δ
all-tests 76.27% <ø> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 17 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46d0870...b907793. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bringing in this feature to the playground Ivan! I have a couple todos that I would like to resolve before approval.

if (initRef.current) {
return;
}
// @ts-expect-error - window.defradb is set in main_js.go.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Please add the full path to remove potential confusion cmd/defradb/main_js.go

Comment on lines 57 to 60
const query = graphQLParams.query || '';
const variables = graphQLParams.variables || {};
// All operations go through execRequest.
const result = await client.execRequest(query, JSON.stringify(variables));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: The execRequest method expects the query and a set of arguments. So not a stringified object. The request can also handle operationName. In its current form, passing in variables doesn't work. This is how I got it to work properly:

const query = graphQLParams.query || '';
const variables = graphQLParams.variables || {};
const operationName = graphQLParams.operationName || {};
const args = {
    operationName,
    variables,
};
// All operations go through execRequest.
const result = await client.execRequest(query, args);

Feel free to modify this if you prefer an different format.

cd playground
npm install
npm run dev:wasm
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: Please add information about the fact that the client is available in the console through the window.defradbClient object.

@iverc iverc requested a review from fredcarle July 4, 2025 13:20
Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for making the changes.

const args = {
operationName,
variables,
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: The indentation seems off here.

@iverc iverc merged commit ba43d5b into develop Jul 4, 2025
73 of 77 checks passed
@iverc iverc deleted the iverc/playground-wasm branch July 4, 2025 17:56
@fredcarle fredcarle added this to the DefraDB v0.19 milestone Aug 5, 2025
@AndrewSisley
Copy link
Contributor

AndrewSisley commented Aug 5, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request platforms Related to platform deployment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add WASM support for Playground

3 participants