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

graphql-fields

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-fields - npm Package Compare versions

Comparing version 1.3.0 to 2.0.0

47

build/index.js

@@ -5,2 +5,4 @@ 'use strict';

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

@@ -40,5 +42,50 @@

function getDirectiveValue(directive, info) {
var arg = directive.arguments[0]; // only arg on an include or skip directive is "if"
if (arg.value.kind !== "Variable") {
return !!arg.value.value;
}
return info.variableValues[arg.value.name.value];
}
function getDirectiveResults(ast, info) {
var directiveResult = {
shouldInclude: true,
shouldSkip: false
};
return ast.directives.reduce(function (result, directive) {
switch (directive.name.value) {
case "include":
return _objectSpread({}, result, {
shouldInclude: getDirectiveValue(directive, info)
});
case "skip":
return _objectSpread({}, result, {
shouldSkip: getDirectiveValue(directive, info)
});
default:
return result;
}
}, directiveResult);
}
function flattenAST(ast, info, obj) {
obj = obj || {};
return getSelections(ast).reduce(function (flattened, a) {
if (a.directives && a.directives.length) {
var _getDirectiveResults = getDirectiveResults(a, info),
shouldInclude = _getDirectiveResults.shouldInclude,
shouldSkip = _getDirectiveResults.shouldSkip; // field/fragment is not included if either the @skip condition is true or the @include condition is false
// https://facebook.github.io/graphql/draft/#sec--include
if (shouldSkip || !shouldInclude) {
return flattened;
}
}
if (isFragment(a)) {

@@ -45,0 +92,0 @@ flattened = flattenAST(getAST(a, info), info, flattened);

# Changelog
## 2.0.0 (2018-11-29)
### Added
- @skip and @include directive parsing
## 1.3.0 (2018-11-15)

@@ -4,0 +10,0 @@

2

package.json
{
"name": "graphql-fields",
"version": "1.3.0",
"version": "2.0.0",
"description": "Turns GraphQLResolveInfo into a map of the requested fields",

@@ -5,0 +5,0 @@ "main": "build/index.js",

# graphql-fields
Turns GraphQLResolveInfo into a map of the requested fields. Flattens all fragments and duplicated fields into a neat object to easily see which fields were requested at any level.
Turns GraphQLResolveInfo into a map of the requested fields. Flattens all fragments and duplicated fields into a neat object to easily see which fields were requested at any level. Takes into account any `@include` or `@skip` directives, excluding fields/fragments which are `@include(if: $false)` or `@skip(if: $true)`.

@@ -19,3 +19,5 @@ ## Usage

lastName: {type: graphql.GraphQLString},
middleName: {type: graphql.GraphQLString}
middleName: {type: graphql.GraphQLString},
nickName: {type: graphql.GraphQLString},
maidenName: {type: graphql.GraphQLString}
}

@@ -69,2 +71,3 @@ }),

firstName
nickName @skip(if: true)
}

@@ -76,2 +79,3 @@

middleName
maidenName @include(if: false)
}

@@ -78,0 +82,0 @@ }

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