From ab8ccc0f7e04108e8d75a75fcfff913407304a79 Mon Sep 17 00:00:00 2001 From: Call Delegation <106365423+calldelegation@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:35:13 -0500 Subject: [PATCH] docs: Beta 5 Schema Updates (#27) Co-authored-by: sarahschwartz <58856580+sarahschwartz@users.noreply.github.com> --- .github/workflows/docs.yml | 14 + docs/overview.mdx | 8 +- docs/querying-from-a-dapp.mdx | 6 +- docs/recipes.mdx | 351 +------------- docs/reference/enums.mdx | 23 + docs/reference/mutations.mdx | 121 ++++- docs/reference/objects.mdx | 483 ++++++++++++++----- docs/reference/queries.mdx | 22 +- docs/reference/scalars.mdx | 12 +- docs/reference/subscriptions.mdx | 4 +- docs/reference/unions.mdx | 17 +- examples/query.tsx | 46 +- examples/tests/balance.test.ts | 6 +- examples/tests/balances.test.ts | 6 +- examples/tests/block.test.ts | 6 +- examples/tests/contract-balance.test.ts | 6 +- examples/tests/contract-balances.test.ts | 6 +- examples/tests/latest-blocks.test.ts | 6 +- examples/tests/latest-transactions.test.ts | 6 +- examples/tests/messages.test.ts | 6 +- examples/tests/transactions-by-owner.test.ts | 12 +- package-lock.json | 167 ++++--- package.json | 2 +- scripts/coverage/enums.mjs | 47 ++ scripts/coverage/index.mjs | 65 +++ scripts/coverage/objects.mjs | 116 +++++ scripts/coverage/queries.mjs | 247 ++++++++++ scripts/coverage/unions.mjs | 50 ++ scripts/coverage/utils.mjs | 274 +++++++++++ spell-check-custom-words.txt | 5 +- src/components/CodeExamples.tsx | 4 +- 31 files changed, 1510 insertions(+), 634 deletions(-) create mode 100644 scripts/coverage/enums.mjs create mode 100644 scripts/coverage/index.mjs create mode 100644 scripts/coverage/objects.mjs create mode 100644 scripts/coverage/queries.mjs create mode 100644 scripts/coverage/unions.mjs create mode 100644 scripts/coverage/utils.mjs diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 513e705..e3f547f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -59,4 +59,18 @@ jobs: npm install npm run lint:docs:check + check-coverage: + name: Check Coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + # RUN COVERAGE CHECK + - name: Coverage Check + run: | + npm install + node scripts/coverage/index.mjs + diff --git a/docs/overview.mdx b/docs/overview.mdx index 4ba77f2..851ce3b 100644 --- a/docs/overview.mdx +++ b/docs/overview.mdx @@ -14,10 +14,8 @@ The playground is an interactive and graphical IDE that includes a reference for You can test out the Fuel GraphQL API playground here: -Beta-4: -https://beta-4.fuel.network/playground +https://beta-5.fuel.network/playground -## API Endpoint +## RPC Endpoint -Beta-4: -https://beta-4.fuel.network/graphql +https://beta-5.fuel.network/graphql diff --git a/docs/querying-from-a-dapp.mdx b/docs/querying-from-a-dapp.mdx index 8954839..a69cc6b 100644 --- a/docs/querying-from-a-dapp.mdx +++ b/docs/querying-from-a-dapp.mdx @@ -11,7 +11,7 @@ This section covers just a few options available to get you started. ```javascript export async function getHealth() { - let response = await fetch('https://beta-4.fuel.network/graphql', { + let response = await fetch('https://beta-5.fuel.network/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -36,7 +36,7 @@ npm install @apollo/client graphql import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; const apolloClient = new ApolloClient({ - uri: 'https://beta-4.fuel.network/graphql', + uri: 'https://beta-5.fuel.network/graphql', cache: new InMemoryCache(), }); @@ -66,7 +66,7 @@ npm install urql graphql import { Client, cacheExchange, fetchExchange } from 'urql'; const urqlClient = new Client({ - url: 'https://beta-4.fuel.network/graphql', + url: 'https://beta-5.fuel.network/graphql', exchanges: [cacheExchange, fetchExchange], }); diff --git a/docs/recipes.mdx b/docs/recipes.mdx index ad0fcf3..da7a825 100644 --- a/docs/recipes.mdx +++ b/docs/recipes.mdx @@ -23,28 +23,8 @@ Click the "TypeScript", "Apollo Client", or "urql" buttons to see code examples. ## Get an asset balance of an address -```graphql -query Balance($address: Address, $assetId: AssetId) { - balance(owner: $address, assetId: $assetId) { - owner - amount - assetId - } -} -``` - -Variables: - -```json -{ - "address": "0xf65d6448a273b531ee942c133bb91a6f904c7d7f3104cdaf6b9f7f50d3518871", - "assetId": "0x0000000000000000000000000000000000000000000000000000000000000000" -} -``` - -{' '} - + <> + {props.query && ( <> - +
+            {props.query}
+          
- {resp && ( + {props.args && Object.keys(props.args).length > 0 && ( <> -
Response:
- + Variables: +
+                
+                  {JSON.stringify(props.args, null, 2)}
+                
+              
)} -
- + )} + + + + <> + + + {resp && ( + <> +
Response:
+ + + )} + +
+
+ ); } diff --git a/examples/tests/balance.test.ts b/examples/tests/balance.test.ts index eda9f48..050049c 100644 --- a/examples/tests/balance.test.ts +++ b/examples/tests/balance.test.ts @@ -3,12 +3,12 @@ import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; const apolloClient = new ApolloClient({ - uri: 'https://beta-4.fuel.network/graphql', + uri: 'https://beta-5.fuel.network/graphql', cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-4.fuel.network/graphql', + url: 'https://beta-5.fuel.network/graphql', exchanges: [cacheExchange, fetchExchange], }); @@ -30,7 +30,7 @@ describe('Balance', () => { }; const getBalance = async () => { - const response = await fetch('https://beta-4.fuel.network/graphql', { + const response = await fetch('https://beta-5.fuel.network/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/examples/tests/balances.test.ts b/examples/tests/balances.test.ts index b187814..502de0f 100644 --- a/examples/tests/balances.test.ts +++ b/examples/tests/balances.test.ts @@ -3,12 +3,12 @@ import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; const apolloClient = new ApolloClient({ - uri: 'https://beta-4.fuel.network/graphql', + uri: 'https://beta-5.fuel.network/graphql', cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-4.fuel.network/graphql', + url: 'https://beta-5.fuel.network/graphql', exchanges: [cacheExchange, fetchExchange], }); @@ -31,7 +31,7 @@ describe('Balances', () => { }; const getBalances = async () => { - const response = await fetch('https://beta-4.fuel.network/graphql', { + const response = await fetch('https://beta-5.fuel.network/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/examples/tests/block.test.ts b/examples/tests/block.test.ts index b09f365..f00902b 100644 --- a/examples/tests/block.test.ts +++ b/examples/tests/block.test.ts @@ -3,12 +3,12 @@ import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; const apolloClient = new ApolloClient({ - uri: 'https://beta-4.fuel.network/graphql', + uri: 'https://beta-5.fuel.network/graphql', cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-4.fuel.network/graphql', + url: 'https://beta-5.fuel.network/graphql', exchanges: [cacheExchange, fetchExchange], }); @@ -24,7 +24,7 @@ describe('Block Info', () => { const args = { height: '3412' }; const getBlock = async () => { - const response = await fetch('https://beta-4.fuel.network/graphql', { + const response = await fetch('https://beta-5.fuel.network/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/examples/tests/contract-balance.test.ts b/examples/tests/contract-balance.test.ts index c8fec60..4a50bc6 100644 --- a/examples/tests/contract-balance.test.ts +++ b/examples/tests/contract-balance.test.ts @@ -3,12 +3,12 @@ import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; const apolloClient = new ApolloClient({ - uri: 'https://beta-4.fuel.network/graphql', + uri: 'https://beta-5.fuel.network/graphql', cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-4.fuel.network/graphql', + url: 'https://beta-5.fuel.network/graphql', exchanges: [cacheExchange, fetchExchange], }); @@ -30,7 +30,7 @@ describe('Contract Balance', () => { }; const getContractBalance = async () => { - const response = await fetch('https://beta-4.fuel.network/graphql', { + const response = await fetch('https://beta-5.fuel.network/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/examples/tests/contract-balances.test.ts b/examples/tests/contract-balances.test.ts index 9eb0875..554d4c8 100644 --- a/examples/tests/contract-balances.test.ts +++ b/examples/tests/contract-balances.test.ts @@ -3,12 +3,12 @@ import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; const apolloClient = new ApolloClient({ - uri: 'https://beta-4.fuel.network/graphql', + uri: 'https://beta-5.fuel.network/graphql', cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-4.fuel.network/graphql', + url: 'https://beta-5.fuel.network/graphql', exchanges: [cacheExchange, fetchExchange], }); @@ -32,7 +32,7 @@ describe('Contract balances', () => { }; const getContractBalances = async () => { - const response = await fetch('https://beta-4.fuel.network/graphql', { + const response = await fetch('https://beta-5.fuel.network/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/examples/tests/latest-blocks.test.ts b/examples/tests/latest-blocks.test.ts index 2656f1a..3c0a698 100644 --- a/examples/tests/latest-blocks.test.ts +++ b/examples/tests/latest-blocks.test.ts @@ -3,12 +3,12 @@ import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; const apolloClient = new ApolloClient({ - uri: 'https://beta-4.fuel.network/graphql', + uri: 'https://beta-5.fuel.network/graphql', cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-4.fuel.network/graphql', + url: 'https://beta-5.fuel.network/graphql', exchanges: [cacheExchange, fetchExchange], }); @@ -78,7 +78,7 @@ describe('Latest blocks', () => { }`; const getLatestBlocks = async () => { - const response = await fetch('https://beta-4.fuel.network/graphql', { + const response = await fetch('https://beta-5.fuel.network/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/examples/tests/latest-transactions.test.ts b/examples/tests/latest-transactions.test.ts index 7eda540..290b946 100644 --- a/examples/tests/latest-transactions.test.ts +++ b/examples/tests/latest-transactions.test.ts @@ -3,12 +3,12 @@ import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; const apolloClient = new ApolloClient({ - uri: 'https://beta-4.fuel.network/graphql', + uri: 'https://beta-5.fuel.network/graphql', cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-4.fuel.network/graphql', + url: 'https://beta-5.fuel.network/graphql', exchanges: [cacheExchange, fetchExchange], }); @@ -83,7 +83,7 @@ describe('Latest transactions', () => { }`; const getLatestTransactions = async () => { - const response = await fetch('https://beta-4.fuel.network/graphql', { + const response = await fetch('https://beta-5.fuel.network/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/examples/tests/messages.test.ts b/examples/tests/messages.test.ts index 02ebd72..8a411a9 100644 --- a/examples/tests/messages.test.ts +++ b/examples/tests/messages.test.ts @@ -3,12 +3,12 @@ import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; const apolloClient = new ApolloClient({ - uri: 'https://beta-4.fuel.network/graphql', + uri: 'https://beta-5.fuel.network/graphql', cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-4.fuel.network/graphql', + url: 'https://beta-5.fuel.network/graphql', exchanges: [cacheExchange, fetchExchange], }); @@ -34,7 +34,7 @@ describe('Messages', () => { }; const getMessages = async () => { - const response = await fetch('https://beta-4.fuel.network/graphql', { + const response = await fetch('https://beta-5.fuel.network/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/examples/tests/transactions-by-owner.test.ts b/examples/tests/transactions-by-owner.test.ts index 1e4dc0d..5db50fc 100644 --- a/examples/tests/transactions-by-owner.test.ts +++ b/examples/tests/transactions-by-owner.test.ts @@ -3,12 +3,12 @@ import { Client, cacheExchange, fetchExchange } from 'urql'; import 'isomorphic-fetch'; const apolloClient = new ApolloClient({ - uri: 'https://beta-4.fuel.network/graphql', + uri: 'https://beta-5.fuel.network/graphql', cache: new InMemoryCache(), }); const urqlClient = new Client({ - url: 'https://beta-4.fuel.network/graphql', + url: 'https://beta-5.fuel.network/graphql', exchanges: [cacheExchange, fetchExchange], }); @@ -84,11 +84,11 @@ describe('Transactions by owner', () => { const args = { address: - '0xf65d6448a273b531ee942c133bb91a6f904c7d7f3104cdaf6b9f7f50d3518871', + '0x44f640c8ed0d0b76fa7a029972e9db1ce92386b8e4df4d789e026443cb5f0d91', }; const getTransactions = async () => { - const response = await fetch('https://beta-4.fuel.network/graphql', { + const response = await fetch('https://beta-5.fuel.network/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -178,7 +178,7 @@ describe('Transactions by owner', () => { const args = { address: - '0xf65d6448a273b531ee942c133bb91a6f904c7d7f3104cdaf6b9f7f50d3518871', + '0x44f640c8ed0d0b76fa7a029972e9db1ce92386b8e4df4d789e026443cb5f0d91', }; const getTransactions = async () => { @@ -264,7 +264,7 @@ describe('Transactions by owner', () => { const args = { address: - '0xf65d6448a273b531ee942c133bb91a6f904c7d7f3104cdaf6b9f7f50d3518871', + '0x44f640c8ed0d0b76fa7a029972e9db1ce92386b8e4df4d789e026443cb5f0d91', }; const getTransactions = async () => { diff --git a/package-lock.json b/package-lock.json index 6368026..ba4f43c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,7 +37,7 @@ "hastscript": "^7.2.0", "isomorphic-fetch": "^3.0.0", "markdownlint-cli": "^0.37.0", - "next": "13.4.19", + "next": "^13.5.6", "next-mdx-remote": "^4.4.1", "node-html-markdown": "^1.3.0", "plyr-react": "^5.3.0", @@ -3132,9 +3132,9 @@ } }, "node_modules/@next/env": { - "version": "13.4.19", - "resolved": "https://registry.npmjs.org/@next/env/-/env-13.4.19.tgz", - "integrity": "sha512-FsAT5x0jF2kkhNkKkukhsyYOrRqtSxrEhfliniIq0bwWbuXLgyt3Gv0Ml+b91XwjwArmuP7NxCiGd++GGKdNMQ==" + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/env/-/env-13.5.6.tgz", + "integrity": "sha512-Yac/bV5sBGkkEXmAX5FWPS9Mmo2rthrOPRQQNfycJPkjUAUclomCPH7QFVCDQ4Mp2k2K1SSM6m0zrxYrOwtFQw==" }, "node_modules/@next/eslint-plugin-next": { "version": "13.5.6", @@ -3145,9 +3145,9 @@ } }, "node_modules/@next/swc-darwin-arm64": { - "version": "13.4.19", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.19.tgz", - "integrity": "sha512-vv1qrjXeGbuF2mOkhkdxMDtv9np7W4mcBtaDnHU+yJG+bBwa6rYsYSCI/9Xm5+TuF5SbZbrWO6G1NfTh1TMjvQ==", + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.5.6.tgz", + "integrity": "sha512-5nvXMzKtZfvcu4BhtV0KH1oGv4XEW+B+jOfmBdpFI3C7FrB/MfujRpWYSBBO64+qbW8pkZiSyQv9eiwnn5VIQA==", "cpu": [ "arm64" ], @@ -3160,9 +3160,9 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "13.4.19", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.19.tgz", - "integrity": "sha512-jyzO6wwYhx6F+7gD8ddZfuqO4TtpJdw3wyOduR4fxTUCm3aLw7YmHGYNjS0xRSYGAkLpBkH1E0RcelyId6lNsw==", + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.5.6.tgz", + "integrity": "sha512-6cgBfxg98oOCSr4BckWjLLgiVwlL3vlLj8hXg2b+nDgm4bC/qVXXLfpLB9FHdoDu4057hzywbxKvmYGmi7yUzA==", "cpu": [ "x64" ], @@ -3175,9 +3175,9 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "13.4.19", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.19.tgz", - "integrity": "sha512-vdlnIlaAEh6H+G6HrKZB9c2zJKnpPVKnA6LBwjwT2BTjxI7e0Hx30+FoWCgi50e+YO49p6oPOtesP9mXDRiiUg==", + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.5.6.tgz", + "integrity": "sha512-txagBbj1e1w47YQjcKgSU4rRVQ7uF29YpnlHV5xuVUsgCUf2FmyfJ3CPjZUvpIeXCJAoMCFAoGnbtX86BK7+sg==", "cpu": [ "arm64" ], @@ -3190,9 +3190,9 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "13.4.19", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.19.tgz", - "integrity": "sha512-aU0HkH2XPgxqrbNRBFb3si9Ahu/CpaR5RPmN2s9GiM9qJCiBBlZtRTiEca+DC+xRPyCThTtWYgxjWHgU7ZkyvA==", + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.5.6.tgz", + "integrity": "sha512-cGd+H8amifT86ZldVJtAKDxUqeFyLWW+v2NlBULnLAdWsiuuN8TuhVBt8ZNpCqcAuoruoSWynvMWixTFcroq+Q==", "cpu": [ "arm64" ], @@ -3205,9 +3205,9 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "13.4.19", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.19.tgz", - "integrity": "sha512-htwOEagMa/CXNykFFeAHHvMJeqZfNQEoQvHfsA4wgg5QqGNqD5soeCer4oGlCol6NGUxknrQO6VEustcv+Md+g==", + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.5.6.tgz", + "integrity": "sha512-Mc2b4xiIWKXIhBy2NBTwOxGD3nHLmq4keFk+d4/WL5fMsB8XdJRdtUlL87SqVCTSaf1BRuQQf1HvXZcy+rq3Nw==", "cpu": [ "x64" ], @@ -3220,9 +3220,9 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "13.4.19", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.19.tgz", - "integrity": "sha512-4Gj4vvtbK1JH8ApWTT214b3GwUh9EKKQjY41hH/t+u55Knxi/0wesMzwQRhppK6Ddalhu0TEttbiJ+wRcoEj5Q==", + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.5.6.tgz", + "integrity": "sha512-CFHvP9Qz98NruJiUnCe61O6GveKKHpJLloXbDSWRhqhkJdZD2zU5hG+gtVJR//tyW897izuHpM6Gtf6+sNgJPQ==", "cpu": [ "x64" ], @@ -3235,9 +3235,9 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "13.4.19", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.19.tgz", - "integrity": "sha512-bUfDevQK4NsIAHXs3/JNgnvEY+LRyneDN788W2NYiRIIzmILjba7LaQTfihuFawZDhRtkYCv3JDC3B4TwnmRJw==", + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.5.6.tgz", + "integrity": "sha512-aFv1ejfkbS7PUa1qVPwzDHjQWQtknzAZWGTKYIAaS4NMtBlk3VyA6AYn593pqNanlicewqyl2jUhQAaFV/qXsg==", "cpu": [ "arm64" ], @@ -3250,9 +3250,9 @@ } }, "node_modules/@next/swc-win32-ia32-msvc": { - "version": "13.4.19", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.19.tgz", - "integrity": "sha512-Y5kikILFAr81LYIFaw6j/NrOtmiM4Sf3GtOc0pn50ez2GCkr+oejYuKGcwAwq3jiTKuzF6OF4iT2INPoxRycEA==", + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.5.6.tgz", + "integrity": "sha512-XqqpHgEIlBHvzwG8sp/JXMFkLAfGLqkbVsyN+/Ih1mR8INb6YCc2x/Mbwi6hsAgUnqQztz8cvEbHJUbSl7RHDg==", "cpu": [ "ia32" ], @@ -3265,9 +3265,9 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "13.4.19", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.19.tgz", - "integrity": "sha512-YzA78jBDXMYiINdPdJJwGgPNT3YqBNNGhsthsDoWHL9p24tEJn9ViQf/ZqTbwSpX/RrkPupLfuuTH2sf73JBAw==", + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.5.6.tgz", + "integrity": "sha512-Cqfe1YmOS7k+5mGu92nl5ULkzpKuxJrP3+4AEuPmrpFZ3BHxTY3TnHmU1On3bFmFFs6FbTcdF58CCUProGpIGQ==", "cpu": [ "x64" ], @@ -3538,14 +3538,14 @@ "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==" }, "node_modules/@pm2/js-api": { - "version": "0.6.7", - "resolved": "https://registry.npmjs.org/@pm2/js-api/-/js-api-0.6.7.tgz", - "integrity": "sha512-jiJUhbdsK+5C4zhPZNnyA3wRI01dEc6a2GhcQ9qI38DyIk+S+C8iC3fGjcjUbt/viLYKPjlAaE+hcT2/JMQPXw==", + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@pm2/js-api/-/js-api-0.8.0.tgz", + "integrity": "sha512-nmWzrA/BQZik3VBz+npRcNIu01kdBhWL0mxKmP1ciF/gTcujPTQqt027N9fc1pK9ERM8RipFhymw7RcmCyOEYA==", "dependencies": { "async": "^2.6.3", - "axios": "^0.21.0", "debug": "~4.3.1", "eventemitter2": "^6.3.1", + "extrareqp2": "^1.0.0", "ws": "^7.0.0" }, "engines": { @@ -7760,14 +7760,6 @@ "node": ">=4" } }, - "node_modules/axios": { - "version": "0.21.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", - "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", - "dependencies": { - "follow-redirects": "^1.14.0" - } - }, "node_modules/axobject-query": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz", @@ -10194,6 +10186,14 @@ "url": "https://github.com/sponsors/jaydenseric" } }, + "node_modules/extrareqp2": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/extrareqp2/-/extrareqp2-1.0.0.tgz", + "integrity": "sha512-Gum0g1QYb6wpPJCVypWP3bbIuaibcFiJcpuPM10YSXp/tzqi84x9PJageob+eN4xVRIOto4wjSGNLyMD54D2xA==", + "dependencies": { + "follow-redirects": "^1.14.0" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -10342,9 +10342,9 @@ "integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==" }, "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.5", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", + "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", "funding": [ { "type": "individual", @@ -15166,9 +15166,9 @@ "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==" }, "node_modules/nanoid": { - "version": "3.3.6", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", - "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", + "version": "3.3.7", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", + "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", "funding": [ { "type": "github", @@ -15231,35 +15231,34 @@ } }, "node_modules/next": { - "version": "13.4.19", - "resolved": "https://registry.npmjs.org/next/-/next-13.4.19.tgz", - "integrity": "sha512-HuPSzzAbJ1T4BD8e0bs6B9C1kWQ6gv8ykZoRWs5AQoiIuqbGHHdQO7Ljuvg05Q0Z24E2ABozHe6FxDvI6HfyAw==", + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/next/-/next-13.5.6.tgz", + "integrity": "sha512-Y2wTcTbO4WwEsVb4A8VSnOsG1I9ok+h74q0ZdxkwM3EODqrs4pasq7O0iUxbcS9VtWMicG7f3+HAj0r1+NtKSw==", "dependencies": { - "@next/env": "13.4.19", - "@swc/helpers": "0.5.1", + "@next/env": "13.5.6", + "@swc/helpers": "0.5.2", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001406", - "postcss": "8.4.14", + "postcss": "8.4.31", "styled-jsx": "5.1.1", - "watchpack": "2.4.0", - "zod": "3.21.4" + "watchpack": "2.4.0" }, "bin": { "next": "dist/bin/next" }, "engines": { - "node": ">=16.8.0" + "node": ">=16.14.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "13.4.19", - "@next/swc-darwin-x64": "13.4.19", - "@next/swc-linux-arm64-gnu": "13.4.19", - "@next/swc-linux-arm64-musl": "13.4.19", - "@next/swc-linux-x64-gnu": "13.4.19", - "@next/swc-linux-x64-musl": "13.4.19", - "@next/swc-win32-arm64-msvc": "13.4.19", - "@next/swc-win32-ia32-msvc": "13.4.19", - "@next/swc-win32-x64-msvc": "13.4.19" + "@next/swc-darwin-arm64": "13.5.6", + "@next/swc-darwin-x64": "13.5.6", + "@next/swc-linux-arm64-gnu": "13.5.6", + "@next/swc-linux-arm64-musl": "13.5.6", + "@next/swc-linux-x64-gnu": "13.5.6", + "@next/swc-linux-x64-musl": "13.5.6", + "@next/swc-win32-arm64-msvc": "13.5.6", + "@next/swc-win32-ia32-msvc": "13.5.6", + "@next/swc-win32-x64-msvc": "13.5.6" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", @@ -15311,21 +15310,13 @@ } }, "node_modules/next/node_modules/@swc/helpers": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.1.tgz", - "integrity": "sha512-sJ902EfIzn1Fa+qYmjdQqh8tPsoxyBz+8yBKC2HKUxyezKJFwPGOn7pv4WY6QuQW//ySQi5lJjA/ZT9sNWWNTg==", + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.2.tgz", + "integrity": "sha512-E4KcWTpoLHqwPHLxidpOqQbcrZVgi0rsmmZXUle1jXmJfuIf/UWpczUJ7MZZ5tlxytgJXyp0w4PGkkeLiuIdZw==", "dependencies": { "tslib": "^2.4.0" } }, - "node_modules/next/node_modules/zod": { - "version": "3.21.4", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz", - "integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==", - "funding": { - "url": "https://github.com/sponsors/colinhacks" - } - }, "node_modules/nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", @@ -16240,13 +16231,13 @@ } }, "node_modules/pm2": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/pm2/-/pm2-5.3.0.tgz", - "integrity": "sha512-xscmQiAAf6ArVmKhjKTeeN8+Td7ZKnuZFFPw1DGkdFPR/0Iyx+m+1+OpCdf9+HQopX3VPc9/wqPQHqVOfHum9w==", + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/pm2/-/pm2-5.3.1.tgz", + "integrity": "sha512-DLVQHpSR1EegaTaRH3KbRXxpPVaqYwAp3uHSCtCsS++LSErvk07WSxuUnntFblBRqNU/w2KQyqs12mSq5wurkg==", "dependencies": { "@pm2/agent": "~2.0.0", "@pm2/io": "~5.0.0", - "@pm2/js-api": "~0.6.7", + "@pm2/js-api": "~0.8.0", "@pm2/pm2-version-check": "latest", "async": "~3.2.0", "blessed": "0.1.81", @@ -16437,9 +16428,9 @@ } }, "node_modules/postcss": { - "version": "8.4.14", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", - "integrity": "sha512-E398TUmfAYFPBSdzgeieK2Y1+1cpdxJx8yXbK/m57nRhKSmk1GB2tO4lbLBtlkfPQTDKfe4Xqv1ASWPpayPEig==", + "version": "8.4.31", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", + "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==", "funding": [ { "type": "opencollective", @@ -16448,10 +16439,14 @@ { "type": "tidelift", "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" } ], "dependencies": { - "nanoid": "^3.3.4", + "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" }, diff --git a/package.json b/package.json index 9dbe54c..afcb269 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "hastscript": "^7.2.0", "isomorphic-fetch": "^3.0.0", "markdownlint-cli": "^0.37.0", - "next": "13.4.19", + "next": "^13.5.6", "next-mdx-remote": "^4.4.1", "node-html-markdown": "^1.3.0", "plyr-react": "^5.3.0", diff --git a/scripts/coverage/enums.mjs b/scripts/coverage/enums.mjs new file mode 100644 index 0000000..570501e --- /dev/null +++ b/scripts/coverage/enums.mjs @@ -0,0 +1,47 @@ +import { visit } from 'unist-util-visit'; + +import { GET_ENUMS } from './queries.mjs'; +import { + fetchItems, + compare, + getHeadings, + getAST, + compareFields, +} from './utils.mjs'; + +const enumExceptions = ['__DirectiveLocation', '__TypeKind']; + +export function getEnumValuesFromDocs(filepath) { + const ast = getAST(filepath); + let currentHeading; + const args = {}; + visit(ast, '', (node, _i, parent) => { + if (node.type === 'heading') { + currentHeading = node.children[0].value; + } else if ( + currentHeading && + currentHeading !== node.value && + node.type === 'inlineCode' && + parent.children[0].value === node.value && + parent.children[1] + ) { + if (!args[currentHeading]) { + args[currentHeading] = []; + } + args[currentHeading].push({ name: node.value }); + } + }); + return args; +} + +export async function checkEnums() { + const filepath = 'docs/reference/enums.mdx'; + const rawEnums = await fetchItems(GET_ENUMS, 'ENUM'); + const enums = rawEnums.filter((item) => !enumExceptions.includes(item.name)); + const names = enums.map((item) => item.name); + const headings = await getHeadings(filepath); + compare(names, headings, enumExceptions, `ENUMs`); + + const fieldsFromDocs = getEnumValuesFromDocs(filepath); + compareFields(enums, fieldsFromDocs, 'enumValues', 'ENUM'); +} diff --git a/scripts/coverage/index.mjs b/scripts/coverage/index.mjs new file mode 100644 index 0000000..162a66a --- /dev/null +++ b/scripts/coverage/index.mjs @@ -0,0 +1,65 @@ +import { checkEnums } from './enums.mjs'; +import { checkAllObjects } from './objects.mjs'; +import { + GET_QUERIES, + GET_SCALARS, + GET_MUTATIONS, + GET_SUBSCRIPTIONS, +} from './queries.mjs'; +import { checkUnions } from './unions.mjs'; +import { checkHeadings, fetchNames, getHeadings, compare } from './utils.mjs'; + +const scalarExceptions = ['Boolean', 'Float', 'ID', 'Int', 'String']; +const queryExceptions = ['register', 'memory']; + +async function checkScalars() { + const names = await fetchNames(GET_SCALARS, 'SCALAR'); + const headings = await getHeadings('docs/reference/scalars.mdx'); + compare(names, headings, scalarExceptions, 'SCALARs'); +} + +async function checkQueries() { + await checkHeadings( + 'docs/reference/queries.mdx', + GET_QUERIES, + 'QUERY', + queryExceptions, + 'queryType' + ); +} + +async function checkMutations() { + await checkHeadings( + 'docs/reference/mutations.mdx', + GET_MUTATIONS, + 'MUTATION', + [], + 'mutationType' + ); +} + +async function checkSubscriptions() { + await checkHeadings( + 'docs/reference/subscriptions.mdx', + GET_SUBSCRIPTIONS, + 'SUBSCRIPTION', + [], + 'subscriptionType' + ); +} + +async function checkDocs() { + await checkScalars(); + await checkEnums(); + await checkUnions(); + await checkAllObjects(); + await checkQueries(); + await checkMutations(); + await checkSubscriptions(); +} + +await checkDocs(); + +// TODO: +// CHECK FOR RETURN TYPES FOR QUERIES, MUTATIONS, SUBSCRIPTIONS +// CHECK FOR LINKS TO RELEVANT TYPES diff --git a/scripts/coverage/objects.mjs b/scripts/coverage/objects.mjs new file mode 100644 index 0000000..b2a9a60 --- /dev/null +++ b/scripts/coverage/objects.mjs @@ -0,0 +1,116 @@ +import { assert } from 'console'; + +import { GET_INPUT_OBJECTS, GET_OBJECTS } from './queries.mjs'; +import { + compare, + getHeadings, + getArgsOrFields, + checkIfEqual, + request, + getType, +} from './utils.mjs'; + +const objectExceptions = [ + '__Directive', + '__EnumValue', + '__Field', + '__InputValue', + '__Schema', + '__Type', + 'Query', + 'Mutation', + 'Subscription', + 'PageInfo', +]; + +// checks to make sure: +// every INPUT_OBJECT and OBJECT from the API is included in the headings in docs/reference/objects.mdx +// there are no headings that are not in the API +// all fields in the API match the fields in the docs +export async function checkAllObjects() { + const filepath = 'docs/reference/objects.mdx'; + const headings = await getHeadings(filepath); + const actual = await checkHeadings(headings); + checkForExtraHeadings(actual, headings); + checkObjectFields(actual, filepath); +} + +async function fetchObjects(query, kind) { + try { + const response = await request(query); + const objects = response.data.__schema.types + .filter((type) => type.kind === kind) + .filter( + (type) => + !type.name.endsWith('Connection') && !type.name.endsWith('Edge') + ) + .map((item) => { + const newItem = { name: item.name }; + const fields = item.fields || item.inputFields; + if (fields) { + newItem.fields = fields.map((field) => ({ + name: field.name, + type: getType(field.type), + })); + } + return newItem; + }); + return objects; + } catch (error) { + console.error(`Error fetching ${kind} names:`, error); + return []; + } +} + +async function checkHeadings(headings) { + const inputObjects = await fetchObjects(GET_INPUT_OBJECTS, 'INPUT_OBJECT'); + const inputObjectNames = inputObjects.map((item) => item.name); + compare(inputObjectNames, headings, [], `INPUT_OBJECTs`); + + const objects = await fetchObjects(GET_OBJECTS, 'OBJECT'); + const objectNames = objects.map((item) => item.name); + compare(objectNames, headings, objectExceptions, `OBJECTs`); + + const actual = [...inputObjects, ...objects].filter( + (item) => !objectExceptions.includes(item.name) + ); + return actual; +} + +function checkForExtraHeadings(actual, headings) { + const extraHeadings = []; + headings.forEach((item) => { + if (!actual.map((item) => item.name).includes(item)) { + extraHeadings.push(item); + } + }); + assert( + extraHeadings.length === 0, + `EXTRA HEADINGS IN OBJECTS: ${extraHeadings}` + ); +} + +function checkObjectFields(actual, filepath) { + const fields = getArgsOrFields(filepath, 'fields:'); + const wrongFields = []; + actual.forEach((item) => { + if (item.fields) { + const fieldsFromDocs = fields[item.name]; + if (!fieldsFromDocs) { + console.log('NO FIELDS IN DOCS:', item.name); + wrongFields.push(item.name); + } else { + const fieldsMatch = checkIfEqual(item.fields, fieldsFromDocs); + if (!fieldsMatch) { + console.log( + `DIFF FIELDS IN DOCS FOR ${item.name}:`, + item.fields, + fieldsFromDocs + ); + wrongFields.push(item.name); + } + } + } + }); + assert(wrongFields.length === 0, `WRONG FIELDS IN OBJECTS: ${wrongFields}`); +} diff --git a/scripts/coverage/queries.mjs b/scripts/coverage/queries.mjs new file mode 100644 index 0000000..f60a72b --- /dev/null +++ b/scripts/coverage/queries.mjs @@ -0,0 +1,247 @@ +export const GET_SCALARS = ` +query IntrospectionQuery { + __schema { + types { + kind + name + } + } +} +`; + +export const GET_ENUMS = ` +query IntrospectionQuery { + __schema { + types { + kind + name + enumValues { + name + } + } + } +} +`; + +export const GET_UNIONS = ` +query IntrospectionQuery { + __schema { + types { + kind + name + possibleTypes { + name + } + } + } +} +`; + +export const GET_INPUT_OBJECTS = ` +query IntrospectionQuery { + __schema { + types { + kind + name + inputFields { + name + type { + name + kind + ofType { + kind + name + } + } + } + } + } +} +`; + +export const GET_OBJECTS = ` +query IntrospectionQuery { + __schema { + types { + kind + name + fields { + name + type { + name + kind + ofType { + kind + name + } + } + } + } + } +} +`; + +export const GET_QUERIES = ` +query IntrospectionQuery { + __schema { + queryType { + fields { + name + args { + name + type { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } + } + type { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } + } + } + } + } + } +} +`; + +export const GET_MUTATIONS = ` +query IntrospectionQuery { + __schema { + mutationType { + fields { + name + args { + name + type { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } + } + } + type { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } + } + } + } + } +} +`; + +export const GET_SUBSCRIPTIONS = ` + query IntrospectionQuery { + __schema { + subscriptionType { + fields { + name + args { + name + type { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } + } + } + type { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } + } + } + } + } + } +`; diff --git a/scripts/coverage/unions.mjs b/scripts/coverage/unions.mjs new file mode 100644 index 0000000..03ebe60 --- /dev/null +++ b/scripts/coverage/unions.mjs @@ -0,0 +1,50 @@ +import { visit } from 'unist-util-visit'; + +import { GET_UNIONS } from './queries.mjs'; +import { + compareFields, + fetchItems, + getAST, + getHeadings, + compare, +} from './utils.mjs'; + +export function getUnionFieldsFromDocs(filepath) { + const ast = getAST(filepath); + const headingArgs = {}; + let currentHeading = ''; + const args = {}; + visit(ast, '', (node, _i, parent) => { + if (node.type === 'heading') { + currentHeading = node.children[0].value; + } + + if (node.value === 'Types:') { + headingArgs[currentHeading] = true; + } + + if ( + headingArgs[currentHeading] && + node.type === 'inlineCode' && + parent.type !== 'paragraph' + ) { + if (!args[currentHeading]) { + args[currentHeading] = []; + } + args[currentHeading].push({ name: node.value }); + } + }); + return args; +} + +export async function checkUnions() { + const filepath = 'docs/reference/unions.mdx'; + const unions = await fetchItems(GET_UNIONS, 'UNION'); + + const unionNames = unions.map((union) => union.name); + const headings = await getHeadings(filepath); + compare(unionNames, headings, [], 'UNIONs'); + + const unionsFromDocs = getUnionFieldsFromDocs(filepath); + compareFields(unions, unionsFromDocs, 'possibleTypes', 'UNION'); +} diff --git a/scripts/coverage/utils.mjs b/scripts/coverage/utils.mjs new file mode 100644 index 0000000..8d772d8 --- /dev/null +++ b/scripts/coverage/utils.mjs @@ -0,0 +1,274 @@ +import { assert } from 'console'; +import { readFileSync } from 'fs'; +import remarkParse from 'remark-parse'; +import { unified } from 'unified'; +import { visit } from 'unist-util-visit'; + +const inputArgExceptions = ['first', 'last', 'after', 'before']; + +const headingsExceptions = (heading) => { + if (heading.startsWith('title: ')) { + return false; + } + if ( + [ + 'Queries', + 'Mutations', + 'Subscriptions', + 'Objects', + 'Union Types', + 'Enums', + 'Scalars', + ].includes(heading) + ) { + return false; + } + return true; +}; + +export async function getHeadings(filepath) { + const file = readFileSync(filepath, 'utf8'); + const processor = unified().use(remarkParse); + const ast = processor.parse(file); + const headings = []; + visit(ast, 'heading', (node) => { + headings.push(node.children[0].value); + }); + return headings.filter(headingsExceptions); +} + +export async function request(query) { + const response = await fetch('https://beta-5.fuel.network/graphql', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + body: JSON.stringify({ + query, + }), + }); + const json = await response.json(); + return json; +} + +export async function fetchItems(query, kind) { + try { + const response = await request(query); + const objects = response.data.__schema.types + .filter((type) => type.kind === kind) + .filter( + (type) => + !type.name.endsWith('Connection') && !type.name.endsWith('Edge') + ); + return objects; + } catch (error) { + console.error(`Error fetching ${kind} names:`, error); + return []; + } +} + +export async function fetchNames(query, kind) { + const objects = await fetchItems(query, kind); + const names = objects.map((object) => object.name); + return names; +} + +export function compare(actual, headings, exceptions, itemName) { + const missing = []; + actual.forEach((item) => { + const isIncluded = headings.includes(item); + if (!isIncluded) { + if (!exceptions.includes(item)) { + missing.push(item); + } + } + }); + assert(missing.length === 0, `MISSING FROM ${itemName}: ${missing}`); + + if (itemName === 'INPUT_OBJECTs' || itemName === 'OBJECTs') { + return; + } + + const extraHeadings = []; + headings.forEach((item) => { + if (!actual.includes(item)) { + extraHeadings.push(item); + } + }); + + assert( + extraHeadings.length === 0, + `EXTRA HEADINGS IN ${itemName}: ${extraHeadings}` + ); +} + +export function getType(type) { + if (!type) { + return null; + } + + if (type.name) { + return type.name; + } + + let nestedTypeName = getType(type.ofType); + + if (type.kind === 'LIST') { + return `[${nestedTypeName}]`; + } else if (type.kind === 'NON_NULL') { + return `${nestedTypeName}!`; + } + + return nestedTypeName; +} + +function processData(fields, exceptions) { + return fields + .filter((query) => !exceptions.includes(query.name)) + .map((query) => ({ + name: query.name, + args: query.args.map((arg) => ({ + name: arg.name, + type: getType(arg.type), + })), + returnType: getType(query.type), + })); +} + +export async function fetchData(query, kind, exceptions, schemaType) { + try { + const response = await request(query); + const fields = response.data.__schema[schemaType].fields; + return processData(fields, exceptions); + } catch (error) { + console.error(`Error fetching ${kind} names:`, error); + return []; + } +} + +export function getAST(filepath) { + const file = readFileSync(filepath, 'utf8'); + const processor = unified().use(remarkParse); + const ast = processor.parse(file); + return ast; +} + +export function getArgsOrFields(filepath, name) { + const ast = getAST(filepath); + const headingArgs = {}; + let currentHeading = ''; + let currentIndex = 0; + const args = {}; + visit(ast, '', (node, _i, parent) => { + if (node.type === 'heading') { + currentHeading = node.children[0].value; + } + + if (node.value === name) { + headingArgs[currentHeading] = true; + } + + if (headingArgs[currentHeading] && node.type === 'inlineCode') { + if ( + (parent.children[1] && parent.children[1].value === ': ') || + parent.children[1] === undefined + ) { + if (args[currentHeading] && !args[currentHeading][currentIndex].type) { + args[currentHeading][currentIndex].type = node.value; + } else { + if (!args[currentHeading]) { + args[currentHeading] = []; + } + args[currentHeading].push({ name: node.value }); + currentIndex = args[currentHeading].length - 1; + } + } + } + }); + return args; +} + +export function checkIfEqual(a, b) { + if (a.length !== b.length) { + console.log('DIFFERENT LENGTHS'); + return false; + } + + return a.every((value, index) => { + const bVal = b[index]; + const isEqual = value.id === bVal.id && value.name === bVal.name; + if (!isEqual) { + console.log('*********NOT EQUAL*********'); + console.log('VALUE A:', value); + console.log('VALUE B:', bVal); + } + return isEqual; + }); +} + +export async function checkHeadings( + filepath, + query, + kind, + exceptions, + schemaType +) { + const headings = await getHeadings(filepath); + const args = getArgsOrFields(filepath, 'args:'); + const items = await fetchData(query, kind, exceptions, schemaType); + const missing = []; + const wrongArgs = []; + items.forEach((item) => { + if (!headings.includes(item.name)) { + missing.push(item.name); + } + + const cleanedArgs = item.args.filter( + (arg) => !inputArgExceptions.includes(arg.name) + ); + if (cleanedArgs && cleanedArgs.length > 0) { + const argsFromDocs = args[item.name]; + if (!argsFromDocs) { + console.log('NO ARGS IN DOCS:', item.name); + wrongArgs.push(item.name); + } else { + const argsMatch = checkIfEqual(cleanedArgs, argsFromDocs); + if (!argsMatch) { + console.log( + `DIFF ARGS IN DOCS FOR ${item.name}:`, + cleanedArgs, + argsFromDocs + ); + wrongArgs.push(item.name); + } + } + } + }); + assert(missing.length === 0, `MISSING FROM ${kind}: ${missing}`); + assert(wrongArgs.length === 0, `ARGS ARE WRONG IN ${kind}: ${wrongArgs}`); +} + +export function compareFields(actual, docs, fieldName, kind) { + const wrongFields = []; + actual.forEach((item) => { + if (item[fieldName]) { + const fieldsFromDocs = docs[item.name]; + if (!fieldsFromDocs) { + console.log('NO FIELDS IN DOCS:', item.name); + wrongFields.push(item.name); + } else { + const fieldsMatch = checkIfEqual(item[fieldName], fieldsFromDocs); + if (!fieldsMatch) { + console.log( + `DIFF FIELDS IN DOCS FOR ${item.name}:`, + item[fieldName], + fieldsFromDocs + ); + wrongFields.push(item.name); + } + } + } + }); + assert(wrongFields.length === 0, `WRONG FIELDS IN ${kind}: ${wrongFields}`); +} diff --git a/spell-check-custom-words.txt b/spell-check-custom-words.txt index b587e2b..cf3e927 100644 --- a/spell-check-custom-words.txt +++ b/spell-check-custom-words.txt @@ -72,4 +72,7 @@ merkle Merkle mempool EOA -args \ No newline at end of file +args +breakpoint +PeerInfo +Unix \ No newline at end of file diff --git a/src/components/CodeExamples.tsx b/src/components/CodeExamples.tsx index 0045041..e9793f8 100644 --- a/src/components/CodeExamples.tsx +++ b/src/components/CodeExamples.tsx @@ -58,7 +58,7 @@ export function CodeExamples({ const apolloImport = `import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; const apolloClient= new ApolloClient({ - uri: 'https://beta-4.fuel.network/graphql', + uri: 'https://beta-5.fuel.network/graphql', 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-4.fuel.network/graphql', + url: 'https://beta-5.fuel.network/graphql', exchanges: [cacheExchange, fetchExchange], });