Skip to content

Commit

Permalink
Added initializer to GarphSchema class
Browse files Browse the repository at this point in the history
  • Loading branch information
mishushakov committed Sep 23, 2023
1 parent f2d3630 commit 3fdff10
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 102 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "git",
"url": "https://github.com/stepci/garph"
},
"version": "0.6.1",
"version": "0.6.2",
"license": "MIT",
"main": "dist/index.js",
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GraphQLResolveInfo } from 'graphql'
import { TSEnumType, UnionToIntersection, getEnumProperties, ObjectToUnion, ExpandRecursively, MaybePromise, MaybeFunction } from './utils'
import { buildSchema, buildSchemaFromTypes, printSchema } from './schema'
import { buildSchema, printSchema } from './schema'

type GraphQLRootType = 'Query' | 'Mutation' | 'Subscription'
type GarphType = 'String' | 'Int' | 'Float' | 'Boolean' | 'ID' | 'ObjectType' | 'InterfaceType' | 'InputType' | 'Scalar' | 'Enum' | 'List' | 'PaginatedList' | 'Union' | 'Ref' | 'Optional' | 'Args' | 'OmitResolver'
Expand Down Expand Up @@ -593,6 +593,10 @@ export class GarphSchema {
after: this.id().optional()
}

constructor ({ types }: { types: AnyType[] } = { types: [] }) {
this.types = types
}

type<N extends string, T extends AnyTypes>(name: N, shape: T) {
const t = new GType<N, T>(name, shape)
this.types.push(t)
Expand Down Expand Up @@ -695,4 +699,4 @@ export class GarphSchema {

export const g = new GarphSchema()

export { buildSchema, buildSchemaFromTypes, printSchema }
export { buildSchema, printSchema }
6 changes: 0 additions & 6 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export function buildSchema({ g, resolvers }: { g: GarphSchema, resolvers?: any
return schemaComposer.buildSchema()
}

export function buildSchemaFromTypes({ types, resolvers }: { types: GarphSchema['types'], resolvers?: any }, config: ConverterConfig = { defaultNullability: false }) {
const schemaComposer = new SchemaComposer();
types.forEach(type => schemaComposer.add(convertToGraphqlType(schemaComposer, type.typeDef.name, type, config, resolvers[type.typeDef.name])))
return schemaComposer.buildSchema()
}

function isOptional(target: string, type: AnyType, config: ConverterConfig) {
return type.typeDef.isRequired ? `${target}!` : type.typeDef.isOptional ? `${target}` : config.defaultNullability ? `${target}` : `${target}!`
}
Expand Down
51 changes: 31 additions & 20 deletions www/api/classes/GarphSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@

### constructor

**new GarphSchema**()
**new GarphSchema**(`«destructured»?`)

#### Parameters

| Name | Type |
| :------ | :------ |
| `«destructured»` | `Object` |
| › `types` | [`AnyType`](../index.md#anytype)[] |

#### Defined in

[index.ts:596](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L596)

## Properties

Expand All @@ -16,7 +27,7 @@

#### Defined in

[index.ts:578](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L578)
[index.ts:578](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L578)

___

Expand All @@ -35,7 +46,7 @@ ___

#### Defined in

[index.ts:589](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L589)
[index.ts:589](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L589)

___

Expand All @@ -45,7 +56,7 @@ ___

#### Defined in

[index.ts:582](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L582)
[index.ts:582](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L582)

___

Expand All @@ -55,7 +66,7 @@ ___

#### Defined in

[index.ts:577](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L577)
[index.ts:577](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L577)

## Methods

Expand All @@ -69,7 +80,7 @@ ___

#### Defined in

[index.ts:677](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L677)
[index.ts:681](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L681)

___

Expand Down Expand Up @@ -97,7 +108,7 @@ ___

#### Defined in

[index.ts:608](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L608)
[index.ts:612](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L612)

___

Expand Down Expand Up @@ -125,7 +136,7 @@ ___

#### Defined in

[index.ts:618](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L618)
[index.ts:622](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L622)

___

Expand Down Expand Up @@ -153,7 +164,7 @@ ___

#### Defined in

[index.ts:637](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L637)
[index.ts:641](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L641)

___

Expand All @@ -167,7 +178,7 @@ ___

#### Defined in

[index.ts:673](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L673)
[index.ts:677](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L677)

___

Expand All @@ -181,7 +192,7 @@ ___

#### Defined in

[index.ts:665](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L665)
[index.ts:669](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L669)

___

Expand Down Expand Up @@ -209,7 +220,7 @@ ___

#### Defined in

[index.ts:631](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L631)
[index.ts:635](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L635)

___

Expand All @@ -223,7 +234,7 @@ ___

#### Defined in

[index.ts:669](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L669)
[index.ts:673](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L673)

___

Expand Down Expand Up @@ -251,7 +262,7 @@ ___

#### Defined in

[index.ts:655](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L655)
[index.ts:659](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L659)

___

Expand Down Expand Up @@ -279,7 +290,7 @@ ___

#### Defined in

[index.ts:602](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L602)
[index.ts:606](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L606)

___

Expand All @@ -305,7 +316,7 @@ ___

#### Defined in

[index.ts:683](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L683)
[index.ts:687](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L687)

___

Expand Down Expand Up @@ -333,7 +344,7 @@ ___

#### Defined in

[index.ts:649](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L649)
[index.ts:653](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L653)

___

Expand All @@ -347,7 +358,7 @@ ___

#### Defined in

[index.ts:661](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L661)
[index.ts:665](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L665)

___

Expand Down Expand Up @@ -375,7 +386,7 @@ ___

#### Defined in

[index.ts:596](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L596)
[index.ts:600](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L600)

___

Expand Down Expand Up @@ -403,4 +414,4 @@ ___

#### Defined in

[index.ts:643](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L643)
[index.ts:647](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L647)
18 changes: 9 additions & 9 deletions www/api/classes/Type.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#### Defined in

[index.ts:13](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L13)
[index.ts:13](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L13)

___

Expand All @@ -40,7 +40,7 @@ ___

#### Defined in

[index.ts:11](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L11)
[index.ts:11](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L11)

___

Expand All @@ -50,7 +50,7 @@ ___

#### Defined in

[index.ts:10](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L10)
[index.ts:10](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L10)

___

Expand All @@ -60,7 +60,7 @@ ___

#### Defined in

[index.ts:9](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L9)
[index.ts:9](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L9)

___

Expand All @@ -70,7 +70,7 @@ ___

#### Defined in

[index.ts:12](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L12)
[index.ts:12](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L12)

___

Expand All @@ -80,7 +80,7 @@ ___

#### Defined in

[index.ts:14](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L14)
[index.ts:14](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L14)

___

Expand All @@ -90,7 +90,7 @@ ___

#### Defined in

[index.ts:15](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L15)
[index.ts:15](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L15)

## Methods

Expand All @@ -110,7 +110,7 @@ ___

#### Defined in

[index.ts:22](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L22)
[index.ts:22](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L22)

___

Expand All @@ -130,4 +130,4 @@ ___

#### Defined in

[index.ts:17](https://github.com/stepci/garph/blob/1256b62/src/index.ts#L17)
[index.ts:17](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L17)
Loading

0 comments on commit 3fdff10

Please sign in to comment.