Skip to content

Commit 34f7ccd

Browse files
committed
Update the custom schema loader
1 parent d7adf7c commit 34f7ccd

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

packages/atlas/codegen.config.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { CodegenConfig } from '@graphql-codegen/cli'
2+
import * as assert from 'assert'
23

34
import { customSchemaLoader } from './scripts/customSchemaLoader'
45

5-
const schemaUrl = 'https://orion.gleev.xyz/graphql'
6+
const NODE_ENV = process.env.NODE_ENV?.toUpperCase() ?? 'PRODUCTION'
7+
const schemaUrl = process.env[`VITE_${NODE_ENV}_ORION_URL`]
8+
const authUrl = process.env[`VITE_${NODE_ENV}_ORION_AUTH_URL`]
9+
assert(schemaUrl)
10+
assert(authUrl)
611

712
const config: CodegenConfig = {
813
overwrite: true,
@@ -13,7 +18,7 @@ const config: CodegenConfig = {
1318
[schemaUrl]: {
1419
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1520
// @ts-ignore
16-
loader: customSchemaLoader,
21+
loader: customSchemaLoader(schemaUrl, `${authUrl}/anonymous-auth`),
1722
},
1823
},
1924
],
+29-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import axios from 'axios'
22
import { buildClientSchema, getIntrospectionQuery } from 'graphql'
33

4-
async function fetchAuthCookie() {
4+
async function fetchAuthCookie(authUrl: string) {
55
const response = await axios.post(
6-
`https://auth.gleev.xyz/api/v1/anonymous-auth`,
6+
authUrl,
77
{},
88
{
99
method: 'POST',
@@ -17,30 +17,34 @@ async function fetchAuthCookie() {
1717
return response.headers['set-cookie']
1818
}
1919

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()
2324

24-
if (!authCookie) {
25-
throw new Error('Authorization cookie is missing.')
26-
}
25+
if (!authCookie) {
26+
throw new Error('Authorization cookie is missing.')
27+
}
2728

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,
4035
},
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+
}
4650
}

packages/atlas/src/.env

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ VITE_NEXT_FAUCET_URL=https://atlas-next.joystream.org/member-faucet/register
5454
VITE_NEXT_YPP_FAUCET_URL=https://52.204.147.11.nip.io/membership
5555

5656
# Local development env URLs
57-
VITE_LOCAL_ORION_URL=http://localhost:6116/graphql
57+
VITE_LOCAL_ORION_AUTH_URL=http://localhost:4074/api/v1
58+
VITE_LOCAL_ORION_URL=http://localhost:4350/graphql
5859
VITE_LOCAL_QUERY_NODE_SUBSCRIPTION_URL=ws://localhost:8081/graphql
5960
VITE_LOCAL_NODE_URL=ws://localhost:9944/ws-rpc
6061
VITE_LOCAL_FAUCET_URL=http://localhost:3002/register
62+
VITE_LOCAL_YPP_FAUCET_URL=https://52.204.147.11.nip.io/membership
6163

6264
VITE_SENTRY_AUTH_TOKEN=

0 commit comments

Comments
 (0)