This is a Next.js project bootstrapped with create-next-app.
First, run the development server:
yarn devOpen http://localhost:3000 with your browser to see the result.
This project uses next/font to automatically optimize and load Inter, a custom Google Font and other fonts.
- https://www.educative.io/answers/how-to-set-up-prettier-and-automatic-formatting-on-vs-code
- https://www.digitalocean.com/community/tutorials/how-to-format-code-with-prettier-in-visual-studio-code
- https://code.visualstudio.com/docs/editor/port-forwarding
- https://medium.com/@agusetyawan/supercharge-your-web-development-harnessing-the-power-of-local-port-forwarding-in-vs-code-bad362e6b719
Install prettier
npm install -g prettierUse scripts from the package.json file, it includes these scripts
prettier --write .
npx eslint --fix .Or simply
yarn prettier
yarn eslintNB! Use local Strapi because graphql retroinspection is allowed in dev mode only. NB! Use http://0.0.0.0:1337 instead of localhost URL to avoid ECONNREFUSED issues.
We've integrated WebStorm graphql-codegen package for automatic types generation based on provided schemas.
The codegen.yml file in the root is configuration file for grapqhl-codegen package, it's created in YML format to pass the ENV value there with no need to run process.env. like commands to pass schema URL.
Graphql configuration file is located at /src/app/_lib/_graphql/cms directory for the Strapi CMS graphql and is generated into generated.ts there.
To generate types:
This can be executed if you run yarn generate from the root of the repository, from where the codegen.yml file is situated.! This will run the introspection and update the schema.graphql for you and update generated.ts file. Then create your *.graphql query file and run this command again, it will inspect schema again and also put your queries from new *.graphl files!
- Go to
src/app/_lib/_graphqland selectcmsif you want to work with CMS API. - Create new
.graphqlfile. - Write your desired query.
- If you are using JetBrains IDE you need to generate schema file:
- In the left bottom corner of your IDE find
GraphQLtab. - Expand
cmsschema. - Double-click on
STRAPI APIbelow "Endpoints". - Select "Get GraphQL Schema from the endpoint (introspection)".
- IDE will update
schema.graphqlfile in selected folder.
- In the left bottom corner of your IDE find
- Open tab in terminal and run
yarn generate. - File
generated.tswill be updated with your newest query types.
NB! If you have issues regenerating the graphql code using codegen look into codegen.yml file.
NB! Introspection works with Strapi running in dev mode only, retrospection is disabled for production mode.
To use your query:
- Go to appropriate
apifile, eg./_lib/api/MenuApi.ts yarn apigenerated for you object that can be passed as query to URQL client, name of this object should look like this:NameOfYourQueryDocument- Once you use this object, it should be auto imported by your IDE. If not, then you can import it from
graphql/*/generated.ts
If Next.js cached page data and you really want to refresh it, try ctrl+F5 hard-refresh in your browser window instead (when yarn dev is used to run the development server).