Source code for the Fauna VS Code extension.
This extension allows users to view individual Fauna databases and run FQL queries directly inside VS Code.
Note: This extension does not yet support auto-complete, which is planned for a future release. Alternatively, please feel free to submit a PR to help out!
-
Create a Fauna account
-
Install VS Code
-
Install the Fauna extension in VS Code.
You can persist a Fauna secret using either a .faunarc file in your project or using the settings in the VS Code IDE.
Persisting a secret in VS Code settings sets the key at a global level for all projects. A project can override the global key by including a .faunarc config file in the root of the project.
- IMPORTANT: Add
.faunarcto your.gitignore. - Create a file
.faunarcin your project root folder. - Add
FAUNA_KEY=your-secret-keyto the.faunarcfile.
Additionally, the config file supports these optional parameters:
FAUNA_DOMAIN=db.fauna.com
FAUNA_SCHEME=https
FAUNA_PORT=443
FAUNA_GRAPHQL_HOST=https://graphql.fauna.com
- The VS Code extension allows you to work in the context of a single database, for which you need to provide a key. You can do this by generating a key with the "admin" role from the database "Security" tab in the Fauna Dashboard.
Note that you'll need to update the Fauna domain in the extension settings (or
.faunarcfile) as needed to match the database Region Group; see the Region Group documentation for more details.
- Copy the secret and paste it in the Fauna extension settings. You can find the Fauna extension settings by either:
-
Selecting
View > Extensionsto open the Extensions pane, scrolling down in the list of installed extensions until you see Fauna, then clicking the cog icon in the lower right to open the extension settings. -
Selecting
Code > Preferences > Settings > Extensions > Faunafrom the VS Code menu.
- Restart VS Code after setting or changing your secret.
fauna.adminSecretKey: The secret for a specific database.fauna.domain: The Fauna domain for the database Region Group orlocalhostwhen using a local Fauna Dev Docker instance.fauna.scheme: One ofhttpsorhttp. Only set tohttpwhen using a local Fauna Dev Docker instance.fauna.port: The port number for the Fauna endpoint. When using a Fauna Dev Docker instance, use the port passed to thedocker runcommand - usually8443.fauna.graphqlHost: The full URL for the Fauna GraphQL API. The default ishttps://graphql.fauna.com. See GraphQL Endpoints for Region Group-specific URLs.
WARNING: Be careful! To avoid exposing this secret, do not commit it to your local
.vscodeconfiguration.
- Click on the Fauna bird icon in the Activity bar on the far left. If you do not see the Activity Bar, select
View > Appearance > Show Activity Barfrom the VS Code menu. - You should see a pane listing all of the database contents, which includes child databases, indexes, collections, documents, and functions.
Note: Browsing is read-only at this time, but you can edit all of your data by running queries (see next section).
-
If you are on a Mac, open the command palette with the keyboard shortcut
Cmd+Shift+P. If you are on a PC, useCtrl+Shift+P. -
Create a new file from which to run your FQL queries by either:
-
Typing
Fauna: Create queryto select that command from the command palette dropdown menu. This opens a new tab with thePaginate(Collections())query already included. -
Creating a new file with the
.fqlfile extension.
-
Open the command palette again using
Cmd+Shift+P, but this time start typingFauna: Run queryto select that command from the dropdown menu. -
The Output panel should open from the bottom of the VS Code window and display the query results.
- If your file contains multiple FQL expressions, you can trigger them individually by highlighting the expression you want to execute.
-
Open a
.graphqlor.gqlfile containing your GraphQL schema as described in the Fauna specification. -
If you are on a Mac, open the command palette with the keyboard shortcut
Cmd+Shift+P. If you are on a PC, useCtrl+Shift+P. -
Fauna provides commands for uploading schemas, depending on modes:
-
Enter
Fauna: Upload GraphQL Schemato upload in the defaultmergemode. -
Enter
Fauna: Merge GraphQL Schemato explicitly upload inmergemode. -
Enter
Fauna: Override GraphQL Schemato upload inoverridemode.
WARNING:
overridemode causes data loss for any previous GraphQL schema. Collections, indexes, or documents that are not involved in GraphQL are not affected.
Commands
- Fauna: Create query
- Fauna: Run query
- Fauna: Upload GraphQL Schema
- Fauna: Merge GraphQL Schema
- Fauna: Override GraphQL Schema