0.10.21 ā€¢ Published 3 years ago

simple-graphql-to-typescript v0.10.21

Weekly downloads
513
License
MIT
Repository
github
Last release
3 years ago

Simple-graphql-to-typescript generator

šŸš€ šŸ”„ Simple Typescript interface generator from a GraphQL api schemas or URL

npm version npm downloads npm downloads

Any help for writing test or adding options is greatly welcomed! šŸ˜

Usage

Refer to the full documentation !

New in 0.10.12

Added apolloVersion option.

Installation

For global use

npm i -g simple-graphql-to-typescript
#or
yarn global add simple-graphql-to-typescript

For local use

npm i simple-graphql-to-typescript --save-dev
#or
yarn add -D simple-graphql-to-typescript

Quick Exemples

With generated, fully-typed and abortable Apollo handlers, and generated fragments

sgts -e https://graphql.anilist.co/ -o ./generated.ts --codegen-functions --gen-fragments
import { apiProvider } from './generated.ts';
import { ApolloClient } from '@apollo/client/core';

const sgts = apiProvider(
  new ApolloClient({ uri: 'https://graphql.anilist.co/', cache: new InMemoryCache() })
);
// Declare the main api source with your ApolloClient constructor

const mediaListQuery = sgts.MediaList().$args({ sort: [MediaListSort.Added_time] });

// You can still add fallback fragment by passing it to the first method
// `sgts.MediaList(`id status`)...`
// Or
// `sgts.MediaList(gql`fragment MediaListFragment on MediaList { ... }`)...`

const mediaList = await mediaListQuery.$fetch();
console.log(mediaList);

mediaListQuery.$abort();
// You can abort the query anytime

With only GraphQL types transpiled to Typescript interfaces

sgts -e https://graphql.anilist.co/ -o ./generated.ts

Part of the generated output:

...

/** A user's general options */
export interface UserOptions {
  /** The language the user wants to see media titles in*/
  titleLanguage: Maybe<UserTitleLanguage>;
  /** Whether the user has enabled viewing of 18+ content*/
  displayAdultContent: Maybe<boolean>;
  /** Whether the user receives notifications when a show they are watching aires*/
  airingNotifications: Maybe<boolean>;
  /** Profile highlight color (blue, purple, pink, orange, red, green, gray)*/
  profileColor: Maybe<string>;
  /** Notification options*/
  notificationOptions: Maybe<NotificationOption[]>;
  /** The user's timezone offset (Auth user only)*/
  timezone: Maybe<string>;
  /** Minutes between activity for them to be merged together. 0 is Never, Above 2 weeks (20160 mins) is Always.*/
  activityMergeTime: Maybe<number>;
}

/** The language the user wants to see media titles in */
export enum UserTitleLanguage {
  Romaji = 'ROMAJI',
  English = 'ENGLISH',
  Native = 'NATIVE',
  Romaji_stylised = 'ROMAJI_STYLISED',
  English_stylised = 'ENGLISH_STYLISED',
  Native_stylised = 'NATIVE_STYLISED',
}
...

Help

sgts -h

Options

OptionShort syntaxTypeUsage
--endpoint <endpoint>-estring(url)See doc
--json <path to json>-jstring(path)See doc
--output <path>-ostring(path) default ./generated.tsSee doc
--codegen-functionsbooleanSee doc
--codegen-react-hooksbooleanSee doc
--codegen-vue-hooksbooleanSee doc
--gen-fragmentsbooleanSee doc
--codegen-templatesbooleanSee doc
--apolloVersionnumber default 3See doc
--customScalars <scalars>{"myScalar": "MyType"}See doc
--prefix <prefix>-pstring default nullSee doc
--suffix <suffix>-sstring default nullSee doc
--header <header>string default nullSee doc
--compileToJsbooleanSee doc
--download-Dstring default nullSee doc
generatestring default developmentSee doc
initSee doc

Roadmap

I don't have much free time to develop feature I don't use, but feel free to send a PR!

  • Export only Gql string
  • Removed Query and mutation name in Apollo Hooks data
  • Config file .sgtsrc.js
  • Support Subscriptions for codegen-react-hooks
  • Support Subscriptions for codegen-vue-hooks
  • Support Subscriptions for codegen-template
  • Support Subscriptions for codegen-functions
  • Support UseLazyQuery Apollo Hook

In Progress

  • Highlight new generated, modified or deleted types in terminal

License

MIT

Victor Garcia

0.10.18

3 years ago

0.10.19

3 years ago

0.10.20

3 years ago

0.10.21

3 years ago

0.10.17

3 years ago

0.10.15

3 years ago

0.10.16

3 years ago

0.10.14

3 years ago

0.10.12

3 years ago

0.10.13

3 years ago

0.10.11

3 years ago

0.10.10

3 years ago

0.10.9

3 years ago

0.10.8

3 years ago

0.10.7

3 years ago

0.10.6

3 years ago

0.10.5

3 years ago

0.10.4

3 years ago

0.10.2

3 years ago

0.10.3

3 years ago

0.10.1

3 years ago

0.9.9

3 years ago

0.10.0

3 years ago

0.9.8

3 years ago

0.9.7

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.9.0

4 years ago

0.8.9

4 years ago

0.8.8

4 years ago

0.8.7

4 years ago

0.8.6

4 years ago

0.8.5

4 years ago

0.8.4

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.7.10

4 years ago

0.8.0

4 years ago

0.7.9

4 years ago

0.7.8

4 years ago

0.7.7

4 years ago

0.7.5

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.19

4 years ago

0.6.18

4 years ago

0.6.17

4 years ago

0.6.16

4 years ago

0.6.15

4 years ago

0.6.14

4 years ago

0.6.13

4 years ago

0.6.12

4 years ago

0.6.11

4 years ago

0.6.10

4 years ago

0.6.9

4 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.8

4 years ago

0.6.5

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.4.9

4 years ago

0.4.8

4 years ago

0.4.7

4 years ago

0.4.6

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.37

4 years ago

0.3.36

4 years ago

0.3.35

4 years ago

0.3.34

4 years ago

0.3.33

4 years ago

0.3.32

4 years ago

0.3.31

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.53

4 years ago

0.2.52

5 years ago

0.2.51

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.31

5 years ago

0.2.3

5 years ago

0.2.12

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.94

5 years ago

0.1.93

5 years ago

0.1.92

5 years ago

0.1.91

5 years ago

0.1.9

5 years ago

0.1.82

5 years ago

0.1.81

5 years ago

0.1.8

5 years ago

0.1.72

5 years ago

0.1.71

5 years ago

0.1.7

5 years ago

0.1.66

5 years ago

0.1.65

5 years ago

0.1.64

5 years ago

0.1.63

5 years ago

0.1.62

5 years ago

0.1.61

5 years ago

0.1.6

5 years ago

0.1.52

5 years ago

0.1.51

5 years ago

0.1.5

5 years ago

0.1.41

5 years ago

0.1.4

5 years ago

0.1.39

5 years ago

0.1.38

5 years ago

0.1.37

5 years ago

0.1.36

5 years ago

0.1.35

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.67

5 years ago

0.0.66

5 years ago

0.0.651

5 years ago

0.0.65

5 years ago

0.0.64

5 years ago

0.0.63

5 years ago

0.0.62

5 years ago

0.0.612

5 years ago

0.0.611

5 years ago

0.0.61

5 years ago

0.0.6

5 years ago

0.0.511

5 years ago

0.0.51

5 years ago

0.0.5

5 years ago

0.0.45

5 years ago

0.0.44

5 years ago

0.0.433

5 years ago

0.0.432

5 years ago

0.0.431

5 years ago

0.0.43

5 years ago

0.0.423

5 years ago

0.0.422

5 years ago

0.0.421

5 years ago

0.0.42

5 years ago

0.0.41

5 years ago

0.0.4

5 years ago

0.0.351

5 years ago

0.0.35

5 years ago

0.0.33

5 years ago

0.0.32

5 years ago

0.0.31

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago