Skip to content

Commit

Permalink
50 setup apollo client for ssr with nextjs (#51)
Browse files Browse the repository at this point in the history
* build(frontend): install apollo client and simplify environment variables

* fix(frontend): disable apollo caching results

* feat: create example client

* feat: setup graphql codegen and example usage

* docs: 📝 Update docs for graphQL codegen

* refactor(frontend): Make blog use graphql queries with apollo

* refactor: 🗑️ Remove unused code

* fix: 🚑 Fix build issues with nextjs and apollo client

Fixed in the new apollo client alpha. issue tracked here apollographql/apollo-client-nextjs#113

* fix: Fix styling and linting ignore files. Also style with prettier

* docs: 📝 Update docs

* refactor(frontend): Refactor blog article page to use graphQL

* fix: fix lint error

* refactor(frontend): 🔥 remove unused console logs

* fix(frontend): fix undefined attributes error

* fix(frontend): 🐛 try to fix undefined attributes bug

* docs: 📝 Update graphql typegen docs

* fix: 🐛 disable caching while developing

* fix: 🐛 fix undefined error

* fix: 🐛 Fix author avatar image bug
  • Loading branch information
stromseng committed Jan 26, 2024
1 parent ed4655f commit 04e1c42
Show file tree
Hide file tree
Showing 19 changed files with 6,760 additions and 637 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "2024-01-26T13:37:41.662Z"
"x-generation-date": "2024-01-26T19:22:16.105Z"
},
"x-strapi-config": {
"path": "/documentation",
Expand Down
12 changes: 12 additions & 0 deletions docs/general-usage.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
### Type generation

###### REST

When updating a schema in Strapi, you have to run `npm run generateTypes` in the root directory to generate the proper types for the frontend.

> This uses Strapi's official [documentation plugin](https://docs.strapi.io/dev-docs/plugins/documentation) to generate documentation matching the [OpenAPI specification](https://swagger.io/specification/). It then uses the [@openapi-typescript](https://www.npmjs.com/package/openapi-typescript) package to generate the typescript types.
>
> The generated documentation can be found at [http://localhost:1337/documentation/v1.0.0](http://localhost:1337/documentation/v1.0.0) when running the dev server.
###### GraphQL

If you're using GraphQL, then you need to run `npm run compile` from `/frontend` whenever you update a schema or define a new graphQL request in the code. Make sure to import the correct `gql` as

```
import { gql } from"@/generated/gql";
```

> [https://www.apollographql.com/docs/react/development-testing/static-typing/](https://www.apollographql.com/docs/react/development-testing/static-typing/)
### Strapi First time boot

Goto Settings > Users & Permissions plugin > Roles > Public > Article, and enable `find` and `findOne`
Expand Down
1 change: 0 additions & 1 deletion frontend/.env.development
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Database API URL
API_URL=http://localhost:1337/api/
HOST_URL=http://localhost:1337
1 change: 0 additions & 1 deletion frontend/.env.production
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Heroku Database API
API_URL=https://small-sat-lab-6ad3da13947b.herokuapp.com/api/
HOST_URL=https://small-sat-lab-6ad3da13947b.herokuapp.com
3 changes: 2 additions & 1 deletion frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": ["eslint:recommended", "next/core-web-vitals", "prettier"]
"extends": ["eslint:recommended", "next/core-web-vitals", "prettier"],
"ignorePatterns": ["src/__generated__/*"]
}
3 changes: 3 additions & 0 deletions frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Ignore artifacts:
build
coverage

# Ignore graphQL codegen generated types
src/__generated__/*
21 changes: 21 additions & 0 deletions frontend/codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CodegenConfig } from "@graphql-codegen/cli";

const HOST_URL = "http://localhost:1337";

const config: CodegenConfig = {
schema: HOST_URL + "/graphql",
// this assumes that all your source files are in a top-level `src/` directory - you might need to adjust this to your file structure
documents: ["src/**/*.{ts,tsx}"],
generates: {
"./src/__generated__/": {
preset: "client",
plugins: [],
presetConfig: {
gqlTagName: "gql",
},
},
},
ignoreNoDocuments: true,
};

export default config;
Loading

0 comments on commit 04e1c42

Please sign in to comment.