Skip to content

Commit

Permalink
Merge pull request #10 from sushidev-team/feat/clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoud authored Mar 5, 2024
2 parents 17844b2 + 3195afd commit 130542f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/workflows/npm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ jobs:
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEXT_PUBLIC_CMS_API_TOKEN: ${{ secrets.CMS_API_TOKEN }}
NEXT_PUBLIC_CMS_API_URL: ${{ secrets.NEXT_PUBLIC_CMS_API_URL }}
1 change: 0 additions & 1 deletion .github/workflows/pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ jobs:
run: npm publish --tag alpha
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEXT_PUBLIC_CMS_API_TOKEN: ${{ secrets.CMS_API_TOKEN }}
NEXT_PUBLIC_CMS_API_URL: ${{ secrets.NEXT_PUBLIC_CMS_STAGE_API_URL }}
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This repository is a collection of shared GraphQL queries that can be used acros

## Getting Started

First, create a `.env.local` file and paste all necessary env variables in there. Check the `.env.example` file as a starting point and ask your team for the necessary content.
First, create a `.env.local` file and paste all necessary env variables in there. Check the `.env.example` file as a starting point.

Add the GraphQL extensions from the GraphQL Foundation to VSCode. This will give you syntax highlighting and autocompletion for GraphQL queries.

Expand All @@ -17,7 +17,6 @@ npm run dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. This is meant for testing your queries before bundling and publishing.
You can also use the local_link script by running `npm run local-link` to link this package to your frontend locally. This will make sure that you can use the latest version of this package without having to publish it first.

When writing queries pls make sure to either have the dev server running or run the `gql:watch` script. Only when either of the two is running the automatic code generation will work.

Expand All @@ -35,7 +34,7 @@ To use this package in other projects follow the steps below to make the project
npm install -D @graphql-codegen/cli @graphql-codegen/typed-document-node @graphql-codegen/typescript @graphql-codegen/typescript-operations @next/env @parcel/watcher
```

- Create a `.graphqlrc.js` file inside the root of your project and paste the following content inside. Replace the url and apiToken with the correct values. Also adapt the gqlPath to your needs. This is the path where the generated types will be saved and where you have to place your graphql files. You can also add a `generateSchema` key with the value false to the graphqlrc function if you don't want to generate the introspection schema.
- Create a `.graphqlrc.js` file inside the root of your project and paste the following content inside. Replace the url and apiToken with the correct values. Also adapt the gqlPath to your needs. This is the path where the generated types will be saved and where you have to place your graphql files.

```js
const { loadEnvConfig } = require('@next/env');
Expand Down Expand Up @@ -77,7 +76,7 @@ Example of your build and dev scripts:

### Urql Boilerplate

- Make sure you have the `NEXT_PUBLIC_CMS_API_URL` and `NEXT_PUBLIC_CMS_API_TOKEN` env set.
- Make sure you have the `NEXT_PUBLIC_CMS_API_URL` env set.
- Paste the following content into `lib/urql.ts` or any other file you want to use for your urql setup.

```ts
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export type Mission = {
asset_full?: Maybe<Scalars['String']>;
/** Asset type */
asset_type?: Maybe<AssetType>;
completed?: Maybe<Scalars['Boolean']>;
creator?: Maybe<User>;
/** This will be filled if the provider is not greengage */
deeplink?: Maybe<Scalars['String']>;
Expand Down Expand Up @@ -677,6 +678,7 @@ export type QueryPoiArgs = {


export type QueryPoisArgs = {
city?: InputMaybe<Scalars['ID']>;
page?: InputMaybe<Scalars['Int']>;
};

Expand Down
12 changes: 10 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import { ExampleQueryDocument } from '../lib/graphql/generated';
import { clearSsrCache, ssrCache, ssrQuery, useQuery } from '../lib/urql';

function Home({ data }) {
console.log(data);

// Example client side request - returns cache when used together with ssr query example 2
const [{ data: citiesData }] = useQuery({ query: ExampleQueryDocument, variables: {} });
const cities = citiesData?.cities;

const printData = JSON.stringify(data || '', null, 2);
const printData = JSON.stringify(cities || '', null, 2);

return (
<main>
Expand All @@ -34,20 +37,25 @@ function Home({ data }) {
{printData}
</SyntaxHighlighter>
</section>
<ul>{cities?.map((city) => <li key={city?.id}>{city?.id}</li>)}</ul>
</main>
);
}

export const getStaticProps: GetStaticProps = async () => {
clearSsrCache();

// SSR query example 1
const { data } = await ssrQuery({ query: ExampleQueryDocument, variables: {} });

// SSR query example 2
await ssrQuery({ query: ExampleQueryDocument, variables: {} });

return {
props: {
// Include this when using SSR query example 1
data,

// Include this when using SSR query example 2
urqlState: ssrCache.extractData(),
},
};
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"skipLibCheck": true,
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"jsx": "react",
"jsx": "preserve",
"incremental": true,
"noEmit": true,
"declaration": false,
"declarationMap": false,
Expand Down

0 comments on commit 130542f

Please sign in to comment.