Adding Query Functions

After completing your mutation implementation, it's time to move onto the query schema module.

Update your ./src/query/schema.graphql file:

...
#import { Query, Connection } into Tezos from "w3://ens/tezos.web3api.eth"
#import { Network, CustomConnection, DomainInfo } from "../common/schema.graphql"

type Query {
 ...

type Query {
  resolveAddress(
    network: Network!
    address: String!
    custom: CustomConnection
  ): DomainInfo

  resolveDomain(
    network: Network!
    domain: String!
    custom: CustomConnection
  ): DomainInfo
}

Update your ./src/query/index.ts file:

import {
 Network,
 Tezos_Query,
 Input_resolveAddress,
 Input_resolveDomain,
 DomainInfo
} from "./w3";
...
export function resolveDomain(input: Input_resolveDomain): DomainInfo | null {
 if (input.network == Network.custom && input.custom === null) {
   throw new Error(`custom network should have a valid connection and contract address`);
 }
 const address = getConnection(input.network, "NameRegistry", input.custom);
 const domain = encodeToHex(input.domain);
 const record = Tezos_Query.executeTzip16View({
   address: address.contractAddress,
   connection: address.connection,
   viewName: "resolve-name",
   args: '["' + domain + '"]'
 });
 if (record.length === 0) {
   return null
 }
 const domainInfo = <JSON.Obj>JSON.parse(record);
 return {
   Name: input.domain,
   Address: getString(domainInfo, "address"),
   Data: getString(domainInfo, "data"),
   Expiry: getString(domainInfo, "expiry")
 };
}

Last updated