FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
GraphQL/reverse_engineering/api.js at develop · hackolade/GraphQL · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
hackolade
/
GraphQL
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
1
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
GraphQL
/
reverse_engineering
/
api.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
150 lines (132 loc) · 5.43 KB
Breadcrumbs
GraphQL
/
reverse_engineering
/
api.js
Copy path
File metadata and controls
150 lines (132 loc) · 5.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/**
*
@import
{FileREData, REFromFileCallback, TestConnectionInfo, TestConnectionCallback, DisconnectCallback, REConnectionInfo, Logger, InstanceREEntityResponseData, REFromInstanceCallback} from "../shared/types/types"
*/
const
{
getFileName
}
=
require
(
'./helpers/getFileName'
)
;
const
{
parseSchema
}
=
require
(
'./helpers/parseSchema'
)
;
const
{
readFileContent
}
=
require
(
'./helpers/readFileContent'
)
;
const
{
getMappedSchemaFromFile
,
getMappedSchemaFromInstance
}
=
require
(
'./mappers/schema'
)
;
const
{
fetchIntrospectionSchema
}
=
require
(
'./helpers/fetchIntrospectionSchema'
)
;
const
{
convertIntrospectionSchemaToGraphQLSchema
}
=
require
(
'./helpers/convertIntrospectionSchemaToGraphQLSchema'
)
;
const
{
mapError
}
=
require
(
'./helpers/mapError'
)
;
const
{
FetchIntrospectionSchemaError
}
=
require
(
'./errors/FetchIntrospectionSchemaError'
)
;
module
.
exports
=
{
/**
* Common disconnect method - not needed for GraphQL API
*
*
@param
{
REConnectionInfo
} _connectionInfo
*
@param
{
Logger
} _logger
*
@param
{
DisconnectCallback
} callback
*/
disconnect
(
_connectionInfo
,
_logger
,
callback
)
{
callback
(
)
;
}
,
/**
* Test a connection to the GraphQL server - executes introspection query
*
*
@param
{
TestConnectionInfo
} connectionInfo
*
@param
{
Logger
} logger
*
@param
{
TestConnectionCallback
} callback
*
@returns
{
Promise<void>
}
*/
async
testConnection
(
connectionInfo
,
logger
,
callback
)
{
const
testConnectionTitle
=
'Test connection'
;
try
{
logger
.
clear
(
)
;
logger
.
log
(
'info'
,
connectionInfo
,
testConnectionTitle
,
connectionInfo
.
hiddenKeys
)
;
logger
.
log
(
'info'
,
'Start test connection'
,
testConnectionTitle
)
;
await
fetchIntrospectionSchema
(
{
connectionInfo
}
)
;
logger
.
log
(
'info'
,
'Test connection successful'
,
testConnectionTitle
)
;
callback
(
)
;
}
catch
(
error
)
{
logger
.
log
(
'error'
,
error
,
testConnectionTitle
)
;
const
message
=
error
instanceof
Error
?
error
?.
message
:
testConnectionTitle
;
const
stack
=
error
instanceof
Error
?
error
?.
stack
:
undefined
;
const
customMsgCode
=
error
instanceof
FetchIntrospectionSchemaError
?
error
?.
customMsgCode
:
undefined
;
callback
(
{
message
,
stack
,
customMsgCode
}
)
;
}
}
,
/**
*
@param
{
REConnectionInfo
} data
*
@param
{
Logger
} logger - Logger instance
*
@param
{
REFromInstanceCallback
} callback
*
@returns
{
Promise<void>
}
*/
async
getDbCollectionsData
(
data
,
logger
,
callback
)
{
try
{
logger
.
clear
(
)
;
const
logTitle
=
'RE schema from GraphQL server'
;
logger
.
log
(
'info'
,
data
.
connectionSettings
,
logTitle
,
data
.
hiddenKeys
)
;
logger
.
progress
(
{
message
:
'Start reverse engineering ...'
,
containerName
:
''
,
entityName
:
''
}
)
;
logger
.
log
(
'info'
,
'Fetching Introspection schema'
,
logTitle
)
;
logger
.
progress
(
{
message
:
'Fetching Introspection schema from GraphQL server'
,
containerName
:
''
,
entityName
:
''
,
}
)
;
const
introspectionSchema
=
await
fetchIntrospectionSchema
(
{
connectionInfo
:
data
.
connectionSettings
,
}
)
;
logger
.
log
(
'info'
,
'Converting Introspection schema to GraphQL SDL schema'
,
logTitle
)
;
logger
.
progress
(
{
message
:
'Converting Introspection schema to GraphQL SDL schema'
,
containerName
:
''
,
entityName
:
''
,
}
)
;
const
graphQLSDLSchema
=
convertIntrospectionSchemaToGraphQLSchema
(
introspectionSchema
)
;
logger
.
log
(
'info'
,
'Parsing GraphQL SQL schema'
,
logTitle
)
;
logger
.
progress
(
{
message
:
'Parsing GraphQL SQL schema'
,
containerName
:
''
,
entityName
:
''
}
)
;
const
{
parsedSchema
}
=
parseSchema
(
{
schemaContent
:
graphQLSDLSchema
}
)
;
logger
.
log
(
'info'
,
'Converting the parsed GraphQL schema to internal RE schema'
,
logTitle
)
;
const
mappedEntities
=
getMappedSchemaFromInstance
(
{
schemaItems
:
[
...
parsedSchema
.
definitions
]
,
graphName
:
'New Graph'
,
logger
,
}
)
;
callback
(
null
,
mappedEntities
)
;
}
catch
(
error
)
{
const
title
=
'Failed to RE schema from GraphQL server'
;
logger
.
log
(
'error'
,
error
,
title
)
;
const
message
=
error
instanceof
Error
?
error
?.
message
:
title
;
const
stack
=
error
instanceof
Error
?
error
?.
stack
:
undefined
;
const
customMsgCode
=
error
instanceof
FetchIntrospectionSchemaError
?
error
?.
customMsgCode
:
undefined
;
callback
(
{
message
,
stack
,
customMsgCode
}
)
;
}
}
,
/**
* RE a GraphQL schema file and returns the mapped schema
*
*
@param
{
FileREData
} data
*
@param
{
Logger
} logger
*
@param
{
REFromFileCallback
} callback
*/
async
reFromFile
(
data
,
logger
,
callback
)
{
try
{
logger
.
clear
(
)
;
logger
.
log
(
'info'
,
'Start RE from file process'
,
'RE from file'
)
;
const
fieldsOrder
=
data
.
fieldInference
.
active
;
const
fileContent
=
await
readFileContent
(
{
filePath
:
data
.
filePath
}
)
;
const
fileName
=
getFileName
(
data
.
filePath
)
;
const
{
parsedSchema
,
validationErrors
}
=
parseSchema
(
{
schemaContent
:
fileContent
}
)
;
let
warning
;
if
(
Array
.
isArray
(
validationErrors
)
&&
validationErrors
.
length
>
0
)
{
warning
=
{
title
:
'Anomalies were detected during reverse-engineering'
,
message
:
'Review the log file for more details.'
,
openLog
:
true
,
}
;
logger
.
log
(
'error'
,
{
validationErrors
}
,
'[Warning] Invalid GraphQL Schema'
)
;
}
const
mappedEntities
=
getMappedSchemaFromFile
(
{
schemaItems
:
[
...
parsedSchema
.
definitions
]
,
graphName
:
fileName
,
logger
,
fieldsOrder
,
}
)
;
callback
(
null
,
mappedEntities
,
{
warning
}
,
[
]
,
'multipleSchema'
)
;
}
catch
(
error
)
{
logger
.
log
(
'error'
,
error
,
'Failed to read GraphQL schema file'
)
;
const
mappedError
=
mapError
(
error
)
;
callback
(
mappedError
)
;
}
}
,
}
;
Back
|
FazBrowse Home
|
New Git URL