From 6e79d45513af04d6797efd55637ecc1555ed2206 Mon Sep 17 00:00:00 2001 From: sarahschwartz <58856580+sarahschwartz@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:16:42 -0600 Subject: [PATCH] use endpoint variable in examples --- docs/reference/objects.mdx | 2 +- examples/query.tsx | 3 ++- examples/tests/balance.test.ts | 10 ++++++---- examples/tests/balances.test.ts | 10 ++++++---- examples/tests/block.test.ts | 10 ++++++---- examples/tests/contract-balance.test.ts | 10 ++++++---- examples/tests/contract-balances.test.ts | 10 ++++++---- examples/tests/latest-blocks.test.ts | 10 ++++++---- examples/tests/latest-transactions.test.ts | 10 ++++++---- examples/tests/messages.test.ts | 10 ++++++---- examples/tests/transactions-by-owner.test.ts | 10 ++++++---- src/components/CodeExamples.tsx | 6 +++--- src/constants.ts | 2 ++ src/lib/code-examples.ts | 5 +++-- tsconfig.json | 1 + 15 files changed, 66 insertions(+), 43 deletions(-) diff --git a/docs/reference/objects.mdx b/docs/reference/objects.mdx index 28bae38..b7c27c1 100644 --- a/docs/reference/objects.mdx +++ b/docs/reference/objects.mdx @@ -82,7 +82,7 @@ Information about the base chain. At a very high level `chainInfo` helps you und `name`: `String!` -The human-readable string name of the chain. i.e. beta-5 +The human-readable string name of the chain. i.e. `beta-5`. `latestBlock`: [`Block!`](#block) diff --git a/examples/query.tsx b/examples/query.tsx index c2995c7..fca9882 100644 --- a/examples/query.tsx +++ b/examples/query.tsx @@ -4,6 +4,7 @@ import { Code } from '~/src/components/Code'; import { ExampleBox } from '~/src/components/ExampleBox'; import { Paragraph } from '~/src/components/Paragraph'; import { Pre } from '~/src/components/Pre'; +import { TESTNET_ENDPOINT } from '~/src/constants'; interface QueryProps { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -18,7 +19,7 @@ export function Query(props: QueryProps) { function runQuery() { setLoading(true); - fetch('https://beta-5.fuel.network/graphql', { + fetch(TESTNET_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/examples/tests/balance.test.ts b/examples/tests/balance.test.ts index 050049c..2fb8aa6 100644 --- a/examples/tests/balance.test.ts +++ b/examples/tests/balance.test.ts @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; +import { TESTNET_ENDPOINT } from '~/src/constants'; const apolloClient = new ApolloClient({ - uri: 'https://beta-5.fuel.network/graphql', + uri: TESTNET_ENDPOINT, cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-5.fuel.network/graphql', + url: TESTNET_ENDPOINT, exchanges: [cacheExchange, fetchExchange], }); @@ -30,7 +32,7 @@ describe('Balance', () => { }; const getBalance = async () => { - const response = await fetch('https://beta-5.fuel.network/graphql', { + const response = await fetch(TESTNET_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -41,7 +43,7 @@ describe('Balance', () => { variables: args, }), }); - const json = await response.json(); + const json: any = await response.json(); console.log('BALANCE:', json.data.balance); expect(json.data.balance.amount).toBeTruthy(); }; diff --git a/examples/tests/balances.test.ts b/examples/tests/balances.test.ts index 502de0f..d018742 100644 --- a/examples/tests/balances.test.ts +++ b/examples/tests/balances.test.ts @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; +import { TESTNET_ENDPOINT } from '~/src/constants'; const apolloClient = new ApolloClient({ - uri: 'https://beta-5.fuel.network/graphql', + uri: TESTNET_ENDPOINT, cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-5.fuel.network/graphql', + url: TESTNET_ENDPOINT, exchanges: [cacheExchange, fetchExchange], }); @@ -31,7 +33,7 @@ describe('Balances', () => { }; const getBalances = async () => { - const response = await fetch('https://beta-5.fuel.network/graphql', { + const response = await fetch(TESTNET_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -42,7 +44,7 @@ describe('Balances', () => { variables: args, }), }); - const json = await response.json(); + const json: any = await response.json(); console.log('BALANCES:', json.data.balances); expect(json.data.balances.nodes).toBeTruthy(); }; diff --git a/examples/tests/block.test.ts b/examples/tests/block.test.ts index f00902b..f3d036a 100644 --- a/examples/tests/block.test.ts +++ b/examples/tests/block.test.ts @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; +import { TESTNET_ENDPOINT } from '~/src/constants'; const apolloClient = new ApolloClient({ - uri: 'https://beta-5.fuel.network/graphql', + uri: TESTNET_ENDPOINT, cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-5.fuel.network/graphql', + url: TESTNET_ENDPOINT, exchanges: [cacheExchange, fetchExchange], }); @@ -24,7 +26,7 @@ describe('Block Info', () => { const args = { height: '3412' }; const getBlock = async () => { - const response = await fetch('https://beta-5.fuel.network/graphql', { + const response = await fetch(TESTNET_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -35,7 +37,7 @@ describe('Block Info', () => { variables: args, }), }); - const json = await response.json(); + const json: any = await response.json(); console.log('BLOCK:', json.data.block); expect(json.data.block.id).toBeTruthy(); }; diff --git a/examples/tests/contract-balance.test.ts b/examples/tests/contract-balance.test.ts index 4a50bc6..e3d63ba 100644 --- a/examples/tests/contract-balance.test.ts +++ b/examples/tests/contract-balance.test.ts @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; +import { TESTNET_ENDPOINT } from '~/src/constants'; const apolloClient = new ApolloClient({ - uri: 'https://beta-5.fuel.network/graphql', + uri: TESTNET_ENDPOINT, cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-5.fuel.network/graphql', + url: TESTNET_ENDPOINT, exchanges: [cacheExchange, fetchExchange], }); @@ -30,7 +32,7 @@ describe('Contract Balance', () => { }; const getContractBalance = async () => { - const response = await fetch('https://beta-5.fuel.network/graphql', { + const response = await fetch(TESTNET_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -41,7 +43,7 @@ describe('Contract Balance', () => { variables: args, }), }); - const json = await response.json(); + const json: any = await response.json(); console.log('CONTRACT BALANCE:', json.data.contractBalance); expect(json.data.contractBalance.amount).toBeTruthy(); }; diff --git a/examples/tests/contract-balances.test.ts b/examples/tests/contract-balances.test.ts index 554d4c8..37a783d 100644 --- a/examples/tests/contract-balances.test.ts +++ b/examples/tests/contract-balances.test.ts @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; +import { TESTNET_ENDPOINT } from '~/src/constants'; const apolloClient = new ApolloClient({ - uri: 'https://beta-5.fuel.network/graphql', + uri: TESTNET_ENDPOINT, cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-5.fuel.network/graphql', + url: TESTNET_ENDPOINT, exchanges: [cacheExchange, fetchExchange], }); @@ -32,7 +34,7 @@ describe('Contract balances', () => { }; const getContractBalances = async () => { - const response = await fetch('https://beta-5.fuel.network/graphql', { + const response = await fetch(TESTNET_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -43,7 +45,7 @@ describe('Contract balances', () => { variables: args, }), }); - const json = await response.json(); + const json: any = await response.json(); console.log('CONTRACT BALANCES:', json.data.contractBalances); expect(json.data.contractBalances.nodes).toBeTruthy(); }; diff --git a/examples/tests/latest-blocks.test.ts b/examples/tests/latest-blocks.test.ts index 3c0a698..5a6dbce 100644 --- a/examples/tests/latest-blocks.test.ts +++ b/examples/tests/latest-blocks.test.ts @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; +import { TESTNET_ENDPOINT } from '~/src/constants'; const apolloClient = new ApolloClient({ - uri: 'https://beta-5.fuel.network/graphql', + uri: TESTNET_ENDPOINT, cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-5.fuel.network/graphql', + url: TESTNET_ENDPOINT, exchanges: [cacheExchange, fetchExchange], }); @@ -78,7 +80,7 @@ describe('Latest blocks', () => { }`; const getLatestBlocks = async () => { - const response = await fetch('https://beta-5.fuel.network/graphql', { + const response = await fetch(TESTNET_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -88,7 +90,7 @@ describe('Latest blocks', () => { query: LATEST_BLOCKS_QUERY, }), }); - const json = await response.json(); + const json: any = await response.json(); console.log('BLOCKS:', json.data.blocks); expect(json.data.blocks.nodes.length).toBeTruthy(); }; diff --git a/examples/tests/latest-transactions.test.ts b/examples/tests/latest-transactions.test.ts index 290b946..c215415 100644 --- a/examples/tests/latest-transactions.test.ts +++ b/examples/tests/latest-transactions.test.ts @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; +import { TESTNET_ENDPOINT } from '~/src/constants'; const apolloClient = new ApolloClient({ - uri: 'https://beta-5.fuel.network/graphql', + uri: TESTNET_ENDPOINT, cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-5.fuel.network/graphql', + url: TESTNET_ENDPOINT, exchanges: [cacheExchange, fetchExchange], }); @@ -83,7 +85,7 @@ describe('Latest transactions', () => { }`; const getLatestTransactions = async () => { - const response = await fetch('https://beta-5.fuel.network/graphql', { + const response = await fetch(TESTNET_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -93,7 +95,7 @@ describe('Latest transactions', () => { query: LATEST_TRANSACTIONS_QUERY, }), }); - const json = await response.json(); + const json: any = await response.json(); console.log('TRANSACTIONS:', json.data.transactions); expect(json.data.transactions.nodes.length).toBeTruthy(); }; diff --git a/examples/tests/messages.test.ts b/examples/tests/messages.test.ts index 8a411a9..2a8dc3e 100644 --- a/examples/tests/messages.test.ts +++ b/examples/tests/messages.test.ts @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; +import { TESTNET_ENDPOINT } from '~/src/constants'; const apolloClient = new ApolloClient({ - uri: 'https://beta-5.fuel.network/graphql', + uri: TESTNET_ENDPOINT, cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-5.fuel.network/graphql', + url: TESTNET_ENDPOINT, exchanges: [cacheExchange, fetchExchange], }); @@ -34,7 +36,7 @@ describe('Messages', () => { }; const getMessages = async () => { - const response = await fetch('https://beta-5.fuel.network/graphql', { + const response = await fetch(TESTNET_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -45,7 +47,7 @@ describe('Messages', () => { variables: args, }), }); - const json = await response.json(); + const json: any = await response.json(); console.log('MESSAGES:', json.data.messages); expect(json.data.messages.nodes).toBeTruthy(); }; diff --git a/examples/tests/transactions-by-owner.test.ts b/examples/tests/transactions-by-owner.test.ts index 5db50fc..942c308 100644 --- a/examples/tests/transactions-by-owner.test.ts +++ b/examples/tests/transactions-by-owner.test.ts @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; +import { TESTNET_ENDPOINT } from '~/src/constants'; const apolloClient = new ApolloClient({ - uri: 'https://beta-5.fuel.network/graphql', + uri: TESTNET_ENDPOINT, cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-5.fuel.network/graphql', + url: TESTNET_ENDPOINT, exchanges: [cacheExchange, fetchExchange], }); @@ -88,7 +90,7 @@ describe('Transactions by owner', () => { }; const getTransactions = async () => { - const response = await fetch('https://beta-5.fuel.network/graphql', { + const response = await fetch(TESTNET_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -99,7 +101,7 @@ describe('Transactions by owner', () => { variables: args, }), }); - const json = await response.json(); + const json: any = await response.json(); console.log('TRANSACTIONS:', json.data.transactionsByOwner); expect(json.data.transactionsByOwner.nodes.length).toBeTruthy(); }; diff --git a/src/components/CodeExamples.tsx b/src/components/CodeExamples.tsx index e9793f8..e739893 100644 --- a/src/components/CodeExamples.tsx +++ b/src/components/CodeExamples.tsx @@ -1,7 +1,7 @@ import { cssObj } from '@fuel-ui/css'; import { Link, Tabs, Box } from '@fuel-ui/react'; -import { REPO_LINK } from '../constants'; +import { REPO_LINK, TESTNET_ENDPOINT } from '../constants'; import { Pre } from './Pre'; @@ -58,7 +58,7 @@ export function CodeExamples({ const apolloImport = `import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; const apolloClient= new ApolloClient({ - uri: 'https://beta-5.fuel.network/graphql', + uri: '${TESTNET_ENDPOINT}', cache: new InMemoryCache(), }); @@ -67,7 +67,7 @@ const apolloClient= new ApolloClient({ const urqlImport = `import { Client, cacheExchange, fetchExchange } from 'urql'; const urqlClient = new Client({ - url: 'https://beta-5.fuel.network/graphql', + url: '${TESTNET_ENDPOINT}', exchanges: [cacheExchange, fetchExchange], }); diff --git a/src/constants.ts b/src/constants.ts index 0b80014..d8410a0 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -10,3 +10,5 @@ export const DEFAULT_SLUG = ['overview']; export const META_DESC = 'Official documentation for the Fuel GraphQL API'; export const META_OGIMG = URL + ogImage.src; + +export const TESTNET_ENDPOINT = 'https://beta-5.fuel.network/graphql'; diff --git a/src/lib/code-examples.ts b/src/lib/code-examples.ts index e555c9a..7c5970a 100644 --- a/src/lib/code-examples.ts +++ b/src/lib/code-examples.ts @@ -9,6 +9,7 @@ import * as prettier from 'prettier'; import type { Root } from 'remark-gfm'; import { visit } from 'unist-util-visit'; import type { Parent } from 'unist-util-visit'; +import { TESTNET_ENDPOINT } from '../constants'; const ROOT_DIR = path.resolve(__dirname, '../../../'); @@ -34,7 +35,7 @@ function extractLines( } else { end = lines.length; } - return lines.slice(start - 1, end).join('\n'); + return lines.slice(start - 1, end).join('\n').replaceAll('TESTNET_ENDPOINT', `'${TESTNET_ENDPOINT}'`); } function getLineOffsets(str: string) { @@ -63,7 +64,7 @@ function extractTestCase(source: string, testCase: string) { if (val && val === testCase) { const body = args[1]?.body; content = chars.slice(body.start, body.end).join('').slice(1, -1); - content = prettier.format(content, { parser: 'babel' }).trimEnd(); + content = prettier.format(content, { parser: 'babel' }).trimEnd().replaceAll('TESTNET_ENDPOINT', `'${TESTNET_ENDPOINT}'`); charStart = body.start; charEnd = body.end; } diff --git a/tsconfig.json b/tsconfig.json index 72c1785..bd036d2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "extends": "@fuels/ts-config/base.json", "compilerOptions": { "types": ["@fuel-wallet/sdk", "jest"], + "lib": ["es2021"], "plugins": [{ "name": "next" }], "allowJs": true, "noEmit": true,