/selection-set-to-type

Turns a GraphQL Selection Set string into a Typescript type

Primary LanguageTypeScriptMIT LicenseMIT

selection-set-to-type

Experimental utility to convert a GraphQL selection set into a TypeScript type.

Turn a string like this:

const selection = `
  {
    a
    b {
      a
      b
      c
    }
    c
    e
    f
    g
  }
`;

Into a type like this:

type T {
    a: unknown;
    b: {
        a: unknown;
        b: unknown;
        c: unknown;
    };
    c: unknown;
    e: unknown;
    f: unknown;
    g: unknown;
}