1 | import type { Values } from '../../lib/prelude.js'
|
2 | import type { TSError } from '../../lib/TSError.js'
|
3 | import type { Schema } from '../1_Schema/__.js'
|
4 |
|
5 | declare global {
|
6 | export namespace GraphQLRequestTypes {
|
7 | interface Schemas {}
|
8 |
|
9 |
|
10 | }
|
11 | }
|
12 |
|
13 | type SomeSchema = {
|
14 | index: Schema.Index
|
15 | customScalars: Record<string, Schema.Scalar.Scalar>
|
16 | featureOptions: {
|
17 | schemaErrors: boolean
|
18 | }
|
19 | }
|
20 |
|
21 | type ZeroSchema = {
|
22 | index: { name: never }
|
23 | featureOptions: {
|
24 | schemaErrors: false
|
25 | }
|
26 | }
|
27 |
|
28 | export type GlobalRegistry = Record<string, SomeSchema>
|
29 |
|
30 | export namespace GlobalRegistry {
|
31 | export type Schemas = GraphQLRequestTypes.Schemas
|
32 |
|
33 | export type IsEmpty = keyof Schemas extends never ? true : false
|
34 |
|
35 | export type SchemaList = IsEmpty extends true ? ZeroSchema : Values<Schemas>
|
36 |
|
37 | export type DefaultSchemaName = 'default'
|
38 |
|
39 | export type SchemaNames = keyof GraphQLRequestTypes.Schemas extends never
|
40 | ? TSError<'SchemaNames', 'No schemas have been registered. Did you run graphql-request generate?'>
|
41 | : keyof GraphQLRequestTypes.Schemas
|
42 |
|
43 | export type HasSchemaErrors<$Schema extends SchemaList> = $Schema['featureOptions']['schemaErrors']
|
44 |
|
45 | export type HasSchemaErrorsViaName<$Name extends SchemaNames> =
|
46 |
|
47 |
|
48 |
|
49 | GraphQLRequestTypes.Schemas[$Name]['featureOptions']['schemaErrors']
|
50 |
|
51 |
|
52 |
|
53 | export type GetSchemaIndex<$Name extends SchemaNames> = GraphQLRequestTypes.Schemas[$Name]['index']
|
54 |
|
55 |
|
56 |
|
57 | export type SchemaIndexDefault = GetSchemaIndex<DefaultSchemaName>
|
58 |
|
59 | export type GetSchemaIndexOrDefault<$Name extends SchemaNames | undefined> = $Name extends SchemaNames
|
60 | ? GetSchemaIndex<$Name>
|
61 | : SchemaIndexDefault
|
62 | }
|