From f8c747f15daffe197f32ed9348cb9c3ca85c1b72 Mon Sep 17 00:00:00 2001 From: aexol Date: Wed, 8 Feb 2023 23:13:15 +0100 Subject: [PATCH] :sparkles: default .js import in node --- examples/typescript-node/package.json | 2 +- examples/typescript-node/src/zeus/apollo.ts | 28 +- examples/typescript-node/src/zeus/const.ts | 104 ++-- examples/typescript-node/src/zeus/index.ts | 482 +++++++++--------- .../src/zeus/typedDocumentNode.ts | 2 +- examples/typescript-node/zeus.graphql | 160 +++--- packages/graphql-zeus-core/TreeToTS/index.ts | 4 +- packages/graphql-zeus-core/package.json | 2 +- packages/graphql-zeus-jsonschema/package.json | 2 +- packages/graphql-zeus/package.json | 2 +- .../plugins/typedDocumentNode/index.ts | 2 +- 11 files changed, 396 insertions(+), 394 deletions(-) diff --git a/examples/typescript-node/package.json b/examples/typescript-node/package.json index e5e5a13c..23530529 100644 --- a/examples/typescript-node/package.json +++ b/examples/typescript-node/package.json @@ -1,6 +1,6 @@ { "name": "typescript-node", - "version": "1.0.7", + "version": "1.0.8", "description": "", "private": true, "main": "index.js", diff --git a/examples/typescript-node/src/zeus/apollo.ts b/examples/typescript-node/src/zeus/apollo.ts index 3e1082c0..27fe6f51 100644 --- a/examples/typescript-node/src/zeus/apollo.ts +++ b/examples/typescript-node/src/zeus/apollo.ts @@ -1,8 +1,8 @@ /* eslint-disable */ import { Zeus, GraphQLTypes, InputType, ValueTypes, OperationOptions, ScalarDefinition } from './index'; -import { gql, useMutation, useQuery, useLazyQuery, useSubscription } from '@apollo/client'; -import type { MutationHookOptions, QueryHookOptions, LazyQueryHookOptions, SubscriptionHookOptions } from '@apollo/client'; +import { gql, useMutation, useSubscription, useQuery, useLazyQuery } from '@apollo/client'; +import type { MutationHookOptions, SubscriptionHookOptions, QueryHookOptions, LazyQueryHookOptions } from '@apollo/client'; export function useTypedMutation( @@ -18,41 +18,41 @@ export function useTypedMutation( - query: Z | ValueTypes[O], +export function useTypedSubscription( + subscription: Z | ValueTypes[O], options?:{ - apolloOptions?: QueryHookOptions>, + apolloOptions?: SubscriptionHookOptions>, operationOptions?: OperationOptions, scalars?: SCLR } ) { - return useQuery>(gql(Zeus("query",query, { + return useSubscription>(gql(Zeus("subscription",subscription, { operationOptions: options?.operationOptions, scalars: options?.scalars })), options?.apolloOptions); } -export function useTypedLazyQuery( - LazyQuery: Z | ValueTypes[O], +export function useTypedQuery( + query: Z | ValueTypes[O], options?:{ - apolloOptions?: LazyQueryHookOptions>, + apolloOptions?: QueryHookOptions>, operationOptions?: OperationOptions, scalars?: SCLR } ) { - return useLazyQuery>(gql(Zeus("query",LazyQuery, { + return useQuery>(gql(Zeus("query",query, { operationOptions: options?.operationOptions, scalars: options?.scalars })), options?.apolloOptions); } -export function useTypedSubscription( - subscription: Z | ValueTypes[O], +export function useTypedLazyQuery( + LazyQuery: Z | ValueTypes[O], options?:{ - apolloOptions?: SubscriptionHookOptions>, + apolloOptions?: LazyQueryHookOptions>, operationOptions?: OperationOptions, scalars?: SCLR } ) { - return useSubscription>(gql(Zeus("subscription",subscription, { + return useLazyQuery>(gql(Zeus("query",LazyQuery, { operationOptions: options?.operationOptions, scalars: options?.scalars })), options?.apolloOptions); diff --git a/examples/typescript-node/src/zeus/const.ts b/examples/typescript-node/src/zeus/const.ts index f8f1ab60..db02b879 100644 --- a/examples/typescript-node/src/zeus/const.ts +++ b/examples/typescript-node/src/zeus/const.ts @@ -1,77 +1,87 @@ /* eslint-disable */ export const AllTypesProps: Record = { - SpecialSkills: "enum" as const, - JSON: `scalar.JSON` as const, - Card:{ - attack:{ - - } - }, createCard:{ skills:"SpecialSkills" }, + Public:{ + powerups:{ + + } + }, Mutation:{ addCard:{ card:"createCard" } }, - Query:{ - cardById:{ + JSON: `scalar.JSON` as const, + Card:{ + attack:{ } }, - Public:{ - powerups:{ + Query:{ + cardById:{ } - } + }, + SpecialSkills: "enum" as const } export const ReturnTypes: Record = { - JSON: `scalar.JSON` as const, - Card:{ - Attack:"Int", - Children:"Int", - Defense:"Int", - attack:"Card", - cardImage:"S3Object", - description:"String", - id:"ID", - image:"String", - info:"JSON", - name:"String", - skills:"SpecialSkills" + ChangeCard:{ + "...on SpecialCard":"SpecialCard", + "...on EffectCard":"EffectCard" + }, + CardStack:{ + cards:"Card", + name:"String" + }, + Public:{ + powerups:"Powerup" + }, + Mutation:{ + addCard:"Card" + }, + S3Object:{ + bucket:"String", + key:"String", + region:"String" }, Powerup:{ name:"String" }, - ChangeCard:{ - "...on SpecialCard":"SpecialCard", - "...on EffectCard":"EffectCard" + SpecialCard:{ + effect:"String", + name:"String" }, EffectCard:{ effectSize:"Float", name:"String" }, Nameable:{ - "...on Card": "Card", - "...on EffectCard": "EffectCard", "...on CardStack": "CardStack", "...on SpecialCard": "SpecialCard", + "...on EffectCard": "EffectCard", + "...on Card": "Card", name:"String" }, - CardStack:{ - cards:"Card", - name:"String" - }, - S3Object:{ - bucket:"String", - key:"String", - region:"String" + JSON: `scalar.JSON` as const, + Card:{ + Attack:"Int", + Children:"Int", + Defense:"Int", + attack:"Card", + cardImage:"S3Object", + description:"String", + id:"ID", + image:"String", + info:"JSON", + name:"String", + skills:"SpecialSkills" }, - Mutation:{ - addCard:"Card" + Subscription:{ + deck:"Card" }, Query:{ cardById:"Card", @@ -81,21 +91,11 @@ export const ReturnTypes: Record = { myStacks:"CardStack", nameables:"Nameable", public:"Public" - }, - SpecialCard:{ - effect:"String", - name:"String" - }, - Public:{ - powerups:"Powerup" - }, - Subscription:{ - deck:"Card" } } export const Ops = { mutation: "Mutation" as const, - query: "Query" as const, - subscription: "Subscription" as const + subscription: "Subscription" as const, + query: "Query" as const } \ No newline at end of file diff --git a/examples/typescript-node/src/zeus/index.ts b/examples/typescript-node/src/zeus/index.ts index bd2c0541..163e3e2d 100644 --- a/examples/typescript-node/src/zeus/index.ts +++ b/examples/typescript-node/src/zeus/index.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import { AllTypesProps, ReturnTypes, Ops } from './const'; +import { AllTypesProps, ReturnTypes, Ops } from './const.js'; import fetch, { Response } from 'node-fetch'; import WebSocket from 'ws'; export const HOST = "https://faker.graphqleditor.com/a-team/olympus/graphql" @@ -54,7 +54,7 @@ const handleFetchResponse = (response: Response): Promise => { .catch(reject); }); } - return response.json(); + return response.json() as Promise; }; export const apiFetch = @@ -656,8 +656,8 @@ export const resolverFor = [Z] extends [infer Input, any] ? Input : any, source: any, - ) => Z extends keyof ModelTypes[T] ? ModelTypes[T][Z] | Promise | X : any, -) => fn as (args?: any, source?: any) => any; + ) => Z extends keyof ModelTypes[T] ? ModelTypes[T][Z] | Promise | X : never, +) => fn as (args?: any, source?: any) => ReturnType; export type UnwrapPromise = T extends Promise ? R : T; export type ZeusState Promise> = NonNullable>>; @@ -833,7 +833,68 @@ export type ScalarCoders = { type ZEUS_UNIONS = GraphQLTypes["ChangeCard"] export type ValueTypes = { - ["SpecialSkills"]:SpecialSkills; + ["ChangeCard"]: AliasType<{ ["...on SpecialCard"] : ValueTypes["SpecialCard"], + ["...on EffectCard"] : ValueTypes["EffectCard"] + __typename?: boolean | `@${string}` +}>; + /** create card inputs
*/ +["createCard"]: { + /** The defense power
*/ + Defense: number | Variable, + /** input skills */ + skills?: Array | undefined | null | Variable, + /** The name of a card
*/ + name: string | Variable, + /** Description of a card
*/ + description: string | Variable, + /**
How many children the greek god had
*/ + Children?: number | undefined | null | Variable, + /** The attack power
*/ + Attack: number | Variable +}; + /** Stack of cards */ +["CardStack"]: AliasType<{ + cards?:ValueTypes["Card"], + name?:boolean | `@${string}`, + __typename?: boolean | `@${string}` +}>; + ["Public"]: AliasType<{ +powerups?: [{ filter: string | Variable},ValueTypes["Powerup"]], + __typename?: boolean | `@${string}` +}>; + ["Mutation"]: AliasType<{ +addCard?: [{ card: ValueTypes["createCard"] | Variable},ValueTypes["Card"]], + __typename?: boolean | `@${string}` +}>; + /** Aws S3 File */ +["S3Object"]: AliasType<{ + bucket?:boolean | `@${string}`, + key?:boolean | `@${string}`, + region?:boolean | `@${string}`, + __typename?: boolean | `@${string}` +}>; + ["Powerup"]: AliasType<{ + name?:boolean | `@${string}`, + __typename?: boolean | `@${string}` +}>; + ["SpecialCard"]: AliasType<{ + effect?:boolean | `@${string}`, + name?:boolean | `@${string}`, + __typename?: boolean | `@${string}` +}>; + ["EffectCard"]: AliasType<{ + effectSize?:boolean | `@${string}`, + name?:boolean | `@${string}`, + __typename?: boolean | `@${string}` +}>; + ["Nameable"]:AliasType<{ + name?:boolean | `@${string}`; + ['...on CardStack']?: Omit; + ['...on SpecialCard']?: Omit; + ['...on EffectCard']?: Omit; + ['...on Card']?: Omit; + __typename?: boolean | `@${string}` +}>; ["JSON"]:unknown; /** Card used in card game
*/ ["Card"]: AliasType<{ @@ -857,32 +918,59 @@ attack?: [{ /** Attacked card/card ids
*/ skills?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - ["Powerup"]: AliasType<{ - name?:boolean | `@${string}`, - __typename?: boolean | `@${string}` -}>; - ["ChangeCard"]: AliasType<{ ["...on SpecialCard"] : ValueTypes["SpecialCard"], - ["...on EffectCard"] : ValueTypes["EffectCard"] + ["Subscription"]: AliasType<{ + deck?:ValueTypes["Card"], __typename?: boolean | `@${string}` }>; - ["EffectCard"]: AliasType<{ - effectSize?:boolean | `@${string}`, - name?:boolean | `@${string}`, + ["Query"]: AliasType<{ +cardById?: [{ cardId?: string | undefined | null | Variable},ValueTypes["Card"]], + /** Draw a card
*/ + drawCard?:ValueTypes["Card"], + drawChangeCard?:ValueTypes["ChangeCard"], + /** list All Cards availble
*/ + listCards?:ValueTypes["Card"], + myStacks?:ValueTypes["CardStack"], + nameables?:ValueTypes["Nameable"], + public?:ValueTypes["Public"], __typename?: boolean | `@${string}` }>; - ["Nameable"]:AliasType<{ - name?:boolean | `@${string}`; - ['...on Card']?: Omit; - ['...on EffectCard']?: Omit; - ['...on CardStack']?: Omit; - ['...on SpecialCard']?: Omit; + ["SpecialSkills"]:SpecialSkills + } + +export type ResolverInputTypes = { + ["ChangeCard"]: AliasType<{ + SpecialCard?:ResolverInputTypes["SpecialCard"], + EffectCard?:ResolverInputTypes["EffectCard"], __typename?: boolean | `@${string}` }>; + /** create card inputs
*/ +["createCard"]: { + /** The defense power
*/ + Defense: number, + /** input skills */ + skills?: Array | undefined | null, + /** The name of a card
*/ + name: string, + /** Description of a card
*/ + description: string, + /**
How many children the greek god had
*/ + Children?: number | undefined | null, + /** The attack power
*/ + Attack: number +}; /** Stack of cards */ ["CardStack"]: AliasType<{ - cards?:ValueTypes["Card"], + cards?:ResolverInputTypes["Card"], name?:boolean | `@${string}`, __typename?: boolean | `@${string}` +}>; + ["Public"]: AliasType<{ +powerups?: [{ filter: string},ResolverInputTypes["Powerup"]], + __typename?: boolean | `@${string}` +}>; + ["Mutation"]: AliasType<{ +addCard?: [{ card: ResolverInputTypes["createCard"]},ResolverInputTypes["Card"]], + __typename?: boolean | `@${string}` }>; /** Aws S3 File */ ["S3Object"]: AliasType<{ @@ -891,35 +979,8 @@ attack?: [{ /** Attacked card/card ids
*/ region?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - /** create card inputs
*/ -["createCard"]: { - /** Description of a card
*/ - description: string | Variable, - /**
How many children the greek god had
*/ - Children?: number | undefined | null | Variable, - /** The attack power
*/ - Attack: number | Variable, - /** The defense power
*/ - Defense: number | Variable, - /** input skills */ - skills?: Array | undefined | null | Variable, - /** The name of a card
*/ - name: string | Variable -}; - ["Mutation"]: AliasType<{ -addCard?: [{ card: ValueTypes["createCard"] | Variable},ValueTypes["Card"]], - __typename?: boolean | `@${string}` -}>; - ["Query"]: AliasType<{ -cardById?: [{ cardId?: string | undefined | null | Variable},ValueTypes["Card"]], - /** Draw a card
*/ - drawCard?:ValueTypes["Card"], - drawChangeCard?:ValueTypes["ChangeCard"], - /** list All Cards availble
*/ - listCards?:ValueTypes["Card"], - myStacks?:ValueTypes["CardStack"], - nameables?:ValueTypes["Nameable"], - public?:ValueTypes["Public"], + ["Powerup"]: AliasType<{ + name?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; ["SpecialCard"]: AliasType<{ @@ -927,18 +988,19 @@ cardById?: [{ cardId?: string | undefined | null | Variable},ValueT name?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - ["Public"]: AliasType<{ -powerups?: [{ filter: string | Variable},ValueTypes["Powerup"]], + ["EffectCard"]: AliasType<{ + effectSize?:boolean | `@${string}`, + name?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - ["Subscription"]: AliasType<{ - deck?:ValueTypes["Card"], + ["Nameable"]:AliasType<{ + name?:boolean | `@${string}`; + ['...on CardStack']?: Omit; + ['...on SpecialCard']?: Omit; + ['...on EffectCard']?: Omit; + ['...on Card']?: Omit; __typename?: boolean | `@${string}` -}> - } - -export type ResolverInputTypes = { - ["SpecialSkills"]:SpecialSkills; +}>; ["JSON"]:unknown; /** Card used in card game
*/ ["Card"]: AliasType<{ @@ -962,58 +1024,8 @@ attack?: [{ /** Attacked card/card ids
*/ skills?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - ["Powerup"]: AliasType<{ - name?:boolean | `@${string}`, - __typename?: boolean | `@${string}` -}>; - ["ChangeCard"]: AliasType<{ - SpecialCard?:ResolverInputTypes["SpecialCard"], - EffectCard?:ResolverInputTypes["EffectCard"], - __typename?: boolean | `@${string}` -}>; - ["EffectCard"]: AliasType<{ - effectSize?:boolean | `@${string}`, - name?:boolean | `@${string}`, - __typename?: boolean | `@${string}` -}>; - ["Nameable"]:AliasType<{ - name?:boolean | `@${string}`; - ['...on Card']?: Omit; - ['...on EffectCard']?: Omit; - ['...on CardStack']?: Omit; - ['...on SpecialCard']?: Omit; - __typename?: boolean | `@${string}` -}>; - /** Stack of cards */ -["CardStack"]: AliasType<{ - cards?:ResolverInputTypes["Card"], - name?:boolean | `@${string}`, - __typename?: boolean | `@${string}` -}>; - /** Aws S3 File */ -["S3Object"]: AliasType<{ - bucket?:boolean | `@${string}`, - key?:boolean | `@${string}`, - region?:boolean | `@${string}`, - __typename?: boolean | `@${string}` -}>; - /** create card inputs
*/ -["createCard"]: { - /** Description of a card
*/ - description: string, - /**
How many children the greek god had
*/ - Children?: number | undefined | null, - /** The attack power
*/ - Attack: number, - /** The defense power
*/ - Defense: number, - /** input skills */ - skills?: Array | undefined | null, - /** The name of a card
*/ - name: string -}; - ["Mutation"]: AliasType<{ -addCard?: [{ card: ResolverInputTypes["createCard"]},ResolverInputTypes["Card"]], + ["Subscription"]: AliasType<{ + deck?:ResolverInputTypes["Card"], __typename?: boolean | `@${string}` }>; ["Query"]: AliasType<{ @@ -1028,23 +1040,56 @@ cardById?: [{ cardId?: string | undefined | null},ResolverInputTypes["Card"]], public?:ResolverInputTypes["Public"], __typename?: boolean | `@${string}` }>; - ["SpecialCard"]: AliasType<{ - effect?:boolean | `@${string}`, - name?:boolean | `@${string}`, - __typename?: boolean | `@${string}` -}>; - ["Public"]: AliasType<{ -powerups?: [{ filter: string},ResolverInputTypes["Powerup"]], - __typename?: boolean | `@${string}` -}>; - ["Subscription"]: AliasType<{ - deck?:ResolverInputTypes["Card"], - __typename?: boolean | `@${string}` -}> + ["SpecialSkills"]:SpecialSkills } export type ModelTypes = { - ["SpecialSkills"]:SpecialSkills; + ["ChangeCard"]:ModelTypes["SpecialCard"] | ModelTypes["EffectCard"]; + /** create card inputs
*/ +["createCard"]: { + /** The defense power
*/ + Defense: number, + /** input skills */ + skills?: Array | undefined, + /** The name of a card
*/ + name: string, + /** Description of a card
*/ + description: string, + /**
How many children the greek god had
*/ + Children?: number | undefined, + /** The attack power
*/ + Attack: number +}; + /** Stack of cards */ +["CardStack"]: { + cards?: Array | undefined, + name: string +}; + ["Public"]: { + powerups?: Array | undefined +}; + ["Mutation"]: { + /** add Card to Cards database
*/ + addCard: ModelTypes["Card"] +}; + /** Aws S3 File */ +["S3Object"]: { + bucket: string, + key: string, + region: string +}; + ["Powerup"]: { + name?: string | undefined +}; + ["SpecialCard"]: { + effect: string, + name: string +}; + ["EffectCard"]: { + effectSize: number, + name: string +}; + ["Nameable"]: ModelTypes["CardStack"] | ModelTypes["SpecialCard"] | ModelTypes["EffectCard"] | ModelTypes["Card"]; ["JSON"]:any; /** Card used in card game
*/ ["Card"]: { @@ -1067,70 +1112,88 @@ export type ModelTypes = { name: string, skills?: Array | undefined }; - ["Powerup"]: { - name?: string | undefined -}; - ["ChangeCard"]:ModelTypes["SpecialCard"] | ModelTypes["EffectCard"]; - ["EffectCard"]: { - effectSize: number, - name: string + ["Subscription"]: { + deck?: Array | undefined }; - ["Nameable"]: ModelTypes["Card"] | ModelTypes["EffectCard"] | ModelTypes["CardStack"] | ModelTypes["SpecialCard"]; - /** Stack of cards */ -["CardStack"]: { - cards?: Array | undefined, - name: string + ["Query"]: { + cardById?: ModelTypes["Card"] | undefined, + /** Draw a card
*/ + drawCard: ModelTypes["Card"], + drawChangeCard: ModelTypes["ChangeCard"], + /** list All Cards availble
*/ + listCards: Array, + myStacks?: Array | undefined, + nameables: Array, + public?: ModelTypes["Public"] | undefined }; - /** Aws S3 File */ -["S3Object"]: { - bucket: string, - key: string, - region: string + ["SpecialSkills"]:SpecialSkills + } + +export type GraphQLTypes = { + ["ChangeCard"]:{ + __typename:"SpecialCard" | "EffectCard" + ['...on SpecialCard']: '__union' & GraphQLTypes["SpecialCard"]; + ['...on EffectCard']: '__union' & GraphQLTypes["EffectCard"]; }; /** create card inputs
*/ ["createCard"]: { + /** The defense power
*/ + Defense: number, + /** input skills */ + skills?: Array | undefined, + /** The name of a card
*/ + name: string, /** Description of a card
*/ description: string, /**
How many children the greek god had
*/ Children?: number | undefined, /** The attack power
*/ - Attack: number, - /** The defense power
*/ - Defense: number, - /** input skills */ - skills?: Array | undefined, - /** The name of a card
*/ + Attack: number +}; + /** Stack of cards */ +["CardStack"]: { + __typename: "CardStack", + cards?: Array | undefined, name: string +}; + ["Public"]: { + __typename: "Public", + powerups?: Array | undefined }; ["Mutation"]: { - /** add Card to Cards database
*/ - addCard: ModelTypes["Card"] + __typename: "Mutation", + /** add Card to Cards database
*/ + addCard: GraphQLTypes["Card"] }; - ["Query"]: { - cardById?: ModelTypes["Card"] | undefined, - /** Draw a card
*/ - drawCard: ModelTypes["Card"], - drawChangeCard: ModelTypes["ChangeCard"], - /** list All Cards availble
*/ - listCards: Array, - myStacks?: Array | undefined, - nameables: Array, - public?: ModelTypes["Public"] | undefined + /** Aws S3 File */ +["S3Object"]: { + __typename: "S3Object", + bucket: string, + key: string, + region: string +}; + ["Powerup"]: { + __typename: "Powerup", + name?: string | undefined }; ["SpecialCard"]: { - effect: string, + __typename: "SpecialCard", + effect: string, name: string }; - ["Public"]: { - powerups?: Array | undefined + ["EffectCard"]: { + __typename: "EffectCard", + effectSize: number, + name: string +}; + ["Nameable"]: { + __typename:"CardStack" | "SpecialCard" | "EffectCard" | "Card", + name: string + ['...on CardStack']: '__union' & GraphQLTypes["CardStack"]; + ['...on SpecialCard']: '__union' & GraphQLTypes["SpecialCard"]; + ['...on EffectCard']: '__union' & GraphQLTypes["EffectCard"]; + ['...on Card']: '__union' & GraphQLTypes["Card"]; }; - ["Subscription"]: { - deck?: Array | undefined -} - } - -export type GraphQLTypes = { - ["SpecialSkills"]: SpecialSkills; ["JSON"]: "scalar" & { name: "JSON" }; /** Card used in card game
*/ ["Card"]: { @@ -1154,60 +1217,9 @@ export type GraphQLTypes = { name: string, skills?: Array | undefined }; - ["Powerup"]: { - __typename: "Powerup", - name?: string | undefined -}; - ["ChangeCard"]:{ - __typename:"SpecialCard" | "EffectCard" - ['...on SpecialCard']: '__union' & GraphQLTypes["SpecialCard"]; - ['...on EffectCard']: '__union' & GraphQLTypes["EffectCard"]; -}; - ["EffectCard"]: { - __typename: "EffectCard", - effectSize: number, - name: string -}; - ["Nameable"]: { - __typename:"Card" | "EffectCard" | "CardStack" | "SpecialCard", - name: string - ['...on Card']: '__union' & GraphQLTypes["Card"]; - ['...on EffectCard']: '__union' & GraphQLTypes["EffectCard"]; - ['...on CardStack']: '__union' & GraphQLTypes["CardStack"]; - ['...on SpecialCard']: '__union' & GraphQLTypes["SpecialCard"]; -}; - /** Stack of cards */ -["CardStack"]: { - __typename: "CardStack", - cards?: Array | undefined, - name: string -}; - /** Aws S3 File */ -["S3Object"]: { - __typename: "S3Object", - bucket: string, - key: string, - region: string -}; - /** create card inputs
*/ -["createCard"]: { - /** Description of a card
*/ - description: string, - /**
How many children the greek god had
*/ - Children?: number | undefined, - /** The attack power
*/ - Attack: number, - /** The defense power
*/ - Defense: number, - /** input skills */ - skills?: Array | undefined, - /** The name of a card
*/ - name: string -}; - ["Mutation"]: { - __typename: "Mutation", - /** add Card to Cards database
*/ - addCard: GraphQLTypes["Card"] + ["Subscription"]: { + __typename: "Subscription", + deck?: Array | undefined }; ["Query"]: { __typename: "Query", @@ -1221,28 +1233,16 @@ export type GraphQLTypes = { nameables: Array, public?: GraphQLTypes["Public"] | undefined }; - ["SpecialCard"]: { - __typename: "SpecialCard", - effect: string, - name: string -}; - ["Public"]: { - __typename: "Public", - powerups?: Array | undefined -}; - ["Subscription"]: { - __typename: "Subscription", - deck?: Array | undefined -} + ["SpecialSkills"]: SpecialSkills } export const enum SpecialSkills { + FIRE = "FIRE", THUNDER = "THUNDER", - RAIN = "RAIN", - FIRE = "FIRE" + RAIN = "RAIN" } type ZEUS_VARIABLES = { - ["SpecialSkills"]: ValueTypes["SpecialSkills"]; - ["JSON"]: ValueTypes["JSON"]; ["createCard"]: ValueTypes["createCard"]; + ["JSON"]: ValueTypes["JSON"]; + ["SpecialSkills"]: ValueTypes["SpecialSkills"]; } \ No newline at end of file diff --git a/examples/typescript-node/src/zeus/typedDocumentNode.ts b/examples/typescript-node/src/zeus/typedDocumentNode.ts index d457da69..54b9e391 100644 --- a/examples/typescript-node/src/zeus/typedDocumentNode.ts +++ b/examples/typescript-node/src/zeus/typedDocumentNode.ts @@ -11,7 +11,7 @@ import { Zeus, ExtractVariables, } from './'; -import { Ops } from './const'; +import { Ops } t'; export const typedGql = >( diff --git a/examples/typescript-node/zeus.graphql b/examples/typescript-node/zeus.graphql index f881340a..e7f63154 100644 --- a/examples/typescript-node/zeus.graphql +++ b/examples/typescript-node/zeus.graphql @@ -1,55 +1,58 @@ """""" -enum SpecialSkills { - """Lower enemy defense -5
""" - THUNDER +union ChangeCard = SpecialCard | EffectCard - """Attack multiple Cards at once
""" - RAIN +"""create card inputs
""" +input createCard { + """The defense power
""" + Defense: Int! - """50% chance to avoid any attack
""" - FIRE -} + """input skills""" + skills: [SpecialSkills!] -"""""" -scalar JSON + """The name of a card
""" + name: String! -"""Card used in card game
""" -type Card implements Nameable { - """The attack power
""" - Attack: Int! + """Description of a card
""" + description: String! """
How many children the greek god had
""" Children: Int - """The defense power
""" - Defense: Int! - - """Attack other cards on the table , returns Cards after attack
""" - attack( - """Attacked card/card ids
""" - cardID: [String!]! - ): [Card!] - - """Put your description here""" - cardImage: S3Object + """The attack power
""" + Attack: Int! +} - """Description of a card
""" - description: String! +"""Stack of cards""" +type CardStack implements Nameable { + """""" + cards: [Card!] """""" - id: ID! + name: String! +} +"""""" +type Public { """""" - image: String! + powerups(filter: String!): [Powerup!] +} + +"""""" +type Mutation { + """add Card to Cards database
""" + addCard(card: createCard!): Card! +} +"""Aws S3 File""" +type S3Object { """""" - info: JSON! + bucket: String! - """The name of a card
""" - name: String! + """""" + key: String! """""" - skills: [SpecialSkills!] + region: String! } """""" @@ -59,7 +62,13 @@ type Powerup { } """""" -union ChangeCard = SpecialCard | EffectCard +type SpecialCard implements Nameable { + """""" + effect: String! + + """""" + name: String! +} """""" type EffectCard implements Nameable { @@ -76,52 +85,52 @@ interface Nameable { name: String! } -"""Stack of cards""" -type CardStack implements Nameable { - """""" - cards: [Card!] +"""""" +scalar JSON - """""" - name: String! -} +"""Card used in card game
""" +type Card implements Nameable { + """The attack power
""" + Attack: Int! -"""Aws S3 File""" -type S3Object { - """""" - bucket: String! + """
How many children the greek god had
""" + Children: Int - """""" - key: String! + """The defense power
""" + Defense: Int! - """""" - region: String! -} + """Attack other cards on the table , returns Cards after attack
""" + attack( + """Attacked card/card ids
""" + cardID: [String!]! + ): [Card!] + + """Put your description here""" + cardImage: S3Object -"""create card inputs
""" -input createCard { """Description of a card
""" description: String! - """
How many children the greek god had
""" - Children: Int - - """The attack power
""" - Attack: Int! + """""" + id: ID! - """The defense power
""" - Defense: Int! + """""" + image: String! - """input skills""" - skills: [SpecialSkills!] + """""" + info: JSON! """The name of a card
""" name: String! + + """""" + skills: [SpecialSkills!] } """""" -type Mutation { - """add Card to Cards database
""" - addCard(card: createCard!): Card! +type Subscription { + """""" + deck: [Card!] } """""" @@ -149,24 +158,15 @@ type Query { } """""" -type SpecialCard implements Nameable { - """""" - effect: String! - - """""" - name: String! -} +enum SpecialSkills { + """50% chance to avoid any attack
""" + FIRE -"""""" -type Public { - """""" - powerups(filter: String!): [Powerup!] -} + """Lower enemy defense -5
""" + THUNDER -"""""" -type Subscription { - """""" - deck: [Card!] + """Attack multiple Cards at once
""" + RAIN } schema{ query: Query, diff --git a/packages/graphql-zeus-core/TreeToTS/index.ts b/packages/graphql-zeus-core/TreeToTS/index.ts index d309e19f..663cd0ed 100644 --- a/packages/graphql-zeus-core/TreeToTS/index.ts +++ b/packages/graphql-zeus-core/TreeToTS/index.ts @@ -105,7 +105,9 @@ export class TreeToTS { subscriptions = 'legacy', }: ResolveOptions) { return { - indexImports: `import { AllTypesProps, ReturnTypes, Ops } from './const${esModule ? '.js' : ''}';`.concat( + indexImports: `import { AllTypesProps, ReturnTypes, Ops } from './const${ + esModule || env === 'node' ? '.js' : '' + }';`.concat( env === 'node' ? ` import fetch, { Response } from 'node-fetch'; diff --git a/packages/graphql-zeus-core/package.json b/packages/graphql-zeus-core/package.json index a13debb1..2941d832 100644 --- a/packages/graphql-zeus-core/package.json +++ b/packages/graphql-zeus-core/package.json @@ -1,6 +1,6 @@ { "name": "graphql-zeus-core", - "version": "5.2.7", + "version": "5.2.8", "private": false, "main": "./lib/index.js", "author": "GraphQL Editor, Artur Czemiel", diff --git a/packages/graphql-zeus-jsonschema/package.json b/packages/graphql-zeus-jsonschema/package.json index 58ae7943..ffef767b 100644 --- a/packages/graphql-zeus-jsonschema/package.json +++ b/packages/graphql-zeus-jsonschema/package.json @@ -1,6 +1,6 @@ { "name": "graphql-zeus-jsonschema", - "version": "5.2.7", + "version": "5.2.8", "private": false, "main": "./lib/index.js", "author": "GraphQL Editor, Artur Czemiel", diff --git a/packages/graphql-zeus/package.json b/packages/graphql-zeus/package.json index c452d6de..ecd9be4d 100644 --- a/packages/graphql-zeus/package.json +++ b/packages/graphql-zeus/package.json @@ -1,6 +1,6 @@ { "name": "graphql-zeus", - "version": "5.2.7", + "version": "5.2.8", "private": false, "scripts": { "start": "ttsc --build tsconfig.build.json --watch", diff --git a/packages/graphql-zeus/plugins/typedDocumentNode/index.ts b/packages/graphql-zeus/plugins/typedDocumentNode/index.ts index 9431b334..57f060e8 100644 --- a/packages/graphql-zeus/plugins/typedDocumentNode/index.ts +++ b/packages/graphql-zeus/plugins/typedDocumentNode/index.ts @@ -11,7 +11,7 @@ import { Zeus, ExtractVariables, } from './'; -import { Ops } from './const'; +import { Ops } t'; export const typedGql = >(