Debug and test a connector
As you develop your extension, refer to this document for tips on how to debug your connector and how to write tests for your connector code.
Run your connector locally
Before you begin, make sure you review the docs for how to run your connector locally and complete the set-up steps. This includes setting local configuration options and specifying a frontend site for visual editor.
Debug
As you develop and test your extension, you may need to debug the GraphQL types that the Netlify SDK generates using your connector, or debug the connector itself.
Make sure your project has dev and build scripts
When you use the SDK’s guided set-up flow to create an extension, we automatically add scripts
to your project that run the netlify-extension dev
and netlify-extension build
commands.
If you skipped the guided set-up flow, make sure you install the Netlify SDK in your project, and manually update your package.json
to
include "dev": "netlify-extension dev"
and "build": "netlify-extension build"
.
Debug GraphQL types
To debug the GraphQL types that the Netlify SDK generates using your connector, run:
The command starts a local GraphQL server for your connector and outputs a dev-model.gql
file to your terminal’s current working directory. The dev-model.gql
file contains the GraphQL schema that the Netlify SDK generated from your model definitions.
For example:
You can review this file to check for any errors.
We recommend that you add dev-model.gql
to your .gitignore
file to avoid committing it to your repository.
Debug your connector
Since connectors deal with large amounts of data, the most effective way to debug your connector is to use Node debuggers. You can use console.log()
statements also, but we recommend using Node debuggers instead.
For Node debuggers to work, set your IDE to auto-attach to child processes.
The steps to use Node debuggers with your connector will be similar across IDEs. As an example, here is how to run the debugger in VS Code:
-
Open the command palette (
cmd+shift+p
on macOS). -
Type in
JavaScript Debug Terminal
and press enter. -
VS Code will open a new terminal window. In that terminal, run:
-
Add breakpoints or type the word
debugger
in your code to pause on a specific line. -
When the debugger pauses, it will highlight the line and you can hover over nearby variables to inspect their runtime values in a pop-up.
-
Save your code to automatically detach the debugger and restart the process. The debugger will pause again on any new breakpoints you set.
Test connector code
To create a stable connector, you should write tests for your code.
The Netlify SDK includes a contentEngine
utility that you can use to run your connector and test locally. contentEngine
includes the following testing utilities:
sync
: simulates a data sync by runningconnector.sync(fn)
.stop
: stops thecontentEngine
. This is helpful for resetting after a test suite completes.test
: includes the following methods that you can use for testing queries:getNodes
: gets all documents.getNodesByType
: gets all documents by GraphQL type. The GraphQL type is generated using the document model’s name. For example,Post
orAuthor
.query
: runs a specified GraphQL query.
Before you run the tests, make sure to build your connector by running:
The tests will run on the bundled extension.
Here is an example of how to use these testing utilities:
Next steps
When you’re ready, you can publish your extension as a private extension and test it with your team in production.