Skip to content

Commit d3df136

Browse files
authored
Merge pull request #339 from oslabs-beta/master
Official Swell-1.15.0
2 parents 0ac050b + b9bbbbc commit d3df136

37 files changed

+1170
-533
lines changed

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ Swell is a one-stop shop for sending and monitoring your API requests:
4545
<!-- -TODO --- This needs to be updated -->
4646
<img src="./ReadMeGifs/Gifs/gRPC.gif" style="display: block; margin: 10px auto 30px;" />
4747

48+
- _tRPC_: Swell includes full support for all methods of TypeScript Remote Procedure Calls including batch call support for queries and mutations as well as subscription
49+
<img src="./ReadMeGifs/Gifs/trpc.gif" style="display: block; margin: 10px auto 30px;" />
50+
<!-- <img src="./ReadMeGifs/Gifs/tRPC-subscription.gif" style="display: block; margin: 10px auto 30px;" /> -->
51+
52+
Calls are currently being made using by using http get and post request using TRPC's http RPC specification (See [RPC docs](https://trpc.io/docs/rpc)). TLDR- inputs for query procedures will be turn into uri-encoded json string and send as query param while inputs for mutate procedures will be store inside of the body.
53+
54+
Batch requests can be made by adding multiple procedures before sending out the request, all query procedures will get batch together into one singular get request and all mutate procedures will get batch together into one singular put request, if there are mixture of query and mutate procedures call in one request, the app will send out both a post and get request concurrently and combine the response into one response.
55+
56+
Nested endpoint must follow the general format parentEndpoint.childEndpoint.grandchildEndpoint. For example:
57+
58+
```js
59+
client.user.update.mutate({ userId: '1', name: 'Luke' });
60+
```
61+
62+
A request to the above endpoint must have the mutate option selected from the drop down menu, must have an endpoint of .user.update and a input body of {"userId": "1","name": "Luke"}
63+
64+
See [tRPC docs](https://trpc.io/docs/) for more information on sending tRPC requests or setting up a tRPC server.
65+
4866
## Additional features
4967

5068
- _Stress testing for HTTP/2 and GraphQL_: Test your server backend with Swell's stress testing feature to ensure your server can manage expected and unexpected loads accordingly
@@ -70,20 +88,6 @@ Swell is a one-stop shop for sending and monitoring your API requests:
7088
- _Mock Server_: Swell allows you to create your own HTTP/2 mock server to facilitate front-end development without depending on a fully built backend server.
7189
<img src="./ReadMeGifs/Gifs/MockServer.gif" style="display: block; margin: 10px auto 30px;" />
7290

73-
- _tRPC_: Swell includes full support for all methods of TypeScript Remote Procedure Calls including batch call support for queries and mutations.
74-
<img src="./ReadMeGifs/Gifs/tRPC.gif" style="display: block; margin: 10px auto 30px;" />
75-
<!-- <img src="./ReadMeGifs/Gifs/tRPC-subscription.gif" style="display: block; margin: 10px auto 30px;" /> -->
76-
77-
Calls are currently being made using Swell's own TRPCProxyClient generated from the URL provided by the user.
78-
Batch requests must be entered one request per line. Swell will treat each line of code entered into the editor as a separate request before batching and returning responses.
79-
Each request must follow the general format client.procedure.querytype(). For example:
80-
81-
```js
82-
client.getUser.query({ name: 'Luke Skywalker' });
83-
```
84-
85-
See [tRPC docs](https://trpc.io/docs/) for more information on sending tRPC requests or setting up a tRPC server.
86-
8791
- _Webhooks_: Swell includes user-defined HTTP callback connection testing designed to test other server's connection to the web and ability to send data. The test insures that when an event occurs, the source site makes an HTTP request to the URL configured for the webhook.
8892
<img src="./ReadMeGifs/Gifs/Webhook.gif" style="float: left; margin-right: 10px;margin-bottom : 30px; margin-top : 10px;" />
8993

ReadMeGifs/Gifs/tRPC.gif

-1.21 MB
Binary file not shown.

ReadMeGifs/Gifs/trpc.gif

4.01 MB
Loading
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import React, { useState } from 'react';
22
import { useSelector, useDispatch } from 'react-redux';
3-
import { RootState } from '../../../toolkit-refactor/store';
4-
import TextCodeArea from '../sharedComponents/TextCodeArea';
3+
import { RootState } from './src/client/toolkit-refactor/store';
4+
import TextCodeArea from './src/client/components/main/sharedComponents/TextCodeArea';
55

66
/**
77
* renders entry form for TRPC request
88
*/
99

10-
1110
const TRPCBodyEntryForm = (props: any) => {
1211
const { newRequestBodySet } = props;
1312
const dispatch = useDispatch();

docs/DEV-README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ From a functionality standpoint:
6666
- Consistent UI/UX styling and color palette
6767
- Make requests via HTTP/2
6868
- Query, Mutation, Subscribe/unsubscribe to GraphQL endpoints
69+
- Query, Mutation, Subscribe/unsubscribe to tRPC endpoints
6970
- HTTP/2 stress testing with `GET` requests
7071
- GraphQL stress testing with `Query`
7172
- Mock server for HTTP/2 (`Express`)
@@ -110,7 +111,8 @@ For the following technologies - if you reference the gifs in `readme` and try t
110111

111112
<!-- - gRPC -->
112113

113-
- tRPC
114+
<!-- - tRPC -->
115+
114116
- OpenAPI
115117

116118
If future groups have a desire to iteration on the above features, please ensure the basic functionality works as expected, update E2E testing in `./test/testSuite.js` before adding new features.
@@ -161,7 +163,7 @@ Continuous Integration has been implemented using GitHub Actions. If you would l
161163
- Make any necessary adjustments to the workflow and continue testing it on ci-draft and ci-main until the workflow is functioning as intended
162164
- Finally, open a pull request to merge the new workflow into the dev and/or main branches
163165

164-
The idea is to troubleshoot new workflows before applying them to the dev or main branches.
166+
The idea is to troubleshoot new workflows before applying them to the dev or main branches.
165167

166168
A Continuous Deployment pipeline would be an advantageous addition, as its absence blocks the ability to automatically package and release new iterations of the application. The groundwork for it is there (see the “scripts” and “build” properties in package.json) but packaging for Linux will need some attention, as outlined in the next section.
167169

index-csp.html

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Swell</title>
7+
</head>
38

4-
<head>
5-
<meta charset="UTF-8" />
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<!-- <link rel="stylesheet" href="./node_modules/chart.js/dist/Chart.min.css" /> -->
8-
<title>Swell</title>
9-
</head>
10-
11-
<body></body>
12-
13-
</html>
9+
<body></body>
10+
</html>

main.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
// ** Entry point for Electron **
3434
const { app, BrowserWindow, ipcMain, dialog, shell } = require('electron');
3535

36-
3736
const { autoUpdater } = require('electron-updater');
3837
const {
3938
default: installExtension,
@@ -60,7 +59,7 @@ require('./main_process/main_graphqlController')();
6059
require('./main_process/main_grpcController.js')();
6160
require('./main_process/main_wsController.js')();
6261
require('./main_process/main_mockController.js')();
63-
62+
require('./main_process/main_trpcController.js')();
6463

6564
// require mac touchbar
6665
const { touchBar } = require('./main_process/main_touchbar.js');
@@ -218,8 +217,6 @@ app.on('ready', () => {
218217
}
219218
});
220219

221-
222-
223220
// Quit when all windows are closed.
224221
app.on('window-all-closed', () => {
225222
if (mockServerProcess) {
@@ -427,9 +424,13 @@ ipcMain.on('import-proto', (event) => {
427424
if (err) {
428425
return console.log('import-proto error reading file : ', err);
429426
}
430-
427+
431428
protoParserFunc(importedProto).then((protoObj) => {
432-
mainWindow.webContents.send('proto-info', JSON.stringify(importedProto), JSON.stringify(protoObj));
429+
mainWindow.webContents.send(
430+
'proto-info',
431+
JSON.stringify(importedProto),
432+
JSON.stringify(protoObj)
433+
);
433434
});
434435
});
435436
})
@@ -442,8 +443,11 @@ ipcMain.on('import-proto', (event) => {
442443
// Runs the function and returns the value back to GRPCProtoEntryForm
443444
ipcMain.on('protoParserFunc-request', async (event, data) => {
444445
try {
445-
const result = await protoParserFunc(data)
446-
mainWindow.webContents.send('protoParserFunc-return', JSON.stringify(result));
446+
const result = await protoParserFunc(data);
447+
mainWindow.webContents.send(
448+
'protoParserFunc-return',
449+
JSON.stringify(result)
450+
);
447451
} catch (err) {
448452
console.log('error in protoParserFunc-request:, ', err);
449453
mainWindow.webContents.send('protoParserFunc-return', { error: err });
@@ -464,28 +468,30 @@ ipcMain.on('import-openapi', (event) => {
464468
.then((filePaths) => {
465469
if (!filePaths) return undefined;
466470
// read uploaded document & save in the redux store
467-
fs.readFile(filePaths.filePaths[0], 'utf-8', async (err, importedFile) => {
468-
// handle read error
469-
if (err) {
470-
return console.log('import-openapi error reading file : ', err);
471-
}
472-
473-
try {
474-
const documentObj = await openapiParserFunc(importedFile);
475-
// console.log('Main.js - Working here!',documentObj);
476-
mainWindow.webContents.send('openapi-info', documentObj);
477-
} catch (err) {
478-
return console.log('import-openapi error reading file : ', err);
471+
fs.readFile(
472+
filePaths.filePaths[0],
473+
'utf-8',
474+
async (err, importedFile) => {
475+
// handle read error
476+
if (err) {
477+
return console.log('import-openapi error reading file : ', err);
478+
}
479+
480+
try {
481+
const documentObj = await openapiParserFunc(importedFile);
482+
// console.log('Main.js - Working here!',documentObj);
483+
mainWindow.webContents.send('openapi-info', documentObj);
484+
} catch (err) {
485+
return console.log('import-openapi error reading file : ', err);
486+
}
479487
}
480-
481-
});
488+
);
482489
})
483490
.catch((err) => {
484491
console.log('error in import-openapi', err);
485492
});
486493
});
487494

488-
489495
/////////////////////////////////////////////////////////////////////////////////
490496
/////////////////////////////// MOCK SERVER //////////////////////////////////////
491497
/////////////////////////////////////////////////////////////////////////////////

main_process/main_httpController.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ const httpController = {
191191
reqResObj.connectionType = 'plain';
192192
}
193193

194-
// FIXME: There is something wrong with the logic below.
195-
// First, it is checking if the headers have a 'content-length'
196-
// or 'Content-Length' property. If it does not, it sets the
197-
// responseSize to null. It it does, it checks if the headers have
198-
// a 'content-length' property. If it does, it sets the contentLength
199-
// to 'content-length' or 'Content-Length'. This does not make sense.
200-
// I think it should be setting contentLength to headers['content-length']
194+
// FIXME: There is something wrong with the logic below.
195+
// First, it is checking if the headers have a 'content-length'
196+
// or 'Content-Length' property. If it does not, it sets the
197+
// responseSize to null. It it does, it checks if the headers have
198+
// a 'content-length' property. If it does, it sets the contentLength
199+
// to 'content-length' or 'Content-Length'. This does not make sense.
200+
// I think it should be setting contentLength to headers['content-length']
201201
// or headers['Content-Length'].
202202

203203
// check if response comes with 'content-length' header
@@ -209,14 +209,14 @@ const httpController = {
209209
? (contentLength = 'content-length')
210210
: (contentLength = 'Content-Length');
211211

212-
// FIXME: A previous group used a conversion figure of 1023.89427 to
213-
// convert octets to bytes. This is incorrect because both an octet
214-
// and byte are exactly 8 bits in modern computing. There could, however,
215-
// be some ambiguity because "bytes" may have a different meaning in legacy
216-
// systems. Check out this link for more info: https://en.wikipedia.org/wiki/Octet_(computing).
217-
// If the desired responseSize is in bytes, it is enough to simply assign the value
212+
// FIXME: A previous group used a conversion figure of 1023.89427 to
213+
// convert octets to bytes. This is incorrect because both an octet
214+
// and byte are exactly 8 bits in modern computing. There could, however,
215+
// be some ambiguity because "bytes" may have a different meaning in legacy
216+
// systems. Check out this link for more info: https://en.wikipedia.org/wiki/Octet_(computing).
217+
// If the desired responseSize is in bytes, it is enough to simply assign the value
218218
// of the content-length header.
219-
219+
220220
// Converting content length octets into bytes
221221
const conversionFigure = 1023.89427;
222222
const octetToByteConversion =
@@ -295,7 +295,6 @@ const httpController = {
295295
const { method, headers, body } = args.options;
296296
const response = await fetch(headers.url, { method, headers, body });
297297
const headersResponse = response.headers.raw();
298-
299298
if (headersResponse['content-type'][0].includes('stream')) {
300299
return {
301300
headers: headersResponse,
@@ -334,7 +333,6 @@ const httpController = {
334333
reqResObj.timeSent = Date.now();
335334

336335
const options = this.parseFetchOptionsFromReqRes(reqResObj);
337-
338336
//-----------------------------------------
339337
// Check if the URL provided is a stream
340338
//-----------------------------------------
@@ -404,7 +402,7 @@ const httpController = {
404402
cookies.forEach((cookie) => {
405403
const cookieString = `${cookie.key}=${cookie.value}`;
406404
// attach to formattedHeaders so options object includes this
407-
formattedHeaders.cookie = cookieString;
405+
formattedHeaders.cookie = formattedHeaders.cookie + ';' + cookieString;
408406
});
409407
}
410408

0 commit comments

Comments
 (0)