2.7.0 • Published 8 months ago

@morpho-org/blue-api-sdk v2.7.0

Weekly downloads
-
License
-
Repository
github
Last release
8 months ago

@morpho-org/blue-api-sdk

GraphQL SDK that exports types from the API's GraphQL schema and a useful Apollo cache controller.

Installation

npm install @morpho-org/blue-api-sdk
yarn add @morpho-org/blue-api-sdk

Getting Started

Codegen

Create a codegen.ts file and define your desired preset & plugins, importing types from @morpho-org/blue-api-sdk. Below is given 3 typically recommended configurations:

Recommended near-operation-file preset config

import type { CodegenConfig } from "@graphql-codegen/cli";

import { BLUE_API_GRAPHQL_URL } from "@morpho-org/morpho-ts";

const config: CodegenConfig = {
  ...,
  schema: BLUE_API_GRAPHQL_URL,
  documents: ["src/graphql/**/*.{query,fragment}.gql"],
  generates: {
    "src/graphql/": {
      ...,
      preset: "near-operation-file",
      presetConfig: {
        baseTypesPath: "~@morpho-org/blue-api-sdk",
      },
    },
  },
};

export default config;

Recommended import-types preset config

import type { CodegenConfig } from "@graphql-codegen/cli";

import { BLUE_API_GRAPHQL_URL } from "@morpho-org/morpho-ts";

const config: CodegenConfig = {
  ...,
  schema: BLUE_API_GRAPHQL_URL,
  documents: ["graphql/*.{query,fragment}.gql"],
  generates: {
    "src/api/types.ts": {
      ...,
      preset: "import-types",
      presetConfig: {
        typesPath: "@morpho-org/blue-api-sdk",
      },
    },
  },
};

Recommended typescript-operations plugin config

import type { CodegenConfig } from "@graphql-codegen/cli";

import { BLUE_API_GRAPHQL_URL } from "@morpho-org/morpho-ts";

const config: CodegenConfig = {
  ...,
  schema: BLUE_API_GRAPHQL_URL,
  generates: {
    [...]: {
      plugins: ["typescript-operations", ...],
      config: {
        avoidOptionals: {
          field: true,
          inputValue: false,
          defaultValue: true,
        },
        scalars: {
          BigInt: {
            input: `Types.Scalars["BigInt"]["input"]`,
            output: `Types.Scalars["BigInt"]["output"]`,
          },
          HexString: {
            input: `Types.Scalars["HexString"]["input"]`,
            output: `Types.Scalars["HexString"]["output"]`,
          },
          Address: {
            input: `Types.Scalars["Address"]["input"]`,
            output: `Types.Scalars["Address"]["output"]`,
          },
          MarketId: {
            input: `Types.Scalars["MarketId"]["input"]`,
            output: `Types.Scalars["MarketId"]["output"]`,
          },
        },
      },
    },
  },
};

Apollo

Define an Apollo cache to use and specify the cache type policies exported from this package:

import { typePolicies } from "@morpho-org/blue-api-sdk";

// Apollo InMemoryCache needs to serialize BigInts to JSON, so we need to add a toJSON method to BigInt.prototype.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
// @ts-ignore
BigInt.prototype.toJSON = function () {
  return this.toString();
};

export const inMemoryCache = new InMemoryCache({ typePolicies });
2.4.1

11 months ago

2.4.0

11 months ago

2.4.2

11 months ago

2.6.0-next.0

10 months ago

2.0.0

1 year ago

2.3.0

1 year ago

2.3.1

12 months ago

2.7.0

8 months ago

2.5.0-next.0

11 months ago

2.0.0-next.15

1 year ago

2.0.0-next.16

1 year ago

2.0.0-next.17

1 year ago

1.12.7

1 year ago

1.12.6

1 year ago

1.12.5

1 year ago

2.0.0-next.11

1 year ago

2.5.0-next.3

11 months ago

2.0.0-next.12

1 year ago

2.5.0-next.2

11 months ago

2.0.0-next.13

1 year ago

2.5.0-next.1

11 months ago

2.0.0-next.14

1 year ago

2.2.0

1 year ago

2.6.1

9 months ago

2.6.0

9 months ago

2.5.0

11 months ago

2.1.0

1 year ago

2.0.0-next.10

1 year ago

2.0.0-next.9

1 year ago

2.0.0-next.8

1 year ago

2.0.0-next.7

1 year ago

2.0.0-next.6

1 year ago

2.0.0-next.4

1 year ago

2.0.0-next.5

1 year ago

2.0.0-next.2

1 year ago

2.0.0-next.1

1 year ago

1.12.3

1 year ago

1.10.5

1 year ago

1.12.1

1 year ago

1.12.0

1 year ago

1.12.4

1 year ago

2.0.0-alpha.3

1 year ago

2.0.0-alpha.4

1 year ago

2.0.0-alpha.5

1 year ago

2.0.0-alpha.6

1 year ago

2.0.0-alpha.1

1 year ago

2.0.0-alpha.2

1 year ago

1.11.0

1 year ago

1.11.2

1 year ago

1.11.1

1 year ago

1.10.5-alpha.5

1 year ago

1.10.5-alpha.8

1 year ago

1.10.5-alpha.6

1 year ago

1.10.5-alpha.7

1 year ago

2.0.0-test.1

1 year ago

1.10.5-alpha.4

1 year ago

1.10.5-alpha.2

1 year ago

1.10.5-alpha.3

1 year ago

1.10.5-alpha.1

1 year ago

1.10.5-alpha.0

1 year ago

1.10.4

1 year ago

1.10.3

1 year ago

1.10.2

1 year ago

1.10.1-alpha.1

1 year ago

1.9.1

1 year ago

1.10.1-alpha.0

1 year ago

1.9.0

1 year ago

1.8.0

1 year ago

1.7.6

1 year ago

1.7.5

1 year ago

1.7.4

1 year ago

1.10.1

1 year ago

1.10.0

1 year ago

1.7.3

1 year ago

1.7.2

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.10

1 year ago

1.5.9

1 year ago

1.5.8

1 year ago

1.5.7

1 year ago

1.5.6

1 year ago

1.5.5

1 year ago

1.5.4

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.6

1 year ago

1.4.6-alpha.3

1 year ago

1.4.6-alpha.2

1 year ago

1.4.6-alpha.1

1 year ago

1.4.6-alpha.0

1 year ago

1.4.5

1 year ago

1.4.4

1 year ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago