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

graphql-helper

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-helper - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

96

lib.js

@@ -8,3 +8,3 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /* @flow */

@@ -33,5 +33,10 @@ exports.configure = configure;

function decorate(target, props) {
/*:: type TemplateStringTarget = any*/
/*:: type TemplateString<V> = (target: TemplateStringTarget, ...values: Array<mixed>) => V*/
/*:: type StrMap<V> = { [key: string]: V }*/
function decorate /*:: <T,K,V>*/(target /*: T*/, props /*: { [key: K]: V }*/) /*: T*/ {
Object.keys(props).forEach(function (key) {
return target[key] = props[key];
return (target /*: any*/)[(key /*: any*/)] = props[(key /*: any*/)];
});

@@ -41,3 +46,3 @@ return target;

function invariant(condition, message) {
function invariant(condition /*: mixed*/, message /*: string*/) /*: void*/ {
if (!gqlIgnoreInvariants && !condition) throw new Error(message);

@@ -48,3 +53,12 @@ }

function configure(_ref) {
/*:: declare class String {
static raw: TemplateString<string>;
}*/
/*:: type Configs =
{ host: string // graphql endpoint
, headers?: StrMap<string> // additional request headers
, ignoreInvariants: boolean // ignore invariants (used for HMR)
, clientMutationId?: () => string // ID generator
}*/
function configure(_ref) /*: void*/ {
var host = _ref.host;

@@ -67,5 +81,5 @@ var _ref$headers = _ref.headers;

// TODO: support operationName
function request(query) {
var variables = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var operations = arguments[2];
function request /*:: <U,V>*/(query /*: string*/) /*: Promise<V>*/ {
var variables /*: ?U*/ = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var operations /*: ?Array<string>*/ = arguments[2];

@@ -85,11 +99,15 @@ return (0, _isomorphicFetch2.default)(gqlHost, { method: 'post',

var operationDefinitions = {};
/*:: type VariablesDef<U> = StrMap<string>*/
/*:: type Query<U,V> = (variables: U) => Promise<V>*/
var wrapParens = function wrapParens(str) {
var operationDefinitions /*: StrMap<Query<mixed,mixed>>*/ = {};
var wrapParens = function wrapParens(str /*: ?string*/) /*: string*/ {
return str ? '(' + str + ')' : '';
};
function query(name, varsDef) {
function query /*:: <U,V>*/(name /*: string*/, varsDef /*: ?VariablesDef<U>*/) /*: TemplateString<Query<U,V>>*/ {
var params = wrapParens(runMaybe(varsDef, function (v) {
var params /*: string*/ = wrapParens(runMaybe(varsDef, function (v) {
return Object.keys(v).map(function (k) {

@@ -107,3 +125,3 @@ return '$' + k + ':' + v[k];

var fragments = mergeFragments(values);
var fragments /*: StrMap<FragmentDefinition>*/ = mergeFragments(values);

@@ -131,3 +149,3 @@ var operation = 'query ' + name + ' ' + params + ' ' + String.raw.apply(String, [target].concat(values));

function mutation(name, varsDef) {
function mutation /*:: <U,V>*/(name /*: string*/, varsDef /*: ?VariablesDef<U>*/) /*: TemplateString<Query<U,V>>*/ {

@@ -145,3 +163,3 @@ var capitalized = capitalize(name);

var fragments = mergeFragments(values);
var fragments /*: StrMap<FragmentDefinition>*/ = mergeFragments(values);

@@ -172,3 +190,3 @@ var operation = 'mutation ' + capitalized + '($input: ' + inputType + '!){\n payload: ' + name + '(input: $input) {\n clientMutationId\n ... on ' + payloadType + ' ' + String.raw.apply(String, [target].concat(values)) + '\n }\n }';

function batch(ops, variables) {
function batch(ops /*: Array<Query<mixed,mixed>>*/, variables /*: mixed*/) /*: Promise<mixed>*/ {

@@ -199,3 +217,9 @@ // TEMPORARY: come up with a reasonable workaround for this:

var partial = exports.partial = function partial(target) {
/*:: type Partial =
{ __GRAPHQL_QUERY_PARTIAL__: true
, toString: () => string
, fragments: StrMap<FragmentDefinition>
}*/
/*:: type FragmentDefinition = string*/
var partial /*: TemplateString<Partial>*/ = exports.partial = function partial(target) {
for (var _len3 = arguments.length, values = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {

@@ -215,6 +239,16 @@ values[_key3 - 1] = arguments[_key3];

var fragmentDefinitions = {};
/*:: type Fragment =
{ __GRAPHQL_QUERY_PARTIAL__: true
, __GRAPHQL_FRAGMENT__: true
, name: string
, type: string
, toString: () => string
, fragments: StrMap<FragmentDefinition>
}*/
var fragment = exports.fragment = function fragment(name) {
var type = arguments.length <= 1 || arguments[1] === undefined ? name : arguments[1];
var fragmentDefinitions /*: StrMap<Fragment>*/ = {};
var fragment = exports.fragment = function fragment(name /*: string*/) /*: TemplateString<Fragment>*/ {
var type /*: string*/ = arguments.length <= 1 || arguments[1] === undefined ? name : arguments[1];
return function (target) {

@@ -241,3 +275,3 @@ for (var _len4 = arguments.length, values = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {

var union = exports.union = function union() {
var union = exports.union = function union() /*: Partial*/ {
for (var _len5 = arguments.length, partials = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {

@@ -253,3 +287,3 @@ partials[_key5] = arguments[_key5];

},
fragments: mergeFragments(partials)
fragments: mergeFragments((partials /*: any*/))
};

@@ -264,10 +298,10 @@ };

var asPartial = function asPartial(x) {
var asPartial = function asPartial(x /*: any*/) /*: ?Partial*/ {
return x && x.__GRAPHQL_QUERY_PARTIAL__ ? x : null;
};
var mergeFragments = function mergeFragments(values) {
return values.map(asPartial).filter(function (x) {
var mergeFragments = function mergeFragments(values /*: Array<mixed>*/) /*: StrMap<FragmentDefinition>*/ {
return (values.map(asPartial).filter(function (x) {
return !!x;
}).reduce(function (acc, _ref3) {
}) /*: any*/).reduce(function (acc, _ref3) {
var fragments = _ref3.fragments;

@@ -281,7 +315,7 @@ return Object.assign(acc, fragments);

function capitalize(s) {
function capitalize(s /*: string*/) /*: string*/ {
return s[0].toUpperCase() + s.slice(1);
}
function mapMaybe(f) {
function mapMaybe /*:: <A,B>*/(f /*: (val: A) => B*/) /*: (val: ?A) => ?B*/ {
return function (x) {

@@ -292,10 +326,10 @@ return x ? f(x) : null;

function runMaybe(x, f) {
function runMaybe /*:: <A,B>*/(x /*: ?A*/, f /*: (val: A) => B*/) /*: ?B*/ {
return x ? f(x) : null;
}
function valuesOf(map) {
function valuesOf /*:: <K,V>*/(map /*: {[key: K]: V}*/) /*: Array<V>*/ {
return Object.keys(map).map(function (k) {
return map[k];
return map[(k /*: any*/)];
});
}
{
"name": "graphql-helper",
"version": "0.0.9",
"version": "0.0.10",
"description": "A simple helper library for making GraphQL queries. For browser usage, ensure that you have a Promise polyfill.",

@@ -32,3 +32,3 @@ "main": "lib.js",

"babel-cli": "^6.11.4",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-plugin-transform-flow-comments": "^6.17.0",
"babel-preset-es2015": "^6.9.0",

@@ -51,3 +51,3 @@ "babel-preset-stage-0": "^6.5.0",

"plugins": [
"transform-flow-strip-types"
"transform-flow-comments"
]

@@ -54,0 +54,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