Skip to content

Commit

Permalink
use endpoint variable in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahschwartz committed Apr 15, 2024
1 parent 0fe02a2 commit 6e79d45
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 43 deletions.
2 changes: 1 addition & 1 deletion docs/reference/objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion examples/query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand Down
10 changes: 6 additions & 4 deletions examples/tests/balance.test.ts
Original file line number Diff line number Diff line change
@@ -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],
});

Expand All @@ -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',
Expand All @@ -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();
};
Expand Down
10 changes: 6 additions & 4 deletions examples/tests/balances.test.ts
Original file line number Diff line number Diff line change
@@ -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],
});

Expand All @@ -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',
Expand All @@ -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();
};
Expand Down
10 changes: 6 additions & 4 deletions examples/tests/block.test.ts
Original file line number Diff line number Diff line change
@@ -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],
});

Expand All @@ -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',
Expand All @@ -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();
};
Expand Down
10 changes: 6 additions & 4 deletions examples/tests/contract-balance.test.ts
Original file line number Diff line number Diff line change
@@ -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],
});

Expand All @@ -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',
Expand All @@ -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();
};
Expand Down
10 changes: 6 additions & 4 deletions examples/tests/contract-balances.test.ts
Original file line number Diff line number Diff line change
@@ -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],
});

Expand All @@ -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',
Expand All @@ -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();
};
Expand Down
10 changes: 6 additions & 4 deletions examples/tests/latest-blocks.test.ts
Original file line number Diff line number Diff line change
@@ -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],
});

Expand Down Expand Up @@ -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',
Expand All @@ -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();
};
Expand Down
10 changes: 6 additions & 4 deletions examples/tests/latest-transactions.test.ts
Original file line number Diff line number Diff line change
@@ -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],
});

Expand Down Expand Up @@ -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',
Expand All @@ -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();
};
Expand Down
10 changes: 6 additions & 4 deletions examples/tests/messages.test.ts
Original file line number Diff line number Diff line change
@@ -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],
});

Expand All @@ -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',
Expand All @@ -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();
};
Expand Down
10 changes: 6 additions & 4 deletions examples/tests/transactions-by-owner.test.ts
Original file line number Diff line number Diff line change
@@ -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],
});

Expand Down Expand Up @@ -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',
Expand All @@ -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();
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/CodeExamples.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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(),
});
Expand All @@ -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],
});
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Loading

0 comments on commit 6e79d45

Please sign in to comment.