This is a demo StepZen + Next.js project created from the stepzen-dev/stepzen-vercel-starter-template template repo.
-
First, install StepZen CLI and log in using your StepZen account name and the admin key from
dashboard.stepzen.com/account.npm i -g stepzen stepzen login
-
Then, create a
.env.localfile to pass your StepZen credentials to the NextJS app:echo "STEPZEN_ACCOUNT=$(stepzen whoami --account)" >> .env.local echo "STEPZEN_API_KEY=$(stepzen whoami --apikey)" >> .env.local
-
Finally, install dependencies and start the development server:
npm i npm run dev
Running
npm run devalso executesstepzen start, which is the command to deploy your GraphQL API to the StepZen cloud. You can as well run thestepzen startcommand at any point, in a serapate terminal window.Read more about what happens when you run
npm run dev, in the "Getting started" explained section below.
Open http://localhost:3000 with your browser to see the app, and dashboard.stepzen.com to see your GraphQL API endpoint.
You can edit the GraphQL API by modifying stepzen/index.graphql by hand, or use the stepzen import CLI command to import additional data sources to your API.
The page auto-updates as you edit JS or CSS files, and the GraphQL API on stepzen.net auto-updates as you edit GraphQL schema files in stepzen/.
The GraphiQL component on the home page is only an example to show that your app has a GraphQL API. Feel free to delete this component at any time. You can always use the StepZen dashboard to explore your GraphQL endpoints.
To learn more about StepZen, take a look at the following resources:
- StepZen Documentation - learn about StepZen features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the StepZen examples GitHub repository for more StepZen examples.
If you created this app by clonning the starter repo with the "Deploy to Vercel" button, your Vercel project already has the STEPZEN_ACCOUNT and STEPZEN_API_KEY environment variables defined. The StepZen Vercel integtaion does that for you, and you do not need to make any extra actions.
If you deploy this repo to another hosting, please make sure to define the STEPZEN_ACCOUNT and STEPZEN_API_KEY environment variables in your deployment / hosting admin panel.
This section explains step-by-step what happens under the hood when running the steps from the Getting started section above.
-
npm i -g stepzenInstall the
stepzennpm package into your system (globally). It comes with thestepzencommand line tool, which is what you can later use to run commands likestepzen login. -
stepzen loginLog in with your StepZen account name and an admin key so that StepZen CLI could act on your behalf. You can always check your login status with
stepzen whoamiand log out withstepzen logout. -
npm run devStart both NextJS and StepZen development servers for your project using the
concurrentlynpm package. Both servers run in parallel and print logs into the same terminal window. Each line starts with either[StepZen]or[NextJS], telling you which source it comes from. Terminating the task withCtrl+C/Cmd+Cstops both dev servers.The StepZen development server watches for GraphQL schema changes inside the
./stepzenfolder, and automatically redeploys the schema to the StepZen cloud on every change. You can start this server separately with thestepzen start --dir ./stepzencommand.The NextJS development server watches for NextJS source file change, and automatically updates the web page in the browser on every change. You can start this server separately with the
npx next devcommand.See the exact logic in
package.json.
In VS Code you can get full IntelliSense support inside GraphQL queries for your API:
-
install the GraphQL: Language Feature Support extension
-
set the
STEPZEN_ACCOUNTandSTEPZEN_API_KEYenvironment variables when launching VS Code- either by setting these 2 environment variables globally, system-wide
- or by passing them to VS Code on start-up (e.g. by
env $(cat .env.local | xargs) code .)
-- OR --
replace the
${STEPZEN_ACCOUNT}and${STEPZEN_API_KEY}placeholders in the.graphqlrcfile with specific values (and do NOT commit this file anymore) -
✨ IntelliSense works inside
/* GraphQL */-prefixed template literals ✨
