Sha256: e2825eb382bef566826d758bc725d01fe6d6cd88a0fab5d4d9be1e3188253056
Contents?: true
Size: 1.04 KB
Versions: 56
Compression:
Stored size: 1.04 KB
Contents
import graphql, { filter } from "graphql-anywhere"; /** * A simple resolver which returns object properties to easily * traverse a graphql response * @param {String} fieldName - An object property * @param {Object} root - An object * @returns {any} - An object's property value */ const resolver = (fieldName: string, root: any) => root[fieldName]; /** * A helper function to mock a graphql api request and return its * result. The result can be filtered by the same query so it just * returns a data subset. * @param {String} document - A graphql query document * @param {options} options - An object with optional options * @returns {Object} - The result of the query filtered or not */ const resolveGraphQLQuery = (document: any, options: any = {}) => { const { filterResult, rootValue, context, variables } = options; const result = graphql( resolver, document, rootValue, context, variables, ); if (filterResult) { return filter(document, result); } return result; }; export default resolveGraphQLQuery;
Version data entries
56 entries across 56 versions & 2 rubygems