Skip to content

Commit

Permalink
Changed types holder to Map
Browse files Browse the repository at this point in the history
  • Loading branch information
mishushakov committed Jan 24, 2024
1 parent 11bfe12 commit ca1b8bd
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 78 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.

4 changes: 2 additions & 2 deletions 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.5",
"version": "0.6.6",
"license": "MIT",
"main": "dist/index.js",
"scripts": {
Expand All @@ -15,7 +15,7 @@
"build": "tsc -p tsconfig.json",
"postbuild": "typedoc --readme none --entryDocument index.md --plugin typedoc-plugin-markdown --tsconfig tsconfig.json --hideInPageTOC true --out www/api src/index.ts",
"ts:check": "tsc -p tsconfig.test.json",
"test": "ts-node examples/relay.ts"
"test": "ts-node examples/promo.ts"
},
"devDependencies": {
"@graphql-yoga/plugin-defer-stream": "^2.0.4",
Expand Down
10 changes: 3 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ class GArgs<T extends AnyType, X extends Args> extends Type<T, 'Args'> {
}

export class GarphSchema {
types: AnyType[] = []
types: Map<string, AnyType> = new Map()

nodeType = this.interface('Node', {
id: this.id()
Expand All @@ -618,12 +618,8 @@ export class GarphSchema {

registerType(type: AnyType) {
const name = type.typeDef.name
if (name) {
if (this.types.find(t => t.typeDef.name === name)) {
throw new Error(`Detected multiple types with name: ${name}`)
}
}
this.types.push(type)
if (this.types.has(name)) throw new Error(`Type with name "${name}" already exists`)
this.types.set(name, type)
}

constructor ({ types }: { types: AnyType[] } = { types: [] }) {
Expand Down
44 changes: 22 additions & 22 deletions www/api/classes/GarphSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#### Defined in

[index.ts:629](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L629)
[index.ts:625](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L625)

## Properties

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

#### Defined in

[index.ts:601](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L601)
[index.ts:601](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L601)

___

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

#### Defined in

[index.ts:612](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L612)
[index.ts:612](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L612)

___

Expand All @@ -56,17 +56,17 @@ ___

#### Defined in

[index.ts:605](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L605)
[index.ts:605](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L605)

___

### types

**types**: [`AnyType`](../index.md#anytype)[] = `[]`
**types**: `Map`<`string`, [`AnyType`](../index.md#anytype)\>

#### Defined in

[index.ts:599](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L599)
[index.ts:599](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L599)

## Methods

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

#### Defined in

[index.ts:714](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L714)
[index.ts:710](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L710)

___

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

#### Defined in

[index.ts:645](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L645)
[index.ts:641](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L641)

___

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

#### Defined in

[index.ts:655](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L655)
[index.ts:651](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L651)

___

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

#### Defined in

[index.ts:674](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L674)
[index.ts:670](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L670)

___

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

#### Defined in

[index.ts:710](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L710)
[index.ts:706](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L706)

___

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

#### Defined in

[index.ts:702](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L702)
[index.ts:698](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L698)

___

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

#### Defined in

[index.ts:668](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L668)
[index.ts:664](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L664)

___

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

#### Defined in

[index.ts:706](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L706)
[index.ts:702](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L702)

___

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

#### Defined in

[index.ts:692](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L692)
[index.ts:688](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L688)

___

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

#### Defined in

[index.ts:639](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L639)
[index.ts:635](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L635)

___

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

#### Defined in

[index.ts:720](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L720)
[index.ts:716](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L716)

___

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

#### Defined in

[index.ts:619](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L619)
[index.ts:619](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L619)

___

Expand Down Expand Up @@ -364,7 +364,7 @@ ___

#### Defined in

[index.ts:686](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L686)
[index.ts:682](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L682)

___

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

#### Defined in

[index.ts:698](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L698)
[index.ts:694](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L694)

___

Expand Down Expand Up @@ -406,7 +406,7 @@ ___

#### Defined in

[index.ts:633](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L633)
[index.ts:629](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L629)

___

Expand Down Expand Up @@ -434,4 +434,4 @@ ___

#### Defined in

[index.ts:680](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L680)
[index.ts:676](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L676)
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/45f35d4/src/index.ts#L13)
[index.ts:13](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L13)

___

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

#### Defined in

[index.ts:11](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L11)
[index.ts:11](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L11)

___

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

#### Defined in

[index.ts:10](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L10)
[index.ts:10](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L10)

___

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

#### Defined in

[index.ts:9](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L9)
[index.ts:9](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L9)

___

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

#### Defined in

[index.ts:12](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L12)
[index.ts:12](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L12)

___

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

#### Defined in

[index.ts:14](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L14)
[index.ts:14](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L14)

___

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

#### Defined in

[index.ts:15](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L15)
[index.ts:15](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L15)

## Methods

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

#### Defined in

[index.ts:22](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L22)
[index.ts:22](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L22)

___

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

#### Defined in

[index.ts:17](https://github.com/stepci/garph/blob/45f35d4/src/index.ts#L17)
[index.ts:17](https://github.com/stepci/garph/blob/11bfe12/src/index.ts#L17)
Loading

0 comments on commit ca1b8bd

Please sign in to comment.