Skip to content

Commit

Permalink
GitBook: [#78] No subject
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kus authored and gitbook-bot committed Jan 18, 2022
1 parent fe7f9d2 commit 2974686
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions graphql/genql.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# GenQL

[GenQL](https://genql.vercel.app/) is a great library and CLI tool that automatically generates a fully typed SDK with a built-in GQL client. It works flawlessly with Hasura and is recommended for DipDup on the client-side.
[GenQL](https://genql.vercel.app) is a great library and CLI tool that automatically generates a fully typed SDK with a built-in GQL client. It works flawlessly with Hasura and is recommended for DipDup on the client-side.

## Project structure

GenQL CLI generates a ready-to-use package, compiled and prepared to publish to NPM. A typical setup is a mono repository containing several packages, including the auto-generated SDK and your front-end application.

```text
```
project_root/
├── package.json
└── packages/
Expand Down Expand Up @@ -35,10 +35,9 @@ Your minimal _package.json_ file will look like the following:
"graphql": "^15.5.0"
},
"scripts": {
"build": "genql --esm --endpoint %GRAPHQL_ENDPOINT% --output ./dist"
"build": "genql --endpoint %GRAPHQL_ENDPOINT% --output ./dist"
}
}

```

That's it! Now you only need to install dependencies and execute the build target:
Expand All @@ -47,3 +46,46 @@ That's it! Now you only need to install dependencies and execute the build targe
yarn
yarn build
```

Read more about CLI [options](https://genql.vercel.app/docs/cli/generate) available.

### Demo

Create a `package.json` file with

* `%PACKAGE_NAME%` => `metadata-sdk`
* `%GRAPHQL_ENDPOINT%` => `https://metadata.dipdup.net/v1/graphql`

And generate the client:

```
yarn
yarn build
```

Then create new file `index.ts` and paste this query:

```typescript
import { createClient, everything } from './dist'

const client = createClient()

client.chain.query
.token_metadata({ where: { network: { _eq: 'mainnet' } }})
.get({ ...everything })
.then(res => console.log(res))
```

We need some additional dependencies to run our sample:

```
yarn add typescript ts-node
```

Finally:

```
npx ts-node index.ts
```

You should see a list of tokens with metadata attached in your console.

0 comments on commit 2974686

Please sign in to comment.