From bf5102bbff9b0b56b3800723e2756976e0e94859 Mon Sep 17 00:00:00 2001 From: aexol Date: Mon, 15 Apr 2024 12:54:01 +0200 Subject: [PATCH] new version with get request --- examples/typescript-node/package.json | 2 +- examples/typescript-node/src/zeus/const.ts | 98 ++-- examples/typescript-node/src/zeus/index.ts | 455 +++++++++--------- examples/typescript-node/zeus.graphql | 160 +++--- package.json | 1 + packages/graphql-zeus-core/package.json | 2 +- packages/graphql-zeus-jsonschema/package.json | 2 +- packages/graphql-zeus/CLIClass.ts | 6 +- packages/graphql-zeus/Utils/index.ts | 24 +- packages/graphql-zeus/index.ts | 5 + packages/graphql-zeus/package.json | 6 +- 11 files changed, 396 insertions(+), 365 deletions(-) diff --git a/examples/typescript-node/package.json b/examples/typescript-node/package.json index 3331a48e..b909b7de 100644 --- a/examples/typescript-node/package.json +++ b/examples/typescript-node/package.json @@ -1,6 +1,6 @@ { "name": "typescript-node", - "version": "1.1.3", + "version": "1.1.4", "description": "", "private": true, "main": "index.js", diff --git a/examples/typescript-node/src/zeus/const.ts b/examples/typescript-node/src/zeus/const.ts index cb056320..b196c2e1 100644 --- a/examples/typescript-node/src/zeus/const.ts +++ b/examples/typescript-node/src/zeus/const.ts @@ -1,42 +1,56 @@ /* eslint-disable */ export const AllTypesProps: Record = { - SpecialSkills: "enum" as const, - Card:{ - attack:{ - - } - }, - JSON: `scalar.JSON` as const, - Mutation:{ - addCard:{ - card:"createCard" - } - }, Public:{ powerups:{ } }, + SpecialSkills: "enum" as const, Query:{ cardById:{ } }, + Card:{ + attack:{ + + } + }, createCard:{ skills:"SpecialSkills" - } + }, + Mutation:{ + addCard:{ + card:"createCard" + } + }, + JSON: `scalar.JSON` as const } export const ReturnTypes: Record = { - S3Object:{ - bucket:"String", - key:"String", - region:"String" + Public:{ + powerups:"Powerup" }, - ChangeCard:{ - "...on SpecialCard":"SpecialCard", - "...on EffectCard":"EffectCard" + EffectCard:{ + effectSize:"Float", + name:"String" + }, + Nameable:{ + "...on EffectCard": "EffectCard", + "...on Card": "Card", + "...on SpecialCard": "SpecialCard", + "...on CardStack": "CardStack", + name:"String" + }, + Query:{ + cardById:"Card", + drawCard:"Card", + drawChangeCard:"ChangeCard", + listCards:"Card", + myStacks:"CardStack", + nameables:"Nameable", + public:"Public" }, Card:{ Attack:"Int", @@ -51,47 +65,33 @@ export const ReturnTypes: Record = { name:"String", skills:"SpecialSkills" }, - Nameable:{ - "...on Card": "Card", - "...on CardStack": "CardStack", - "...on SpecialCard": "SpecialCard", - "...on EffectCard": "EffectCard", - name:"String" + ChangeCard:{ + "...on SpecialCard":"SpecialCard", + "...on EffectCard":"EffectCard" }, - JSON: `scalar.JSON` as const, Powerup:{ name:"String" }, - Mutation:{ - addCard:"Card" - }, - CardStack:{ - cards:"Card", + SpecialCard:{ + effect:"String", name:"String" }, - Public:{ - powerups:"Powerup" - }, - Query:{ - cardById:"Card", - drawCard:"Card", - drawChangeCard:"ChangeCard", - listCards:"Card", - myStacks:"CardStack", - nameables:"Nameable", - public:"Public" + Mutation:{ + addCard:"Card" }, Subscription:{ deck:"Card" }, - SpecialCard:{ - effect:"String", + CardStack:{ + cards:"Card", name:"String" }, - EffectCard:{ - effectSize:"Float", - name:"String" - } + S3Object:{ + bucket:"String", + key:"String", + region:"String" + }, + JSON: `scalar.JSON` as const } export const Ops = { diff --git a/examples/typescript-node/src/zeus/index.ts b/examples/typescript-node/src/zeus/index.ts index 289a602f..84393dac 100644 --- a/examples/typescript-node/src/zeus/index.ts +++ b/examples/typescript-node/src/zeus/index.ts @@ -815,11 +815,18 @@ export type Variable = { ' __zeus_type': T; }; +export type ExtractVariablesDeep = Query extends Variable + ? { [key in VName]: GetVariableType } + : Query extends string | number | boolean | Array + ? // eslint-disable-next-line @typescript-eslint/ban-types + {} + : UnionToIntersection<{ [K in keyof Query]: WithOptionalNullables> }[keyof Query]>; + export type ExtractVariables = Query extends Variable ? { [key in VName]: GetVariableType } : Query extends [infer Inputs, infer Outputs] - ? ExtractVariables & ExtractVariables - : Query extends string | number | boolean + ? ExtractVariablesDeep & ExtractVariables + : Query extends string | number | boolean | Array ? // eslint-disable-next-line @typescript-eslint/ban-types {} : UnionToIntersection<{ [K in keyof Query]: WithOptionalNullables> }[keyof Query]>; @@ -839,18 +846,36 @@ export type ScalarCoders = { type ZEUS_UNIONS = GraphQLTypes["ChangeCard"] export type ValueTypes = { - /** Aws S3 File */ -["S3Object"]: AliasType<{ - bucket?:boolean | `@${string}`, - key?:boolean | `@${string}`, - region?:boolean | `@${string}`, + ["Public"]: AliasType<{ +powerups?: [{ filter: string | Variable},ValueTypes["Powerup"]], __typename?: boolean | `@${string}` }>; - ["ChangeCard"]: AliasType<{ ["...on SpecialCard"] : ValueTypes["SpecialCard"], - ["...on EffectCard"] : ValueTypes["EffectCard"] + ["SpecialSkills"]:SpecialSkills; + ["EffectCard"]: AliasType<{ + effectSize?:boolean | `@${string}`, + name?:boolean | `@${string}`, + __typename?: boolean | `@${string}` +}>; + ["Nameable"]:AliasType<{ + name?:boolean | `@${string}`; + ['...on EffectCard']?: Omit; + ['...on Card']?: Omit; + ['...on SpecialCard']?: Omit; + ['...on CardStack']?: Omit; + __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"], __typename?: boolean | `@${string}` }>; - ["SpecialSkills"]:SpecialSkills; /** Card used in card game
*/ ["Card"]: AliasType<{ /** The attack power
*/ @@ -873,22 +898,41 @@ attack?: [{ /** Attacked card/card ids
*/ skills?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - ["Nameable"]:AliasType<{ - name?:boolean | `@${string}`; - ['...on Card']?: Omit; - ['...on CardStack']?: Omit; - ['...on SpecialCard']?: Omit; - ['...on EffectCard']?: Omit; + ["ChangeCard"]: AliasType<{ ["...on SpecialCard"] : ValueTypes["SpecialCard"], + ["...on EffectCard"] : ValueTypes["EffectCard"] __typename?: boolean | `@${string}` }>; - ["JSON"]:unknown; + /** create card inputs
*/ +["createCard"]: { + /** 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, + /** Description of a card
*/ + description: string | Variable, + /**
How many children the greek god had
*/ + Children?: number | undefined | null | Variable +}; ["Powerup"]: AliasType<{ name?:boolean | `@${string}`, __typename?: boolean | `@${string}` +}>; + ["SpecialCard"]: AliasType<{ + effect?:boolean | `@${string}`, + name?:boolean | `@${string}`, + __typename?: boolean | `@${string}` }>; ["Mutation"]: AliasType<{ addCard?: [{ card: ValueTypes["createCard"] | Variable},ValueTypes["Card"]], __typename?: boolean | `@${string}` +}>; + ["Subscription"]: AliasType<{ + deck?:ValueTypes["Card"], + __typename?: boolean | `@${string}` }>; /** Stack of cards */ ["CardStack"]: AliasType<{ @@ -896,67 +940,47 @@ addCard?: [{ card: ValueTypes["createCard"] | Variable},ValueTypes[ name?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - ["Public"]: AliasType<{ -powerups?: [{ filter: string | Variable},ValueTypes["Powerup"]], - __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"], - __typename?: boolean | `@${string}` -}>; - ["Subscription"]: AliasType<{ - deck?:ValueTypes["Card"], + /** Aws S3 File */ +["S3Object"]: AliasType<{ + bucket?:boolean | `@${string}`, + key?:boolean | `@${string}`, + region?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - ["SpecialCard"]: AliasType<{ - effect?:boolean | `@${string}`, - name?:boolean | `@${string}`, + ["JSON"]:unknown + } + +export type ResolverInputTypes = { + ["Public"]: AliasType<{ +powerups?: [{ filter: string},ResolverInputTypes["Powerup"]], __typename?: boolean | `@${string}` }>; + ["SpecialSkills"]:SpecialSkills; ["EffectCard"]: AliasType<{ effectSize?:boolean | `@${string}`, name?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - /** create card inputs
*/ -["createCard"]: { - /** 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, - /** The defense power
*/ - Defense: number | Variable, - /** input skills */ - skills?: Array | undefined | null | Variable -} - } - -export type ResolverInputTypes = { - /** Aws S3 File */ -["S3Object"]: AliasType<{ - bucket?:boolean | `@${string}`, - key?:boolean | `@${string}`, - region?:boolean | `@${string}`, + ["Nameable"]:AliasType<{ + name?:boolean | `@${string}`; + ['...on EffectCard']?: Omit; + ['...on Card']?: Omit; + ['...on SpecialCard']?: Omit; + ['...on CardStack']?: Omit; __typename?: boolean | `@${string}` }>; - ["ChangeCard"]: AliasType<{ - SpecialCard?:ResolverInputTypes["SpecialCard"], - EffectCard?:ResolverInputTypes["EffectCard"], + ["Query"]: AliasType<{ +cardById?: [{ cardId?: string | undefined | null},ResolverInputTypes["Card"]], + /** Draw a card
*/ + drawCard?:ResolverInputTypes["Card"], + drawChangeCard?:ResolverInputTypes["ChangeCard"], + /** list All Cards availble
*/ + listCards?:ResolverInputTypes["Card"], + myStacks?:ResolverInputTypes["CardStack"], + nameables?:ResolverInputTypes["Nameable"], + public?:ResolverInputTypes["Public"], __typename?: boolean | `@${string}` }>; - ["SpecialSkills"]:SpecialSkills; /** Card used in card game
*/ ["Card"]: AliasType<{ /** The attack power
*/ @@ -979,74 +1003,57 @@ attack?: [{ /** Attacked card/card ids
*/ skills?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - ["Nameable"]:AliasType<{ - name?:boolean | `@${string}`; - ['...on Card']?: Omit; - ['...on CardStack']?: Omit; - ['...on SpecialCard']?: Omit; - ['...on EffectCard']?: Omit; + ["ChangeCard"]: AliasType<{ + SpecialCard?:ResolverInputTypes["SpecialCard"], + EffectCard?:ResolverInputTypes["EffectCard"], __typename?: boolean | `@${string}` }>; - ["JSON"]:unknown; + /** create card inputs
*/ +["createCard"]: { + /** The attack power
*/ + Attack: number, + /** 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 +}; ["Powerup"]: AliasType<{ name?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - ["Mutation"]: AliasType<{ -addCard?: [{ card: ResolverInputTypes["createCard"]},ResolverInputTypes["Card"]], - __typename?: boolean | `@${string}` -}>; - /** Stack of cards */ -["CardStack"]: AliasType<{ - cards?:ResolverInputTypes["Card"], + ["SpecialCard"]: AliasType<{ + effect?:boolean | `@${string}`, name?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - ["Public"]: AliasType<{ -powerups?: [{ filter: string},ResolverInputTypes["Powerup"]], - __typename?: boolean | `@${string}` -}>; - ["Query"]: AliasType<{ -cardById?: [{ cardId?: string | undefined | null},ResolverInputTypes["Card"]], - /** Draw a card
*/ - drawCard?:ResolverInputTypes["Card"], - drawChangeCard?:ResolverInputTypes["ChangeCard"], - /** list All Cards availble
*/ - listCards?:ResolverInputTypes["Card"], - myStacks?:ResolverInputTypes["CardStack"], - nameables?:ResolverInputTypes["Nameable"], - public?:ResolverInputTypes["Public"], + ["Mutation"]: AliasType<{ +addCard?: [{ card: ResolverInputTypes["createCard"]},ResolverInputTypes["Card"]], __typename?: boolean | `@${string}` }>; ["Subscription"]: AliasType<{ deck?:ResolverInputTypes["Card"], __typename?: boolean | `@${string}` }>; - ["SpecialCard"]: AliasType<{ - effect?:boolean | `@${string}`, + /** Stack of cards */ +["CardStack"]: AliasType<{ + cards?:ResolverInputTypes["Card"], name?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - ["EffectCard"]: AliasType<{ - effectSize?:boolean | `@${string}`, - name?:boolean | `@${string}`, + /** Aws S3 File */ +["S3Object"]: AliasType<{ + bucket?:boolean | `@${string}`, + key?:boolean | `@${string}`, + region?:boolean | `@${string}`, __typename?: boolean | `@${string}` }>; - /** create card inputs
*/ -["createCard"]: { - /** 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, - /** The defense power
*/ - Defense: number, - /** input skills */ - skills?: Array | undefined | null -}; + ["JSON"]:unknown; ["schema"]: AliasType<{ query?:ResolverInputTypes["Query"], mutation?:ResolverInputTypes["Mutation"], @@ -1056,14 +1063,26 @@ cardById?: [{ cardId?: string | undefined | null},ResolverInputTypes["Card"]], } export type ModelTypes = { - /** Aws S3 File */ -["S3Object"]: { - bucket: string, - key: string, - region: string + ["Public"]: { + powerups?: Array | undefined }; - ["ChangeCard"]:ModelTypes["SpecialCard"] | ModelTypes["EffectCard"]; ["SpecialSkills"]:SpecialSkills; + ["EffectCard"]: { + effectSize: number, + name: string +}; + ["Nameable"]: ModelTypes["EffectCard"] | ModelTypes["Card"] | ModelTypes["SpecialCard"] | ModelTypes["CardStack"]; + ["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 +}; /** Card used in card game
*/ ["Card"]: { /** The attack power
*/ @@ -1085,60 +1104,48 @@ export type ModelTypes = { name: string, skills?: Array | undefined }; - ["Nameable"]: ModelTypes["Card"] | ModelTypes["CardStack"] | ModelTypes["SpecialCard"] | ModelTypes["EffectCard"]; - ["JSON"]:any; + ["ChangeCard"]:ModelTypes["SpecialCard"] | ModelTypes["EffectCard"]; + /** create card inputs
*/ +["createCard"]: { + /** The attack power
*/ + Attack: number, + /** 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 +}; ["Powerup"]: { name?: string | undefined +}; + ["SpecialCard"]: { + effect: string, + name: string }; ["Mutation"]: { /** add Card to Cards database
*/ addCard: ModelTypes["Card"] -}; - /** Stack of cards */ -["CardStack"]: { - cards?: Array | undefined, - name: string -}; - ["Public"]: { - powerups?: Array | undefined -}; - ["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 }; ["Subscription"]: { deck?: Array | undefined }; - ["SpecialCard"]: { - effect: string, - name: string -}; - ["EffectCard"]: { - effectSize: number, + /** Stack of cards */ +["CardStack"]: { + cards?: Array | undefined, name: string }; - /** create card inputs
*/ -["createCard"]: { - /** 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 + /** Aws S3 File */ +["S3Object"]: { + bucket: string, + key: string, + region: string }; + ["JSON"]:any; ["schema"]: { query?: ModelTypes["Query"] | undefined, mutation?: ModelTypes["Mutation"] | undefined, @@ -1147,19 +1154,36 @@ export type ModelTypes = { } export type GraphQLTypes = { - /** Aws S3 File */ -["S3Object"]: { - __typename: "S3Object", - bucket: string, - key: string, - region: string + ["Public"]: { + __typename: "Public", + powerups?: Array | undefined }; - ["ChangeCard"]:{ - __typename:"SpecialCard" | "EffectCard" - ['...on SpecialCard']: '__union' & GraphQLTypes["SpecialCard"]; + ["SpecialSkills"]: SpecialSkills; + ["EffectCard"]: { + __typename: "EffectCard", + effectSize: number, + name: string +}; + ["Nameable"]: { + __typename:"EffectCard" | "Card" | "SpecialCard" | "CardStack", + name: string ['...on EffectCard']: '__union' & GraphQLTypes["EffectCard"]; + ['...on Card']: '__union' & GraphQLTypes["Card"]; + ['...on SpecialCard']: '__union' & GraphQLTypes["SpecialCard"]; + ['...on CardStack']: '__union' & GraphQLTypes["CardStack"]; +}; + ["Query"]: { + __typename: "Query", + cardById?: GraphQLTypes["Card"] | undefined, + /** Draw a card
*/ + drawCard: GraphQLTypes["Card"], + drawChangeCard: GraphQLTypes["ChangeCard"], + /** list All Cards availble
*/ + listCards: Array, + myStacks?: Array | undefined, + nameables: Array, + public?: GraphQLTypes["Public"] | undefined }; - ["SpecialSkills"]: SpecialSkills; /** Card used in card game
*/ ["Card"]: { __typename: "Card", @@ -1182,84 +1206,67 @@ export type GraphQLTypes = { name: string, skills?: Array | undefined }; - ["Nameable"]: { - __typename:"Card" | "CardStack" | "SpecialCard" | "EffectCard", - name: string - ['...on Card']: '__union' & GraphQLTypes["Card"]; - ['...on CardStack']: '__union' & GraphQLTypes["CardStack"]; - ['...on SpecialCard']: '__union' & GraphQLTypes["SpecialCard"]; + ["ChangeCard"]:{ + __typename:"SpecialCard" | "EffectCard" + ['...on SpecialCard']: '__union' & GraphQLTypes["SpecialCard"]; ['...on EffectCard']: '__union' & GraphQLTypes["EffectCard"]; }; - ["JSON"]: "scalar" & { name: "JSON" }; + /** create card inputs
*/ +["createCard"]: { + /** The attack power
*/ + Attack: number, + /** 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 +}; ["Powerup"]: { __typename: "Powerup", name?: string | undefined +}; + ["SpecialCard"]: { + __typename: "SpecialCard", + effect: string, + name: string }; ["Mutation"]: { __typename: "Mutation", /** add Card to Cards database
*/ addCard: GraphQLTypes["Card"] -}; - /** Stack of cards */ -["CardStack"]: { - __typename: "CardStack", - cards?: Array | undefined, - name: string -}; - ["Public"]: { - __typename: "Public", - powerups?: Array | undefined -}; - ["Query"]: { - __typename: "Query", - cardById?: GraphQLTypes["Card"] | undefined, - /** Draw a card
*/ - drawCard: GraphQLTypes["Card"], - drawChangeCard: GraphQLTypes["ChangeCard"], - /** list All Cards availble
*/ - listCards: Array, - myStacks?: Array | undefined, - nameables: Array, - public?: GraphQLTypes["Public"] | undefined }; ["Subscription"]: { __typename: "Subscription", deck?: Array | undefined }; - ["SpecialCard"]: { - __typename: "SpecialCard", - effect: string, + /** Stack of cards */ +["CardStack"]: { + __typename: "CardStack", + cards?: Array | undefined, name: string }; - ["EffectCard"]: { - __typename: "EffectCard", - effectSize: number, - name: string + /** Aws S3 File */ +["S3Object"]: { + __typename: "S3Object", + bucket: string, + key: string, + region: string }; - /** create card inputs
*/ -["createCard"]: { - /** 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 -} + ["JSON"]: "scalar" & { name: "JSON" } } 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"]; } \ No newline at end of file diff --git a/examples/typescript-node/zeus.graphql b/examples/typescript-node/zeus.graphql index 56a8d084..66827389 100644 --- a/examples/typescript-node/zeus.graphql +++ b/examples/typescript-node/zeus.graphql @@ -1,28 +1,58 @@ -"""Aws S3 File""" -type S3Object { +"""""" +type Public { """""" - bucket: String! + powerups(filter: String!): [Powerup!] +} + +"""""" +enum SpecialSkills { + """50% chance to avoid any attack
""" + FIRE + + """Lower enemy defense -5
""" + THUNDER + """Attack multiple Cards at once
""" + RAIN +} + +"""""" +type EffectCard implements Nameable { """""" - key: String! + effectSize: Float! """""" - region: String! + name: String! } """""" -union ChangeCard = SpecialCard | EffectCard +interface Nameable { + """""" + name: String! +} """""" -enum SpecialSkills { - """Lower enemy defense -5
""" - THUNDER +type Query { + """""" + cardById(cardId: String): Card - """Attack multiple Cards at once
""" - RAIN + """Draw a card
""" + drawCard: Card! - """50% chance to avoid any attack
""" - FIRE + """""" + drawChangeCard: ChangeCard! + + """list All Cards availble
""" + listCards: [Card!]! + + """""" + myStacks: [CardStack!] + + """""" + nameables: [Nameable!]! + + """""" + public: Public } """Card used in card game
""" @@ -65,13 +95,28 @@ type Card implements Nameable { } """""" -interface Nameable { - """""" +union ChangeCard = SpecialCard | EffectCard + +"""create card inputs
""" +input createCard { + """The attack power
""" + Attack: Int! + + """The defense power
""" + Defense: Int! + + """input skills""" + skills: [SpecialSkills!] + + """The name of a card
""" name: String! -} -"""""" -scalar JSON + """Description of a card
""" + description: String! + + """
How many children the greek god had
""" + Children: Int +} """""" type Powerup { @@ -80,48 +125,18 @@ type Powerup { } """""" -type Mutation { - """add Card to Cards database
""" - addCard(card: createCard!): Card! -} - -"""Stack of cards""" -type CardStack implements Nameable { +type SpecialCard implements Nameable { """""" - cards: [Card!] + effect: String! """""" name: String! } """""" -type Public { - """""" - powerups(filter: String!): [Powerup!] -} - -"""""" -type Query { - """""" - cardById(cardId: String): Card - - """Draw a card
""" - drawCard: Card! - - """""" - drawChangeCard: ChangeCard! - - """list All Cards availble
""" - listCards: [Card!]! - - """""" - myStacks: [CardStack!] - - """""" - nameables: [Nameable!]! - - """""" - public: Public +type Mutation { + """add Card to Cards database
""" + addCard(card: createCard!): Card! } """""" @@ -130,44 +145,29 @@ type Subscription { deck: [Card!] } -"""""" -type SpecialCard implements Nameable { +"""Stack of cards""" +type CardStack implements Nameable { """""" - effect: String! + cards: [Card!] """""" name: String! } -"""""" -type EffectCard implements Nameable { +"""Aws S3 File""" +type S3Object { """""" - effectSize: Float! + bucket: String! """""" - name: String! -} - -"""create card inputs
""" -input createCard { - """The name of a card
""" - name: String! - - """Description of a card
""" - description: String! - - """
How many children the greek god had
""" - Children: Int - - """The attack power
""" - Attack: Int! - - """The defense power
""" - Defense: Int! + key: String! - """input skills""" - skills: [SpecialSkills!] + """""" + region: String! } + +"""""" +scalar JSON schema{ query: Query, mutation: Mutation, diff --git a/package.json b/package.json index 71230bba..062ef81b 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "examples-generate": "npm run generate-typescript-node", "produce-lib": "ts-node libBuilder.ts && eslint packages/graphql-zeus-core/TreeToTS/functions/generated.ts --quiet --fix", "generate-typescript-node": "node ./packages/graphql-zeus/lib/index.js https://faker.graphqleditor.com/a-team/olympus/graphql ./examples/typescript-node/src --n -g ./examples/typescript-node/zeus.graphql --stuccoSubscriptions --td", + "generate-typescript-node-get": "node ./packages/graphql-zeus/lib/index.js https://faker.graphqleditor.com/a-team/olympus/graphql ./examples/typescript-node/src --n -g ./examples/typescript-node/zeus.graphql --method=GET --td", "cli": "node ./packages/graphql-zeus/lib/index.js", "test": "jest" }, diff --git a/packages/graphql-zeus-core/package.json b/packages/graphql-zeus-core/package.json index a6476324..52f6aa7d 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.3.3", + "version": "5.3.4", "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 6d2b205c..ecc875ca 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.3.3", + "version": "5.3.4", "private": false, "main": "./lib/index.js", "author": "GraphQL Editor, Artur Czemiel", diff --git a/packages/graphql-zeus/CLIClass.ts b/packages/graphql-zeus/CLIClass.ts index 25bb553f..b95cf255 100644 --- a/packages/graphql-zeus/CLIClass.ts +++ b/packages/graphql-zeus/CLIClass.ts @@ -29,6 +29,7 @@ interface CliArgs extends Yargs { stuccoSubscriptions?: boolean; typedDocumentNode?: boolean; subscriptions?: string; + method?: string; } /** * Main class for controlling CLI @@ -44,9 +45,9 @@ export class CLI { const schemaFile: string = allArgs[0]; let host: string | undefined; if (schemaFile.startsWith('http://') || schemaFile.startsWith('https://')) { - const { header } = args; + const { header, method } = args; host = schemaFile; - schemaFileContents = await Utils.getFromUrl(schemaFile, header); + schemaFileContents = await Utils.getFromUrl(schemaFile, { header, method: method === 'GET' ? 'GET' : 'POST' }); } schemaFileContents = schemaFileContents || fs.readFileSync(schemaFile).toString(); const pathToFile = allArgs[1] || ''; @@ -59,7 +60,6 @@ export class CLI { const pathToSchema = path.dirname(schemaPath); const schemaFile = path.basename(schemaPath); - writeFileRecursive(pathToSchema, schemaFile, schemaFileContents); } if (args.jsonSchema) { diff --git a/packages/graphql-zeus/Utils/index.ts b/packages/graphql-zeus/Utils/index.ts index acf6cd02..1f193160 100644 --- a/packages/graphql-zeus/Utils/index.ts +++ b/packages/graphql-zeus/Utils/index.ts @@ -7,12 +7,18 @@ export class Utils { /** * Get GraphQL Schema by doing introspection on specified URL */ - static getFromUrl = async (url: string, header?: string | string[]): Promise => { + static getFromUrl = async ( + url: string, + options: { + header?: string | string[]; + method?: 'POST' | 'GET'; + }, + ): Promise => { const headers: Record = { 'Content-Type': 'application/json', }; - if (header) { - const allHeaders: string[] = Array.isArray(header) ? header : [header]; + if (options.header) { + const allHeaders: string[] = Array.isArray(options.header) ? options.header : [options.header]; for (const h of allHeaders) { const [key, ...val] = h.split(':').map((k) => k.trim()); if (!val) { @@ -21,6 +27,18 @@ export class Utils { headers[key] = val.join(':'); } } + if (options.method === 'GET') { + const response = await fetch(url + `?query=${getIntrospectionQuery()}`, { + method: 'GET', + headers, + }); + const { data, errors } = await response.json(); + if (errors) { + throw new Error(JSON.stringify(errors, null, 2)); + } + const c = buildClientSchema(data); + return Utils.printFullSchema(c); + } const response = await fetch(url, { method: 'POST', headers, diff --git a/packages/graphql-zeus/index.ts b/packages/graphql-zeus/index.ts index 6f29c013..4c1abe2c 100644 --- a/packages/graphql-zeus/index.ts +++ b/packages/graphql-zeus/index.ts @@ -41,6 +41,11 @@ zeus [path] [output_path] [options] describe: 'Generate React Query useTypedQuery module', boolean: true, }) + .option('method', { + alias: 'm', + describe: 'provide request method "GET" or "POST" post by default', + choices: ['POST', 'GET'], + }) .option('header', { alias: 'h', describe: diff --git a/packages/graphql-zeus/package.json b/packages/graphql-zeus/package.json index 22972729..e4bf67d4 100644 --- a/packages/graphql-zeus/package.json +++ b/packages/graphql-zeus/package.json @@ -1,6 +1,6 @@ { "name": "graphql-zeus", - "version": "5.3.3", + "version": "5.3.4", "private": false, "scripts": { "start": "ttsc --build tsconfig.build.json --watch", @@ -24,8 +24,8 @@ }, "dependencies": { "cross-fetch": "^3.0.4", - "graphql-zeus-core": "^5.3.3", - "graphql-zeus-jsonschema": "^5.3.3", + "graphql-zeus-core": "^5.3.4", + "graphql-zeus-jsonschema": "^5.3.4", "yargs": "^16.1.1" } }