-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
TypeMapper.d.ts
156 lines (127 loc) · 4.6 KB
/
TypeMapper.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import {
DocumentNode,
GraphQLArgumentConfig,
GraphQLFieldConfig,
GraphQLFieldConfigArgumentMap,
GraphQLFieldConfigMap,
GraphQLInputFieldConfig,
GraphQLInputFieldConfigMap,
GraphQLNamedType,
GraphQLType,
GraphQLObjectType,
} from 'graphql';
import { SchemaComposer, AnyComposeType, AnyType } from './SchemaComposer';
import { ComposeInputFieldConfig, ComposeInputFieldConfigMap } from './InputTypeComposer';
import {
ObjectTypeComposer,
ComposeArgumentConfig,
ComposeFieldConfig,
ComposeFieldConfigArgumentMap,
ComposeFieldConfigMap,
ComposeObjectType,
} from './ObjectTypeComposer';
import { TypeDefinitionString, TypeNameString, TypeWrappedString } from './TypeMapper';
import { TypeStorage } from './TypeStorage';
/**
* Eg. `type Name { field: Int }`
*/
export type TypeDefinitionString = string;
/**
* Eg. `Int`, `Int!`, `[Int]`
*/
export type TypeWrappedString = string;
/**
* Eg. `Int`, `Float`
*/
export type TypeNameString = string;
export type TypeAsString = TypeDefinitionString | TypeWrappedString | TypeNameString;
/**
* Type storage and type generator from `Schema Definition Language` (`SDL`).
* This is slightly rewritten [buildASTSchema](https://github.com/graphql/graphql-js/blob/master/src/utilities/buildASTSchema.js)
* utility from `graphql-js` that allows to create type from a string (SDL).
*/
declare class TypeMapper<TContext> {
public schemaComposer: SchemaComposer<TContext>;
protected basicScalars: Map<string, GraphQLNamedType>;
public constructor(schemaComposer: SchemaComposer<TContext>);
/**
* Check that string is a valid GraphQL Type name.
* According to spec valid mask is `/^[_A-Za-z][_0-9A-Za-z]*$/`.
*/
public static isTypeNameString(str: string): boolean;
/**
* Checks that string is SDL definition of some type
* eg. `type Out { name: String! }` or `input Filter { minAge: Int }` etc.
*/
public static isTypeDefinitionString(str: string): boolean;
/**
* Checks that string is OutputType SDL definition
* eg. `type Out { name: String! }`
*/
public static isOutputTypeDefinitionString(str: string): boolean;
/**
* Checks that string is InputType SDL definition
* eg. `input Filter { minAge: Int }`
*/
public static isInputTypeDefinitionString(str: string): boolean;
/**
* Checks that string is EnumType SDL definition
* eg. `enum Sort { ASC DESC }`
*/
public static isEnumTypeDefinitionString(str: string): boolean;
/**
* Checks that string is ScalarType SDL definition
* eg. `scalar UInt`
*/
public static isScalarTypeDefinitionString(str: string): boolean;
/**
* Checks that string is InterfaceType SDL definition
* eg. `interface User { name: String }`
*/
public static isInterfaceTypeDefinitionString(str: string): boolean;
public get(name: string): GraphQLNamedType | void;
public set(name: string, type: AnyType<any>): void;
public has(name: string): boolean;
public getWrapped(str: TypeWrappedString | TypeNameString): GraphQLType | null;
public createType(str: TypeDefinitionString): AnyComposeType<TContext> | void;
public createGraphQLType(str: TypeDefinitionString): GraphQLType | void;
public parseTypesFromString(str: string): TypeStorage<string, AnyComposeType<TContext>>;
public parseTypesFromAst(astDocument: DocumentNode): TypeStorage<string, GraphQLNamedType>;
public convertOutputType(composeType: ComposeObjectType): GraphQLObjectType;
public convertOutputFieldConfig<TSource = any, TContext = any>(
composeFC: ComposeFieldConfig<TSource, TContext>,
fieldName?: string,
typeName?: string
): GraphQLFieldConfig<TSource, TContext>;
public convertOutputFieldConfigMap<TSource = any, TContext = any>(
composeFields:
| ComposeFieldConfigMap<TSource, TContext>
| GraphQLFieldConfigMap<TSource, TContext>,
typeName?: string
): GraphQLFieldConfigMap<TSource, TContext>;
public convertArgConfig(
composeAC: ComposeArgumentConfig,
argName?: string,
fieldName?: string,
typeName?: string
): GraphQLArgumentConfig;
public convertArgConfigMap(
composeArgsConfigMap: ComposeFieldConfigArgumentMap<any>,
fieldName?: string,
typeName?: string
): GraphQLFieldConfigArgumentMap;
public convertInputFieldConfig(
composeIFC: ComposeInputFieldConfig,
fieldName?: string,
typeName?: string
): GraphQLInputFieldConfig;
public convertInputFieldConfigMap(
composeFields: ComposeInputFieldConfigMap,
typeName?: string
): GraphQLInputFieldConfigMap;
/**
* -----------------------------------------------
* Internal methods
* -----------------------------------------------
*/
}