-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add typings for global.lab to Monaco Editor (#6393)
- Loading branch information
1 parent
a8ff443
commit 84fd770
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'hive': minor | ||
--- | ||
|
||
Add type definitions of global.lab to Preflight Script editor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/web/app/src/lib/preflight-sandbox/lab-api-declaration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
|
||
// The content of this file is used as a string | ||
// and feed into the context of the Monaco Editor and the Preflight Script. | ||
// The lack of `declare const lab: LabAPI` is intentional, to avoid messing up the global scope | ||
// of the web app codebase. | ||
// This could be a string in `graphiql-plugin.tsx`, but it's better to keep it in a separate file, | ||
// and use Prettier to format it, have syntax highlighting, etc. | ||
|
||
interface LabAPI { | ||
/** | ||
* [CryptoJS](https://cryptojs.gitbook.io/docs) library. | ||
*/ | ||
CryptoJS: any; | ||
/** | ||
* Use lab.environment API to store and retrieve data between requests | ||
* or to pass values directly to HTTP headers for executed GraphQL requests. | ||
*/ | ||
environment: { | ||
/** | ||
* Returns the value of the environment variable with the given key. | ||
*/ | ||
get(key: string): unknown; | ||
/** | ||
* Sets the value of the environment variable with the given key. | ||
*/ | ||
set(key: string, value: unknown): void; | ||
}; | ||
/** | ||
* Mimics the \`prompt\` function in the browser, by sending a message to the main thread | ||
* and waiting for a response. | ||
*/ | ||
prompt(message: string, defaultValue?: string): Promise<string>; | ||
} |