New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphql-mutate

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-mutate - npm Package Compare versions

Comparing version

to
0.3.0

.eslintrc.js

53

index.js

@@ -17,11 +17,24 @@ function compositeKey(path) {

function findSelections(keys, operation) {
function selectionsMap(selections) {
const map = {}
selections.forEach(selection => {
map[selectionName(selection)] = selection
})
return map
}
function findSelections(keys, ctx, operation) {
keys = keys.filter(i => typeof i === 'string')
let key = keys.shift()
let selections = operation.selectionSet.selections
while (key) {
selections = selections.find(selection => selectionName(selection) == key).selectionSet.selections
key = keys.shift()
const keyPath = keys.join('-')
if (!ctx.__mutate.prefixs[keyPath]) {
let key = keys.shift()
let selections = operation.selectionSet.selections
while (key) {
const map = selectionsMap(selections)
selections = map[key].selectionSet.selections
key = keys.shift()
}
ctx.__mutate.prefixs[keyPath] = selections
}
return selections
return ctx.__mutate.prefixs[keyPath]
}

@@ -42,3 +55,3 @@

return (source, args, ctx, info) => {
if (!ctx.__mutate) ctx.__mutate = {}
if (!ctx.__mutate) ctx.__mutate = { callbacks: {}, prefixs: {}}
const keyPath = compositeKey(info.path)

@@ -48,3 +61,3 @@ const keys = reverseKey(info.path)

const selections = findSelections(keys.slice(), info.operation)
const selections = findSelections(keys.slice(), ctx, info.operation)
const mutatesFields = selections.filter(s => mutations.indexOf(s.name.value) !== -1)

@@ -55,2 +68,9 @@ const dependant = isMutate ? depend(name, mutatesFields) : mutatesFields[mutatesFields.length - 1]

const callback = (source) => {
const resolveDependencies = (source) => {
if (ctx.__mutate.callbacks[keyPath]) {
ctx.__mutate.callbacks[keyPath].forEach(r => r(source))
ctx.__mutate.callbacks[keyPath] = []
delete ctx.__mutate.callbacks[keyPath]
}
}
Promise.resolve(resolver(source, args, ctx, info)).then(data => {

@@ -60,10 +80,11 @@ if (isMutate) {

resolve(result)
if (ctx.__mutate[keyPath]) {
ctx.__mutate[keyPath].forEach(r => r(source))
ctx.__mutate[keyPath] = []
delete ctx.__mutate[keyPath]
}
resolveDependencies(source)
} else {
resolve(data)
}
}).catch(e => {
reject(e)
if (isMutate) {
resolveDependencies(source)
}
})

@@ -82,4 +103,4 @@ }

const dependantPath = keys.join('-')
if (!ctx.__mutate[dependantPath]) ctx.__mutate[dependantPath] = []
ctx.__mutate[dependantPath].push(callback)
if (!ctx.__mutate.callbacks[dependantPath]) ctx.__mutate.callbacks[dependantPath] = []
ctx.__mutate.callbacks[dependantPath].push(callback)
}

@@ -86,0 +107,0 @@ })

{
"name": "graphql-mutate",
"version": "0.2.0",
"version": "0.3.0",
"description": "GraphQL nested mutation",

@@ -17,11 +17,16 @@ "keywords": [

"repository": {
"type": "git",
"url": "https://github.com/oney/graphql-mutate.git"
"type": "git",
"url": "https://github.com/oney/graphql-mutate.git"
},
"author": {
"name": "Howard Yang",
"email": "appdevoney@gmail.com"
"name": "Howard Yang",
"email": "appdevoney@gmail.com"
},
"homepage": "https://github.com/oney/graphql-mutate",
"bugs": "https://github.com/oney/graphql-mutate/issues"
"bugs": "https://github.com/oney/graphql-mutate/issues",
"devDependencies": {
"babel-eslint": "^8.1.0",
"eslint": "^4.14.0",
"eslint-plugin-require-path-exists": "^1.1.7"
}
}