JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 92
  • Score
    100M100P100Q58469F
  • License MIT

A GraphQL code generator plugin for Grafast schemas

Package Exports

  • graphql-codegen-grafast

Readme

graphql-codegen-grafast

GitHub Sponsors Discord chat room Follow

GraphQL Codegen support for Grafast's makeGrafastSchema.

Types only.

HIGHLY EXPERIMENTAL - expect breaking changes in every release.

Usage

TODO

yarn add --dev @graphql-codegen/cli graphql-codegen-grafast
// codegen.ts
import type { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  schema: "./schema.ts",
  ignoreNoDocuments: true,
  generates: {
    "./schema-generated.ts": {
      plugins: ["typescript", "grafast"],
      config: {
        overridesFile: "./schema-manual-types.ts",
      },
    },
  },
};

export default config;
// schema.ts
import { get } from "grafast";
import { typedMakeGrafastSchema } from "./schema-generated.js";

const schema = typedMakeGrafastSchema({
  typeDefs: /* GraphQL */ `
    type Query {
      character(id: Int!): Character
    }

    interface Character {
      id: Int!
      name: String!
    }
  `,
  objects: {
    Character: {
      plans: {
        name($character) {
          return get($character, "name");
        },
      },
    },
    // ...
  },
  unions: {
    // ...
  },
  interfaces: {
    // ...
  },
  inputObjects: {
    // ...
  },
  scalars: {
    // ...
  },
  enums: {
    // ...
  },
});
// schema-manual-types.ts
import type { Maybe, Step } from "grafast";
import type { CharacterData } from "./data.js";

// IMPORTANT: Steps must represent the nullable version (suitable for returning
// from a plan resolver). Should you wish to specify a different (non-nullable)
// version that's suitable as a field plan resolver's first argument, use the
// `source:` key in addition to specifying `nullable:`.
export type Overrides = {
  Character: {
    nullable: Step<Maybe<CharacterData>>;
  };
};
yarn graphql-codegen

Crowd-funded open-source software

To help us develop this software sustainably, we ask all individuals and businesses that use it to help support its ongoing maintenance and development via sponsorship.

Click here to find out more about sponsors and sponsorship.

And please give some love to our featured sponsors 🤩:

The Guild
The Guild
*
Steelhead
Steelhead
*

* Sponsors the entire Graphile suite