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!
Getting started
Prerequisites
Create a Fauna account
Install VS Code
Install the Fauna extension in VS Code.
1. Set your secret key
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.
Using a .faunarc
file for a project
- IMPORTANT: Add
.faunarc
to your .gitignore
.
- Create a file
.faunarc
in your project root folder.
- Add
FAUNA_KEY=your-secret-key
to the .faunarc
file.
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
Using VS Code to store a database key
- 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 .faunarc
file) 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 > Extensions
to 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 > Fauna
from 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 or localhost
when using a local Fauna Dev Docker instance.
fauna.scheme
: One of https
or http
. Only set to http
when 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 the docker run
command - usually 8443
.
fauna.graphqlHost
: The full URL for the Fauna GraphQL API. The default is https://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 .vscode
configuration.
2. Browse database
- 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 Bar
from 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).
3. Run queries
If you are on a Mac, open the command palette with the keyboard shortcut Cmd
+ Shift
+ P
. If you are on a PC, use Ctrl
+ Shift
+ P
.
Create a new file from which to run your FQL queries by either:
Typing Fauna: Create query
to select that command from the command palette dropdown menu. This opens a new tab with the Paginate(Collections())
query already included.
Creating a new file with the .fql
file extension.
Open the command palette again using Cmd
+ Shift
+ P
, but this time start typing Fauna: Run query
to 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.
4. Upload GraphQL Schema
Open a .graphql
or .gql
file 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, use Ctrl
+ Shift
+ P
.
Fauna provides commands for uploading schemas, depending on modes:
Enter Fauna: Upload GraphQL Schema
to upload in the default merge
mode.
Enter Fauna: Merge GraphQL Schema
to explicitly upload in merge
mode.
Enter Fauna: Override GraphQL Schema
to upload in override
mode.
WARNING: override
mode causes data loss for any previous GraphQL schema. Collections, indexes, or documents that are not involved in GraphQL are not affected.
Features
Commands
- Fauna: Create query
- Fauna: Run query
- Fauna: Upload GraphQL Schema
- Fauna: Merge GraphQL Schema
- Fauna: Override GraphQL Schema
Built With