1
1
import axios from 'axios'
2
2
import { buildClientSchema , getIntrospectionQuery } from 'graphql'
3
3
4
- async function fetchAuthCookie ( ) {
4
+ async function fetchAuthCookie ( authUrl : string ) {
5
5
const response = await axios . post (
6
- `https://auth.gleev.xyz/api/v1/anonymous-auth` ,
6
+ authUrl ,
7
7
{ } ,
8
8
{
9
9
method : 'POST' ,
@@ -17,30 +17,34 @@ async function fetchAuthCookie() {
17
17
return response . headers [ 'set-cookie' ]
18
18
}
19
19
20
- export async function customSchemaLoader ( ) {
21
- const authCookie = await fetchAuthCookie ( )
22
- const introspectionQuery = getIntrospectionQuery ( )
20
+ export function customSchemaLoader ( schemaUrl : string , authUrl : string ) {
21
+ return async ( ) => {
22
+ const authCookie = await fetchAuthCookie ( authUrl )
23
+ const introspectionQuery = getIntrospectionQuery ( )
23
24
24
- if ( ! authCookie ) {
25
- throw new Error ( 'Authorization cookie is missing.' )
26
- }
25
+ if ( ! authCookie ) {
26
+ throw new Error ( 'Authorization cookie is missing.' )
27
+ }
27
28
28
- const schemaResponse = await axios
29
- . post < any > (
30
- 'https://orion.gleev.xyz/graphql' ,
31
- {
32
- query : introspectionQuery ,
33
- } ,
34
- {
35
- method : 'post' ,
36
- withCredentials : true ,
37
- headers : {
38
- Cookie : authCookie . join ( '; ' ) ,
39
- 'Content-Type' : 'application/json' ,
29
+ const schemaResponse = await axios
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ . post < any > (
32
+ schemaUrl ,
33
+ {
34
+ query : introspectionQuery ,
40
35
} ,
41
- }
42
- )
43
- . catch ( ( error ) => console . log ( error . response . data ) )
44
- const schema = buildClientSchema ( schemaResponse && schemaResponse . data . data )
45
- return schema
36
+ {
37
+ method : 'post' ,
38
+ withCredentials : true ,
39
+ headers : {
40
+ Cookie : authCookie . join ( '; ' ) ,
41
+ 'Content-Type' : 'application/json' ,
42
+ } ,
43
+ }
44
+ )
45
+ // eslint-disable-next-line no-console
46
+ . catch ( ( error ) => console . log ( error . response . data ) )
47
+ const schema = buildClientSchema ( schemaResponse && schemaResponse . data . data )
48
+ return schema
49
+ }
46
50
}
0 commit comments