import { findSchemaAtPath } from "./find-shape-at-path.js";
import { getReturnShape } from "./get-return-shape.js";
function parseFieldName(fieldName) {
    return fieldName.split('.');
}
export function getQueryFieldPath(operation, fieldName) {
    return [operation === 'query' ? 'queries' : 'mutations', ...parseFieldName(fieldName)];
}
/**
 * Get a query or property schema
 * @param schema
 * @param queryFieldPath
 * @returns
 */
export function findSchemaAtQueryFieldPath(schema, queryFieldPath) {
    const [operationName, queryName, ...fieldPath] = queryFieldPath;
    const queryOrMutation = schema[operationName]?.[queryName];
    if (!queryOrMutation) {
        return undefined;
    }
    const shape = getReturnShape(schema, queryOrMutation);
    return shape ? findSchemaAtPath(schema, shape.schema, fieldPath) : undefined;
}
