-
Notifications
You must be signed in to change notification settings - Fork 17
Update examples export to be published to NPM #2130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
2ed324c
e6413bb
100fda5
6239a61
410e6ff
d5ce33d
ca6540a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,7 @@ | |
| import { useSearchParams } from "next/navigation"; | ||
| import { useMemo } from "react"; | ||
|
|
||
| import { getNamespaceSpecificValue } from "@ensnode/ensnode-sdk"; | ||
| import { GRAPHQL_API_EXAMPLE_QUERIES } from "@ensnode/ensnode-sdk/internal"; | ||
| import { GRAPHQL_API_EXAMPLE_QUERIES, getNamespaceSpecificValue } from "@ensnode/ensnode-sdk"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| import { GraphiQLEditor } from "@/components/graphiql-editor"; | ||
| import { RequireENSAdminFeature } from "@/components/require-ensadmin-feature"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,20 +33,38 @@ const ENS_TEST_ENV_V2_ETH_REGISTRAR = maybeGetDatasourceContract( | |
| const VITALIK_ADDRESS = toNormalizedAddress("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"); | ||
|
|
||
| // owns sfmonicdeb*.eth (mix of v1 + v2) on sepolia-v2 and holds v2 ETHRegistry permissions | ||
| const SEPOLIA_V2_USER_ADDRESS = toNormalizedAddress("0x2f8e8b1126e75fde0b7f731e7cb5847eba2d2574"); | ||
| const _SEPOLIA_V2_USER_ADDRESS = toNormalizedAddress("0x2f8e8b1126e75fde0b7f731e7cb5847eba2d2574"); | ||
|
|
||
|
Comment on lines
35
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const SEPOLIA_V2_ADDRESS_WITH_LOT_OF_NAMES = toNormalizedAddress( | ||
| "0x205d2686da3bf33f64c17f21462c51b5ead462cf", | ||
| ); | ||
|
Comment on lines
+36
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the Sepolia V2 fixtures that actually demonstrate permissions. Line 35 introduces Suggested patch variables: {
// TODO: same as above
default: { contract: ENS_TEST_ENV_V2_ETH_REGISTRAR },
- // TODO: example response is empty for this address on Sepolia V2
- [ENSNamespaceIds.SepoliaV2]: { contract: SEPOLIA_V2_V2_ETH_REGISTRAR },
+ [ENSNamespaceIds.SepoliaV2]: { contract: SEPOLIA_V2_V2_ETH_REGISTRY },
},
},
@@
variables: {
default: { address: accounts.deployer.address },
- // TODO: example response is empty for this address on Sepolia V2
- [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_ADDRESS_WITH_LOT_OF_NAMES },
+ [ENSNamespaceIds.SepoliaV2]: { address: _SEPOLIA_V2_USER_ADDRESS },
},
},Also applies to: 300-304, 326-329 🤖 Prompt for AI Agents |
||
|
|
||
| const DEVNET_NAME_WITH_OWNED_RESOLVER = asInterpretedName("example.eth"); | ||
|
|
||
| const SEPOLIA_V2_NAME_WITH_OWNED_RESOLVER = asInterpretedName("sfmonicdebmig.eth"); | ||
|
|
||
| export const GRAPHQL_API_EXAMPLE_QUERIES: Array<{ | ||
| const SEPOLIA_V2_TEST_NAME = asInterpretedName("test-name.eth"); | ||
|
|
||
| export type GraphqlApiExampleQuery = { | ||
| id: string; | ||
| query: string; | ||
| variables: NamespaceSpecificValue<Record<string, unknown>>; | ||
| }> = [ | ||
| }; | ||
|
Comment on lines
+48
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win Enforce the query-ID invariant explicitly and fail fast on duplicates. Line 422 currently allows duplicate Suggested patch+export type GraphqlApiExampleQueryId = string;
+
export type GraphqlApiExampleQuery = {
- id: string;
+ id: GraphqlApiExampleQueryId;
query: string;
variables: NamespaceSpecificValue<Record<string, unknown>>;
};
-export function getGraphqlApiExampleQueryById(id: string): GraphqlApiExampleQuery {
+export function getGraphqlApiExampleQueryById(id: GraphqlApiExampleQueryId): GraphqlApiExampleQuery {
const found = graphqlApiExampleQueryById.get(id);
if (!found) {
throw new Error(`Unknown GraphQL API example query id: ${id}`);
}
return found;
}
@@
-const graphqlApiExampleQueryById = new Map(
- GRAPHQL_API_EXAMPLE_QUERIES.map((entry) => [entry.id, entry]),
-);
+const graphqlApiExampleQueryById = (() => {
+ const byId = new Map<GraphqlApiExampleQueryId, GraphqlApiExampleQuery>();
+ for (const entry of GRAPHQL_API_EXAMPLE_QUERIES) {
+ if (byId.has(entry.id)) {
+ throw new Error(`Duplicate GraphQL API example query id: ${entry.id}`);
+ }
+ byId.set(entry.id, entry);
+ }
+ return byId;
+})();Also applies to: 421-423 🤖 Prompt for AI Agents |
||
|
|
||
| export function getGraphqlApiExampleQueryById(id: string): GraphqlApiExampleQuery { | ||
| const found = graphqlApiExampleQueryById.get(id); | ||
| if (!found) { | ||
| throw new Error(`Unknown GraphQL API example query id: ${id}`); | ||
| } | ||
| return found; | ||
| } | ||
|
|
||
| export const GRAPHQL_API_EXAMPLE_QUERIES: GraphqlApiExampleQuery[] = [ | ||
| //////////////// | ||
| // Hello World | ||
| //////////////// | ||
| { | ||
| id: "hello-world", | ||
| query: `# | ||
| # Welcome to this interactive playground for | ||
| # ENSNode's GraphQL API! | ||
|
|
@@ -56,7 +74,7 @@ export const GRAPHQL_API_EXAMPLE_QUERIES: Array<{ | |
| # | ||
| # There are also example queries in the tabs above ☝️ | ||
| query HelloWorld { | ||
| domain(by: { name: "eth" }) { name owner { address } } | ||
| domain(by: { name: "eth" }) { canonical { name } owner { address } } | ||
| }`, | ||
|
Comment on lines
74
to
78
|
||
| variables: { default: {} }, | ||
| }, | ||
|
|
@@ -65,9 +83,10 @@ query HelloWorld { | |
| // Find Domains | ||
| ///////////////// | ||
| { | ||
| id: "find-domains", | ||
| query: ` | ||
| query FindDomains( | ||
| $name: String! | ||
| $name: DomainsNameFilter! | ||
| $order: DomainsOrderInput | ||
| ) { | ||
| domains( | ||
|
|
@@ -80,62 +99,65 @@ query FindDomains( | |
| __typename | ||
| id | ||
| label { interpreted hash } | ||
| name | ||
| canonical { name } | ||
|
|
||
| registration { expiry event { timestamp } } | ||
| } | ||
| } | ||
| } | ||
| }`, | ||
| variables: { | ||
| default: { name: "vitalik", order: { by: "NAME", dir: "DESC" } }, | ||
| [ENSNamespaceIds.EnsTestEnv]: { name: "c", order: { by: "NAME", dir: "DESC" } }, | ||
| [ENSNamespaceIds.SepoliaV2]: { name: "sfmonic", order: { by: "NAME", dir: "DESC" } }, | ||
| default: { name: { starts_with: "vitalik" }, order: { by: "NAME", dir: "DESC" } }, | ||
| [ENSNamespaceIds.EnsTestEnv]: { | ||
| name: { starts_with: "c" }, | ||
| order: { by: "NAME", dir: "DESC" }, | ||
| }, | ||
| [ENSNamespaceIds.SepoliaV2]: { | ||
| name: { starts_with: "test-na" }, | ||
| order: { by: "NAME", dir: "DESC" }, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| /////////////////// | ||
| // Domain By Name | ||
| /////////////////// | ||
| { | ||
| id: "domain-by-name", | ||
| query: ` | ||
| query DomainByName($name: InterpretedName!) { | ||
| domain(by: {name: $name}) { | ||
| __typename | ||
| id | ||
| label { interpreted hash } | ||
| name | ||
| canonical { name node path { id } } | ||
| owner { address } | ||
| subregistry { contract { chainId address } } | ||
|
|
||
| ... on ENSv1Domain { | ||
| rootRegistryOwner { address } | ||
| } | ||
|
|
||
|
|
||
| ... on ENSv2Domain { | ||
| subregistry { | ||
| contract { chainId address } | ||
| } | ||
| } | ||
| } | ||
| }`, | ||
| variables: { | ||
| default: { name: "eth" }, | ||
| [ENSNamespaceIds.SepoliaV2]: { name: "sfmonicdebmig.eth" }, | ||
| [ENSNamespaceIds.SepoliaV2]: { name: SEPOLIA_V2_TEST_NAME }, | ||
| }, | ||
| }, | ||
|
|
||
| ////////////////////// | ||
| // Domain Subdomains | ||
| ////////////////////// | ||
| { | ||
| id: "domain-subdomains", | ||
| query: ` | ||
| query DomainSubdomains($name: InterpretedName!) { | ||
| domain(by: {name: $name}) { | ||
| name | ||
| canonical { name } | ||
| subdomains(first: 10) { | ||
| edges { | ||
| node { | ||
| name | ||
| canonical { name } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -148,6 +170,7 @@ query DomainSubdomains($name: InterpretedName!) { | |
| // Domain Events | ||
| ///////////////// | ||
| { | ||
| id: "domain-events", | ||
| query: ` | ||
| query DomainEvents($name: InterpretedName!) { | ||
| domain(by: {name: $name}) { | ||
|
|
@@ -176,6 +199,7 @@ query DomainEvents($name: InterpretedName!) { | |
| // Account Domains | ||
| //////////////////// | ||
| { | ||
| id: "domains-by-address", | ||
| query: ` | ||
| query AccountDomains( | ||
| $address: Address! | ||
|
|
@@ -185,7 +209,7 @@ query AccountDomains( | |
| edges { | ||
| node { | ||
| label { interpreted } | ||
| name | ||
| canonical { name } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -194,14 +218,15 @@ query AccountDomains( | |
| variables: { | ||
| default: { address: VITALIK_ADDRESS }, | ||
| [ENSNamespaceIds.EnsTestEnv]: { address: accounts.owner.address }, | ||
| [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_USER_ADDRESS }, | ||
| [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_ADDRESS_WITH_LOT_OF_NAMES }, | ||
| }, | ||
| }, | ||
|
|
||
| //////////////////// | ||
| // Account Events | ||
| //////////////////// | ||
| { | ||
| id: "account-events", | ||
| query: ` | ||
| query AccountEvents( | ||
| $address: Address! | ||
|
|
@@ -213,14 +238,15 @@ query AccountEvents( | |
| variables: { | ||
| default: { address: VITALIK_ADDRESS }, | ||
| [ENSNamespaceIds.EnsTestEnv]: { address: accounts.deployer.address }, | ||
| [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_USER_ADDRESS }, | ||
| [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_ADDRESS_WITH_LOT_OF_NAMES }, | ||
| }, | ||
| }, | ||
|
|
||
| ///////////////////// | ||
| // Registry Domains | ||
| ///////////////////// | ||
| { | ||
| id: "registry-domains", | ||
| query: ` | ||
| query RegistryDomains( | ||
| $registry: AccountIdInput! | ||
|
|
@@ -230,7 +256,7 @@ query RegistryDomains( | |
| edges { | ||
| node { | ||
| label { interpreted } | ||
| name | ||
| canonical { name } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -247,6 +273,7 @@ query RegistryDomains( | |
| // Permissions By Contract | ||
| //////////////////////////// | ||
| { | ||
| id: "permissions-by-contract", | ||
| query: ` | ||
| query PermissionsByContract( | ||
| $contract: AccountIdInput! | ||
|
|
@@ -274,6 +301,7 @@ query PermissionsByContract( | |
| variables: { | ||
| // TODO: same as above | ||
| default: { contract: ENS_TEST_ENV_V2_ETH_REGISTRAR }, | ||
| // TODO: example response is empty for this address on Sepolia V2 | ||
| [ENSNamespaceIds.SepoliaV2]: { contract: SEPOLIA_V2_V2_ETH_REGISTRAR }, | ||
| }, | ||
| }, | ||
|
|
@@ -282,6 +310,7 @@ query PermissionsByContract( | |
| // Permissions By User | ||
| //////////////////////// | ||
| { | ||
| id: "permissions-by-user", | ||
| query: ` | ||
| query PermissionsByUser($address: Address!) { | ||
| account(by: { address: $address }) { | ||
|
|
@@ -297,14 +326,16 @@ query PermissionsByUser($address: Address!) { | |
| }`, | ||
| variables: { | ||
| default: { address: accounts.deployer.address }, | ||
| [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_USER_ADDRESS }, | ||
| // TODO: example response is empty for this address on Sepolia V2 | ||
| [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_ADDRESS_WITH_LOT_OF_NAMES }, | ||
| }, | ||
| }, | ||
|
|
||
| ////////////////////////////////// | ||
| // Account Resolver Permissions | ||
| ////////////////////////////////// | ||
| { | ||
| id: "account-resolver-permissions", | ||
| query: ` | ||
| query AccountResolverPermissions($address: Address!) { | ||
| account(by: { address: $address }) { | ||
|
|
@@ -323,18 +354,19 @@ query AccountResolverPermissions($address: Address!) { | |
| }`, | ||
| variables: { | ||
| default: { address: accounts.deployer.address }, | ||
| [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_USER_ADDRESS }, | ||
| [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_ADDRESS_WITH_LOT_OF_NAMES }, | ||
| }, | ||
| }, | ||
|
|
||
| ////////////////////////////// | ||
| // Domain's Assigned Resolver | ||
| ////////////////////////////// | ||
| { | ||
| id: "domain-resolver", | ||
| query: ` | ||
| query DomainResolver($name: InterpretedName!) { | ||
| domain(by: { name: $name }) { | ||
| resolver { | ||
| assignedResolver { | ||
| records { edges { node { node keys coinTypes } } } | ||
| permissions { resources { edges { node { resource users { edges { node { user { address } roles } } } } } } } | ||
| events { totalCount edges { node { topics data timestamp } } } | ||
|
|
@@ -352,24 +384,25 @@ query DomainResolver($name: InterpretedName!) { | |
| // Namegraph | ||
| ////////////// | ||
| { | ||
| id: "namegraph", | ||
| query: ` | ||
| query Namegraph { | ||
| root { | ||
| id | ||
| domains { | ||
| edges { | ||
| node { | ||
| name | ||
| canonical { name } | ||
|
|
||
| subdomains { | ||
| edges { | ||
| node { | ||
| name | ||
| canonical { name } | ||
|
|
||
| subdomains { | ||
| edges { | ||
| node { | ||
| name | ||
| canonical { name } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -384,3 +417,7 @@ query Namegraph { | |
| variables: { default: {} }, | ||
| }, | ||
| ]; | ||
|
|
||
| const graphqlApiExampleQueryById = new Map( | ||
| GRAPHQL_API_EXAMPLE_QUERIES.map((entry) => [entry.id, entry]), | ||
| ); | ||
Uh oh!
There was an error while loading. Please reload this page.