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

Version Path
decidim-comments-0.9.3 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.9.2 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.9.1 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.9.0 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.8.4 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.8.3 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.8.2 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.8.1 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.8.0 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.7.4 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.7.3 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.7.2 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.7.1 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.7.0 app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.6.8 app/frontend/support/resolve_graphql_query.ts
decidim-0.6.8 decidim-comments/app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.6.7 app/frontend/support/resolve_graphql_query.ts
decidim-0.6.7 decidim-comments/app/frontend/support/resolve_graphql_query.ts
decidim-comments-0.6.6 app/frontend/support/resolve_graphql_query.ts
decidim-0.6.6 decidim-comments/app/frontend/support/resolve_graphql_query.ts