/
custom-type-resolver.ts
91 lines (80 loc) · 2.64 KB
/
custom-type-resolver.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
import {
GraphQLBoolean,
GraphQLFloat,
GraphQLID,
GraphQLInputType,
GraphQLInt,
GraphQLOutputType,
GraphQLScalarType,
GraphQLString,
} from 'graphql';
import { GraphQLDate, GraphQLDateTime, GraphQLTime } from 'graphql-scalars';
/**
* Resolver that converts WSDL types, that are not fully defined in the WSDL itself, to GraphQL types.
* This is especially necessary for all primitive WSDL types (resp. scalar GraphQL types) like 'string', 'datetime', etc.
*
* You can provide your own resolver to handle custom types of your WSDL.
* But you must still provide resolvment for primitive types like 'string', e.g by re-using DefaultTypeResolver.
*/
export interface CustomTypeResolver {
outputType(typeName: string, namespace: string): GraphQLOutputType;
inputType(typeName: string, namespace: string): GraphQLInputType;
}
/**
* Default implementation of CustomTypeResolver.
* Based on https://www.w3.org/TR/xmlschema-2/#built-in-datatypes
*/
export class DefaultTypeResolver implements CustomTypeResolver {
string = GraphQLString;
base64Binary = GraphQLString;
hexBinary = GraphQLString;
duration = GraphQLString;
gYearMonth = GraphQLString;
gYear = GraphQLString;
gMonthDay = GraphQLString;
gDay = GraphQLString;
gMonth = GraphQLString;
anyURI = GraphQLString;
QName = GraphQLString;
normalizedString = GraphQLString;
token = GraphQLString;
NMTOKEN = GraphQLString;
NMTOKENS = GraphQLString;
language = GraphQLString;
Name = GraphQLString;
NCName = GraphQLString;
IDREF = GraphQLString;
IDREFS = GraphQLString;
ENTITY = GraphQLString;
ENTITIES = GraphQLString;
ID = GraphQLID;
boolean = GraphQLBoolean;
byte = GraphQLInt;
unsignedByte = GraphQLInt;
short = GraphQLInt;
unsignedShort = GraphQLInt;
int = GraphQLInt;
unsignedInt = GraphQLInt;
integer = GraphQLInt;
positiveInteger = GraphQLInt;
nonPositiveInteger = GraphQLInt;
negativeInteger = GraphQLInt;
nonNegativeInteger = GraphQLInt;
long = GraphQLInt;
unsignedLong = GraphQLInt;
decimal = GraphQLFloat;
float = GraphQLFloat;
double = GraphQLFloat;
dateTime = GraphQLDateTime;
date = GraphQLDate;
time = GraphQLTime;
resolve(typeName: string, namespace: string): GraphQLScalarType {
return this[`${namespace}:${typeName}`] || this[typeName];
}
outputType(typeName: string, namespace: string): GraphQLOutputType {
return this.resolve(typeName, namespace);
}
inputType(typeName: string, namespace: string): GraphQLInputType {
return this.resolve(typeName, namespace);
}
}