MCPcopy Create free account
hub / github.com/subquery/subql / findNodePath

Function findNodePath

packages/query/src/graphql/plugins/GetMetadataPlugin.ts:171–187  ·  view source on GitHub ↗
(nodes: readonly SelectionNode[], path: string[])

Source from the content-addressed store, hash-verified

169
170/* Recursively work down the AST to find a node with a matching path */
171function findNodePath(nodes: readonly SelectionNode[], path: string[]): FieldNode | undefined {
172 if (!path.length) {
173 throw new Error('Path must have a length');
174 }
175
176 const currentPath = path[0];
177 const found = nodes.find((node) => isFieldNode(node) && node.name.value === currentPath);
178
179 if (found && isFieldNode(found)) {
180 const newPath = path.slice(1);
181
182 if (!newPath.length) return found;
183
184 if (!found.selectionSet) return;
185 return findNodePath(found.selectionSet.selections, newPath);
186 }
187}
188
189export const GetMetadataPlugin = makeExtendSchemaPlugin((build: Build, options) => {
190 const [schemaName] = options.pgSchemas;

Callers 1

Calls 2

isFieldNodeFunction · 0.85
findMethod · 0.65

Tested by

no test coverage detected