Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-anywhere

Package Overview
Dependencies
Maintainers
4
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-anywhere

Run GraphQL queries with no schema and just one resolver

  • 3.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created

What is graphql-anywhere?

The graphql-anywhere package is a flexible utility for running GraphQL queries against any arbitrary data structure. It allows you to execute GraphQL queries on client-side data, making it useful for scenarios where you need to filter or transform data based on a GraphQL query.

What are graphql-anywhere's main functionalities?

Executing GraphQL queries on client-side data

This feature allows you to execute GraphQL queries on client-side data. The code sample demonstrates how to filter a data object based on a GraphQL query, returning only the fields specified in the query.

const { graphql } = require('graphql-anywhere');
const { filter } = require('graphql-anywhere/lib/async');

const query = `{
  user {
    name
    age
  }
}`;

const resolver = (fieldName, root, args, context, info) => {
  return root[fieldName];
};

const data = {
  user: {
    name: 'John Doe',
    age: 30,
    email: 'john.doe@example.com'
  }
};

filter(resolver, query, data).then(result => {
  console.log(result);
  // Output: { user: { name: 'John Doe', age: 30 } }
});

Custom resolvers for handling data

This feature allows you to define custom resolvers to handle data in a specific way. The code sample shows how to use a custom resolver to modify the 'age' field before returning the result.

const { graphql } = require('graphql-anywhere');
const { filter } = require('graphql-anywhere/lib/async');

const query = `{
  user {
    name
    age
  }
}`;

const customResolver = (fieldName, root, args, context, info) => {
  if (fieldName === 'age') {
    return root[fieldName] + 1; // Custom logic to modify the age
  }
  return root[fieldName];
};

const data = {
  user: {
    name: 'John Doe',
    age: 30,
    email: 'john.doe@example.com'
  }
};

filter(customResolver, query, data).then(result => {
  console.log(result);
  // Output: { user: { name: 'John Doe', age: 31 } }
});

Other packages similar to graphql-anywhere

Keywords

FAQs

Package last updated on 05 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc