diff --git a/README.md b/README.md index 7e69baa..6c26409 100644 --- a/README.md +++ b/README.md @@ -16,29 +16,43 @@ It provides the public schema SDL for you to use. You can use graphql-codegen to Follow one of the examples in the [examples](/examples) directory, or simply run. -Fetch a token. -```typescript -import { Defined } from '@definedfi/sdk' - -const sdk = new Defined(MY_API_KEY) +Fetch a token. -sdk.queries.token({ input: { address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c", networkId: 56 } }).then(console.log) +```typescript +import { Defined } from "@definedfi/sdk"; + +const sdk = new Defined(MY_API_KEY); + +sdk.queries + .token({ + input: { + address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c", + networkId: 56, + }, + }) + .then(console.log); ``` Use your own GraphQL selections + ```typescript -import { Network } from '../../src/resources/graphql' -import { Defined } from '@definedfi/sdk/dist/sdk' +import { Network } from "../../src/resources/graphql"; +import { Defined } from "@definedfi/sdk/dist/sdk"; -const sdk = new Defined(process.env.DEFINED_API_KEY || "") +const sdk = new Defined(process.env.DEFINED_API_KEY || ""); -sdk.send<{ getNetworks: Network[] }>(` +sdk + .send<{ getNetworks: Network[] }>( + ` query GetNetworks { getNetworks { id name } } -`, {}).then(res => { - console.log("Networks: ", res.getNetworks) -}) +`, + {} + ) + .then((res) => { + console.log("Networks: ", res.getNetworks); + }); ``` ## Running the examples @@ -49,30 +63,36 @@ You need to provide an API key in order for the examples to work. We have [bun]( After installing [bun](https://bun.sh), from the project root. -* `bun i` -* `bun run build` +- `bun i` +- `bun run build` ### Simple + This performs a simple inline graphql request, and uses a user-provided query and selection set. -* `cd examples/simple` -* `bun i` -* `DEFINED_API_KEY=xyz bun run index.ts` +- `cd examples/simple` +- `bun i` +- `DEFINED_API_KEY=xyz bun run index.ts` + +You can define your own GraphQL queries and use those with codegen (see next section). The pre-defined queries we provide in the +examples do not include all of the fields for every query. ### Codegen + This shows how to use graphql-codegen to generate query types and get a fully typed end-to-end experience. -* `cd examples/codegen` -* `bun i` -* `bun run codegen` -* `DEFINED_API_KEY=xyz bun run src/index.ts` +- `cd examples/codegen` +- `bun i` +- `bun run codegen` +- `DEFINED_API_KEY=xyz bun run src/index.ts` ### Next -This shows how you could use it in a next JS project. -* `cd examples/next` -* `bun i` -* `NEXT_PUBLIC_DEFINED_API_KEY=xyz bun run dev` +This shows how you could use it in a NextJS project. + +- `cd examples/next` +- `bun i` +- `NEXT_PUBLIC_DEFINED_API_KEY=xyz bun run dev` ## Contributing