Skip to content

Commit dc5822b

Browse files
committed
refactor(scheduler-utils)!: accept GRAPHQL_URL instead of GATEWAY_URL #551
1 parent 49a0152 commit dc5822b

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

scheduler-utils/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ The default size of the cache is `100`. If you'd like a smaller or larger cache,
9696
If you would like to use config other than the defaults, you can
9797
specify those coonfigurations by providing their values `connect`. You can currently specify
9898

99-
- The `GATEWAY_URL`
99+
- The `GRAPHQL_URL`
100100
- The In-Memory `cacheSize`
101101
- Following Redirects `followRedirects`, a boolean that optimizes scheduler routing if `true`
102102

scheduler-utils/src/client/gateway.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ const findTransactionTags = (err) => pipe(
2222
defaultTo([])
2323
)
2424

25-
function gatewayWith ({ fetch, GATEWAY_URL }) {
25+
function gatewayWith ({ fetch, GRAPHQL_URL }) {
2626
return async ({ query, variables }) => {
27-
return fetch(`${GATEWAY_URL}/graphql`, {
27+
return fetch(GRAPHQL_URL, {
2828
method: 'POST',
2929
headers: { 'Content-Type': 'application/json' },
3030
body: JSON.stringify({ query, variables })
@@ -33,9 +33,9 @@ function gatewayWith ({ fetch, GATEWAY_URL }) {
3333
}
3434
}
3535

36-
export function loadProcessSchedulerWith ({ fetch, GATEWAY_URL }) {
37-
const gateway = gatewayWith({ fetch, GATEWAY_URL })
38-
const loadScheduler = loadSchedulerWith({ fetch, GATEWAY_URL })
36+
export function loadProcessSchedulerWith ({ fetch, GRAPHQL_URL }) {
37+
const gateway = gatewayWith({ fetch, GRAPHQL_URL })
38+
const loadScheduler = loadSchedulerWith({ fetch, GRAPHQL_URL })
3939

4040
const GET_TRANSACTIONS_QUERY = `
4141
query GetTransactions ($transactionIds: [ID!]!) {
@@ -55,7 +55,7 @@ export function loadProcessSchedulerWith ({ fetch, GATEWAY_URL }) {
5555
return async (process) => {
5656
return gateway({ query: GET_TRANSACTIONS_QUERY, variables: { transactionIds: [process] } })
5757
.then(path(['data', 'transactions', 'edges', '0', 'node']))
58-
.then(findTransactionTags(`Process ${process} was not found on gateway ${GATEWAY_URL}`))
58+
.then(findTransactionTags(`Process ${process} was not found on gateway`))
5959
.then(findTagValue(SCHEDULER_TAG))
6060
.then((walletAddress) => {
6161
if (!walletAddress) throw new SchedulerTagNotFoundError('No "Scheduler" tag found on process')
@@ -64,8 +64,8 @@ export function loadProcessSchedulerWith ({ fetch, GATEWAY_URL }) {
6464
}
6565
}
6666

67-
export function loadSchedulerWith ({ fetch, GATEWAY_URL }) {
68-
const gateway = gatewayWith({ fetch, GATEWAY_URL })
67+
export function loadSchedulerWith ({ fetch, GRAPHQL_URL }) {
68+
const gateway = gatewayWith({ fetch, GRAPHQL_URL })
6969

7070
const GET_SCHEDULER_LOCATION = `
7171
query GetSchedulerLocation ($owner: String!) {

scheduler-utils/src/client/gateway.test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import * as assert from 'node:assert'
44
import { InvalidSchedulerLocationError, SchedulerTagNotFoundError } from '../err.js'
55
import { loadProcessSchedulerWith, loadSchedulerWith } from './gateway.js'
66

7-
const GATEWAY_URL = globalThis.GATEWAY_URL || 'https://arweave.net'
7+
const GRAPHQL_URL = globalThis.GRAPHQL_URL || 'https://arweave.net/graphql'
88
const PROCESS = 'zc24Wpv_i6NNCEdxeKt7dcNrqL5w0hrShtSCcFGGL24'
99
const SCHEDULER = 'gnVg6A6S8lfB10P38V7vOia52lEhTX3Uol8kbTGUT8w'
1010
const TWO_DAYS = 1000 * 60 * 60 * 48
1111

1212
const mockFetch = async (url, options) => {
13-
assert.equal(url, `${GATEWAY_URL}/graphql`)
13+
assert.equal(url, GRAPHQL_URL)
1414
const body = JSON.parse(options.body)
1515
if (body.query.includes('GetTransactions')) return new Response(JSON.stringify(mockFetch.GetTransactions))
1616
if (body.query.includes('GetSchedulerLocation')) return new Response(JSON.stringify(mockFetch.GetSchedulerLocation))
@@ -62,7 +62,7 @@ describe('gateway', () => {
6262
}
6363

6464
const loadProcessScheduler = loadProcessSchedulerWith({
65-
GATEWAY_URL,
65+
GRAPHQL_URL,
6666
fetch: mockFetch
6767
})
6868

@@ -95,7 +95,7 @@ describe('gateway', () => {
9595
}
9696

9797
const loadProcessScheduler = loadProcessSchedulerWith({
98-
GATEWAY_URL,
98+
GRAPHQL_URL,
9999
fetch: mockFetch
100100
})
101101

@@ -130,7 +130,7 @@ describe('gateway', () => {
130130
}
131131

132132
const loadScheduler = loadSchedulerWith({
133-
GATEWAY_URL,
133+
GRAPHQL_URL,
134134
fetch: mockFetch
135135
})
136136

@@ -167,7 +167,7 @@ describe('gateway', () => {
167167
}
168168

169169
const loadScheduler = loadSchedulerWith({
170-
GATEWAY_URL,
170+
GRAPHQL_URL,
171171
fetch: mockFetch
172172
})
173173

@@ -203,7 +203,7 @@ describe('gateway', () => {
203203
}
204204

205205
const loadScheduler = loadSchedulerWith({
206-
GATEWAY_URL,
206+
GRAPHQL_URL,
207207
fetch: mockFetch
208208
})
209209

scheduler-utils/src/index.browser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { connect } from './index.common.js'
22

33
export * from './index.common.js'
44

5-
const GATEWAY_URL = globalThis.GATEWAY_URL || undefined
5+
const GRAPHQL_URL = globalThis.GRAPHQL_URL || undefined
66
const CACHE_SIZE = globalThis.SCHEDULER_UTILS_CACHE_SIZE || undefined
77
const FOLLOW_REDIRECTS = globalThis.SCHEDULER_UTILS_FOLLOW_REDIRECTS === 'true' || undefined
88

9-
const { locate, validate, raw } = connect({ GATEWAY_URL, cacheSize: CACHE_SIZE, followRedirects: FOLLOW_REDIRECTS })
9+
const { locate, validate, raw } = connect({ GRAPHQL_URL, cacheSize: CACHE_SIZE, followRedirects: FOLLOW_REDIRECTS })
1010

1111
export { locate, validate, raw }

scheduler-utils/src/index.common.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import { validateWith } from './validate.js'
88

99
export * from './err.js'
1010

11-
const DEFAULT_GATEWAY_URL = 'https://arweave.net'
11+
const DEFAULT_GRAPHQL_URL = 'https://arweave.net/graphql'
1212

1313
/**
1414
* @typedef ConnectParams
1515
* @property {number} [cacheSize] - the size of the internal LRU cache
1616
* @property {boolean} [followRedirects] - whether to follow redirects and cache that url instead
17-
* @property {string} [GATEWAY_URL] - the url of the gateway to be used
17+
* @property {string} [GRAPHQL_URL] - the url of the gateway to be used
1818
*
1919
* Build the apis using the provided configuration. You can currently specify
2020
*
21-
* - a GATEWAY_URL. Defaults to https://arweave.net
21+
* - a GRAPHQL_URL. Defaults to https://arweave.net/graphql
2222
* - a cache size for the internal LRU cache. Defaults to 100
2323
* - whether or not to follow redirects when locating a scheduler. Defaults to false
2424
*
@@ -28,10 +28,10 @@ const DEFAULT_GATEWAY_URL = 'https://arweave.net'
2828
*
2929
* @param {ConnectParams} [params]
3030
*/
31-
export function connect ({ cacheSize = 100, GATEWAY_URL = DEFAULT_GATEWAY_URL, followRedirects = false } = {}) {
31+
export function connect ({ cacheSize = 100, GRAPHQL_URL = DEFAULT_GRAPHQL_URL, followRedirects = false } = {}) {
3232
const _cache = InMemoryClient.createLruCache({ size: cacheSize })
3333

34-
const loadScheduler = GatewayClient.loadSchedulerWith({ fetch, GATEWAY_URL })
34+
const loadScheduler = GatewayClient.loadSchedulerWith({ fetch, GRAPHQL_URL })
3535
const cache = {
3636
getByProcess: InMemoryClient.getByProcessWith({ cache: _cache }),
3737
getByOwner: InMemoryClient.getByOwnerWith({ cache: _cache }),
@@ -42,7 +42,7 @@ export function connect ({ cacheSize = 100, GATEWAY_URL = DEFAULT_GATEWAY_URL, f
4242
* Locate the scheduler for the given process.
4343
*/
4444
const locate = locateWith({
45-
loadProcessScheduler: GatewayClient.loadProcessSchedulerWith({ fetch, GATEWAY_URL }),
45+
loadProcessScheduler: GatewayClient.loadProcessSchedulerWith({ fetch, GRAPHQL_URL }),
4646
loadScheduler,
4747
cache,
4848
followRedirects,

scheduler-utils/src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { connect } from './index.common.js'
22

33
export * from './index.common.js'
44

5-
const GATEWAY_URL = process.env.GATEWAY_URL || undefined
5+
const GRAPHQL_URL = process.env.GRAPHQL_URL || undefined
66
const CACHE_SIZE = process.env.SCHEDULER_UTILS_CACHE_SIZE || undefined
77
const FOLLOW_REDIRECTS = process.env.SCHEDULER_UTILS_FOLLOW_REDIRECTS === 'true' || undefined
88

9-
const { locate, validate, raw } = connect({ GATEWAY_URL, cacheSize: CACHE_SIZE, followRedirects: FOLLOW_REDIRECTS })
9+
const { locate, validate, raw } = connect({ GRAPHQL_URL, cacheSize: CACHE_SIZE, followRedirects: FOLLOW_REDIRECTS })
1010

1111
export { locate, validate, raw }

0 commit comments

Comments
 (0)