Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
eae25f6
add records resolution
sevenzing Apr 21, 2026
bbf391c
Merge branch 'main' into ll/omnigraph-resolution-api
sevenzing May 19, 2026
e8653a4
small docker fixes
sevenzing May 20, 2026
6ff2930
add graphql styled records selection
sevenzing May 20, 2026
713f1ee
add primary names field in omnigraph
sevenzing May 20, 2026
319a99d
forgot introspection
sevenzing May 20, 2026
32f53c8
remove default chain id and add disableAcceleration
sevenzing May 20, 2026
09b1435
fix docs
sevenzing May 20, 2026
7668d50
fix tests a little bit
sevenzing May 20, 2026
e1e5680
refactor
sevenzing May 20, 2026
2e00efe
Merge branch 'main' into ll/omnigraph-resolution-api
sevenzing May 20, 2026
c88dde2
fix tests
sevenzing May 20, 2026
380dadf
forgot changeset
sevenzing May 20, 2026
4fef571
Merge branch 'main' into ll/omnigraph-resolution-api
sevenzing May 20, 2026
cf7cf01
Merge branch 'main' into ll/omnigraph-resolution-api
sevenzing May 20, 2026
b1232ab
fix PR suggestions
sevenzing May 21, 2026
bf275b9
fix the cast problem
sevenzing May 21, 2026
cbdca11
remove seed-cli
sevenzing May 21, 2026
8acc0b2
Merge branch 'main' into ll/omnigraph-resolution-api
sevenzing May 21, 2026
60d2793
Merge branch 'main' into ll/omnigraph-resolution-api
sevenzing May 22, 2026
0550de5
Merge branch 'main' into ll/omnigraph-resolution-api
sevenzing May 26, 2026
7c80a61
update resolution api
sevenzing May 27, 2026
caa8f76
fix PR comments
sevenzing May 27, 2026
ab2b849
lint + generate
sevenzing May 27, 2026
5b0b1d2
default chain id
sevenzing May 27, 2026
4e94c06
add resolve { } object and trace to resolve { }
sevenzing May 28, 2026
f5bacdd
self review
sevenzing May 28, 2026
c5330f0
fix for greptile review
sevenzing May 28, 2026
6f50a9d
add EMBEDDED_DATA for AccelerationStatus
sevenzing May 28, 2026
a0008ea
self review again
sevenzing May 28, 2026
c5d7818
fix no selection bug
sevenzing May 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/ensapi/src/omnigraph-api/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { AttributeNames, createOpenTelemetryWrapper } from "@pothos/tracing-open
import type {
ChainId,
CoinType,
DefaultableChainId,
DomainId,
Hex,
InterfaceId,
InterpretedLabel,
InterpretedName,
Node,
Expand Down Expand Up @@ -62,7 +64,9 @@ export type BuilderScalars = {
Address: { Input: NormalizedAddress; Output: NormalizedAddress };
Hex: { Input: Hex; Output: Hex };
ChainId: { Input: ChainId; Output: ChainId };
DefaultableChainId: { Input: DefaultableChainId; Output: DefaultableChainId };
CoinType: { Input: CoinType; Output: CoinType };
InterfaceId: { Input: InterfaceId; Output: InterfaceId };
Node: { Input: Node; Output: Node };
InterpretedName: { Input: InterpretedName; Output: InterpretedName };
InterpretedLabel: { Input: InterpretedLabel; Output: InterpretedLabel };
Expand Down
167 changes: 167 additions & 0 deletions apps/ensapi/src/omnigraph-api/lib/build-records-selection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import {
type GraphQLFieldConfigMap,
GraphQLInt,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
type GraphQLResolveInfo,
GraphQLScalarType,
GraphQLString,
Kind,
parse,
} from "graphql";
import { describe, expect, it } from "vitest";

import {
buildRecordsSelectionFromResolveInfo,
EMPTY_RECORDS_SELECTION_MESSAGE,
} from "@/omnigraph-api/lib/build-records-selection";
import {
RECORDS_SELECTION_PARAMETRIC_FIELDS,
RECORDS_SELECTION_SIMPLE_FIELDS,
} from "@/omnigraph-api/lib/records-selection-config";

const stringListArg = new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString)));
const intListArg = new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLInt)));

const mockBigIntArg = new GraphQLNonNull(
new GraphQLScalarType({
name: "BigInt",
serialize: String,
parseValue: (value) => BigInt(value as string | number | bigint),
parseLiteral(ast) {
if (ast.kind === Kind.STRING || ast.kind === Kind.INT) return BigInt(ast.value);
throw new Error("BigInt literal must be a string or integer");
},
}),
);

function buildMockResolvedRecordsType() {
const fields: Record<string, { type: typeof GraphQLString; args?: Record<string, unknown> }> = {};

for (const { graphqlField } of RECORDS_SELECTION_SIMPLE_FIELDS) {
fields[graphqlField] = { type: GraphQLString };
}

for (const { graphqlField, argName } of RECORDS_SELECTION_PARAMETRIC_FIELDS) {
const argType =
argName === "coinTypes"
? intListArg
: argName === "contentTypeMask"
? mockBigIntArg
: stringListArg;
fields[graphqlField] = { type: GraphQLString, args: { [argName]: { type: argType } } };
}

return new GraphQLObjectType({
name: "ResolvedRecords",
fields: fields as GraphQLFieldConfigMap<unknown, unknown>,
});
}

const ResolvedRecordsType = buildMockResolvedRecordsType();

function resolveInfoForRecordsSubselection(subselection: string): GraphQLResolveInfo {
const document = parse(`{ records { ${subselection} } }`);
const operation = document.definitions[0];
if (operation.kind !== "OperationDefinition") throw new Error("expected operation");

const recordsField = operation.selectionSet.selections[0];
if (recordsField.kind !== "Field") throw new Error("expected field");

return {
fieldNodes: [recordsField],
fragments: {},
returnType: ResolvedRecordsType,
variableValues: {},
} as unknown as GraphQLResolveInfo;
}

describe("buildRecordsSelectionFromResolveInfo", () => {
it.each(RECORDS_SELECTION_SIMPLE_FIELDS)(
"selects $graphqlField as $selectionKey",
({ graphqlField, selectionKey }) => {
const info = resolveInfoForRecordsSubselection(graphqlField);
expect(buildRecordsSelectionFromResolveInfo(info)).toEqual({ [selectionKey]: true });
},
);

it.each([
{
subselection: 'texts(keys: ["description"])',
expected: { texts: ["description"] },
},
{
subselection: "addresses(coinTypes: [60])",
expected: { addresses: [60] },
},
{
subselection: 'abi(contentTypeMask: "1")',
expected: { abi: 1n },
},
{
subselection: 'interfaces(ids: ["0x01020304"])',
expected: { interfaces: ["0x01020304"] },
},
])("parses parametric field: $subselection", ({ subselection, expected }) => {
const info = resolveInfoForRecordsSubselection(subselection);
expect(buildRecordsSelectionFromResolveInfo(info)).toEqual(expected);
});

it("builds combined selection across simple and parametric fields", () => {
const info = resolveInfoForRecordsSubselection(`
reverseName
contenthash
texts(keys: ["avatar", "description"])
addresses(coinTypes: [60])
abi(contentTypeMask: "1")
`);

expect(buildRecordsSelectionFromResolveInfo(info)).toEqual({
name: true,
contenthash: true,
texts: ["avatar", "description"],
addresses: [60],
abi: 1n,
});
});

it("ignores __typename", () => {
const info = resolveInfoForRecordsSubselection("__typename reverseName");
expect(buildRecordsSelectionFromResolveInfo(info)).toEqual({ name: true });
});

it("throws when selection is empty", () => {
const info = resolveInfoForRecordsSubselection("__typename");
expect(() => buildRecordsSelectionFromResolveInfo(info)).toThrow(
EMPTY_RECORDS_SELECTION_MESSAGE,
);
});

it("throws when only unknown fields are selected", () => {
const info = {
fieldNodes: [
{
kind: "Field",
name: { kind: "Name", value: "records" },
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "unknownField" },
},
],
},
},
],
fragments: {},
returnType: ResolvedRecordsType,
variableValues: {},
} as unknown as GraphQLResolveInfo;

expect(() => buildRecordsSelectionFromResolveInfo(info)).toThrow(
EMPTY_RECORDS_SELECTION_MESSAGE,
);
});
});
81 changes: 81 additions & 0 deletions apps/ensapi/src/omnigraph-api/lib/build-records-selection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {
type FieldNode,
GraphQLError,
type GraphQLResolveInfo,
getArgumentValues,
getNamedType,
isObjectType,
type SelectionSetNode,
} from "graphql";

import { isSelectionEmpty, type ResolverRecordsSelection } from "@ensnode/ensnode-sdk";

import {
getParametricRecordsSelectionField,
getSimpleRecordsSelectionField,
} from "@/omnigraph-api/lib/records-selection-config";

export const EMPTY_RECORDS_SELECTION_MESSAGE = "Records selection cannot be empty.";

function collectFieldNodes(selectionSet: SelectionSetNode, info: GraphQLResolveInfo): FieldNode[] {
const fields: FieldNode[] = [];

for (const selection of selectionSet.selections) {
if (selection.kind === "Field") {
if (selection.name.value === "__typename") continue;
fields.push(selection);
} else if (selection.kind === "InlineFragment") {
fields.push(...collectFieldNodes(selection.selectionSet, info));
} else if (selection.kind === "FragmentSpread") {
const fragment = info.fragments[selection.name.value];
if (fragment) fields.push(...collectFieldNodes(fragment.selectionSet, info));
}
}

return fields;
}

/**
* Builds a {@link ResolverRecordsSelection} from the GraphQL selection set and field
* arguments on `Domain.records` → `ResolvedRecords`.
*/
export function buildRecordsSelectionFromResolveInfo(
info: GraphQLResolveInfo,
): ResolverRecordsSelection {
const fieldNode = info.fieldNodes[0];
if (!fieldNode?.selectionSet) {
throw new GraphQLError(EMPTY_RECORDS_SELECTION_MESSAGE);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

const returnType = getNamedType(info.returnType);
if (!isObjectType(returnType)) {
throw new GraphQLError("Return type must be an object type.");
}

const selection: ResolverRecordsSelection = {};

for (const childField of collectFieldNodes(fieldNode.selectionSet, info)) {
const graphqlField = childField.name.value;

const simple = getSimpleRecordsSelectionField(graphqlField);
if (simple) {
selection[simple.selectionKey] = true;
continue;
}

const parametric = getParametricRecordsSelectionField(graphqlField);
if (!parametric) continue;

const fieldDef = returnType.getFields()[graphqlField];
if (!fieldDef) continue;

const args = getArgumentValues(fieldDef, childField, info.variableValues);
parametric.applySelection(selection, args);
}

if (isSelectionEmpty(selection)) {
throw new GraphQLError(EMPTY_RECORDS_SELECTION_MESSAGE);
}

return selection;
}
95 changes: 95 additions & 0 deletions apps/ensapi/src/omnigraph-api/lib/records-selection-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type { CoinType, ContentType, InterfaceId } from "enssdk";

import type { ResolverRecordsSelection } from "@ensnode/ensnode-sdk";

export type RecordsSelectionSimpleKey = Extract<
keyof ResolverRecordsSelection,
"name" | "contenthash" | "pubkey" | "dnszonehash" | "version"
>;

export type RecordsSelectionParametricKey = Extract<
keyof ResolverRecordsSelection,
"texts" | "addresses" | "abi" | "interfaces"
>;

export type RecordsSelectionSimpleField = {
graphqlField: string;
selectionKey: RecordsSelectionSimpleKey;
};

export type RecordsSelectionParametricField = {
graphqlField: string;
argName: string;
selectionKey: RecordsSelectionParametricKey;
applySelection: (selection: ResolverRecordsSelection, args: Record<string, unknown>) => void;
};

/**
* GraphQL fields on `ResolvedRecords` that map to boolean flags in {@link ResolverRecordsSelection}.
* Querying the field (no args) selects that record for resolution.
*/
export const RECORDS_SELECTION_SIMPLE_FIELDS = [
{ graphqlField: "reverseName", selectionKey: "name" },
{ graphqlField: "contenthash", selectionKey: "contenthash" },
{ graphqlField: "pubkey", selectionKey: "pubkey" },
{ graphqlField: "dnszonehash", selectionKey: "dnszonehash" },
{ graphqlField: "version", selectionKey: "version" },
] as const satisfies readonly RecordsSelectionSimpleField[];

/**
* GraphQL fields on `ResolvedRecords` that require arguments specifying which records to resolve.
*/
export const RECORDS_SELECTION_PARAMETRIC_FIELDS = [
{
graphqlField: "texts",
argName: "keys",
selectionKey: "texts",
applySelection: (selection, args) => {
selection.texts = args.keys as string[];
},
},
{
graphqlField: "addresses",
argName: "coinTypes",
selectionKey: "addresses",
applySelection: (selection, args) => {
selection.addresses = args.coinTypes as CoinType[];
},
},
{
graphqlField: "abi",
argName: "contentTypeMask",
selectionKey: "abi",
applySelection: (selection, args) => {
selection.abi = args.contentTypeMask as ContentType;
},
},
{
graphqlField: "interfaces",
argName: "ids",
selectionKey: "interfaces",
applySelection: (selection, args) => {
selection.interfaces = args.ids as InterfaceId[];
},
},
] as const satisfies readonly RecordsSelectionParametricField[];

const simpleFieldByGraphqlName = new Map<string, RecordsSelectionSimpleField>(
RECORDS_SELECTION_SIMPLE_FIELDS.map((f) => [f.graphqlField, f]),
);

const parametricFieldByGraphqlName = new Map<string, RecordsSelectionParametricField>(
RECORDS_SELECTION_PARAMETRIC_FIELDS.map((f) => [f.graphqlField, f]),
);

export function getSimpleRecordsSelectionField(
graphqlField: string,
): RecordsSelectionSimpleField | undefined {
return simpleFieldByGraphqlName.get(graphqlField);
}

export function getParametricRecordsSelectionField(
graphqlField: string,
): RecordsSelectionParametricField | undefined {
return parametricFieldByGraphqlName.get(graphqlField);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DEFAULT_EVM_CHAIN_ID } from "enssdk";
import { describe, expect, it } from "vitest";

import {
DEFAULT_CHAIN_ID_WITH_OTHERS_MESSAGE,
EMPTY_CHAIN_IDS_MESSAGE,
validatePrimaryNamesChainIds,
} from "@/omnigraph-api/lib/validate-primary-names-chain-ids";

describe("validatePrimaryNamesChainIds", () => {
it.each([
{ chainIds: undefined, label: "omitted" },
{ chainIds: null, label: "null" },
{ chainIds: [1], label: "single chain" },
{ chainIds: [1, 10], label: "multiple chains" },
{ chainIds: [DEFAULT_EVM_CHAIN_ID], label: "default chain only" },
])("allows $label", ({ chainIds }) => {
expect(() => validatePrimaryNamesChainIds(chainIds)).not.toThrow();
});

it("rejects empty chainIds", () => {
expect(() => validatePrimaryNamesChainIds([])).toThrow(EMPTY_CHAIN_IDS_MESSAGE);
});

it("rejects default chain id combined with other chain ids", () => {
expect(() => validatePrimaryNamesChainIds([DEFAULT_EVM_CHAIN_ID, 1])).toThrow(
DEFAULT_CHAIN_ID_WITH_OTHERS_MESSAGE,
);
});
});
Loading
Loading