apollo-link-ethereum
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -9,7 +9,7 @@ (function (global, factory) { | ||
var connectionRemoveConfig = { | ||
test: function (directive) { return directive.name.value === 'contract'; }, | ||
test: function (directive) { return ['contract', 'block'].indexOf(directive.name.value) !== -1; }, | ||
remove: true, | ||
}; | ||
var removed = new Map(); | ||
function removeContractSetsFromDocument(query) { | ||
function removeEthereumSetsFromDocument(query) { | ||
// caching | ||
@@ -217,19 +217,18 @@ var cached = removed.get(query); | ||
var aliasNeeded = resultKey !== fieldName; | ||
console.log("resolverFactory for " + fieldName + " found aliases: " + aliasedNode + " " + preAliasingNode + " " + aliasNeeded); | ||
// if data already exists, return it! | ||
if (aliasedNode !== undefined || preAliasingNode !== undefined) { | ||
console.log("returning " + (aliasedNode || preAliasingNode)); | ||
return aliasedNode || preAliasingNode; | ||
} | ||
// otherwise, run the web3 resolver | ||
// debug(`resolver: `, fieldName, rootValue, args, context, info, contract) | ||
if (info.directives && info.directives.hasOwnProperty('contract')) { | ||
var isContract = info.directives && info.directives.hasOwnProperty('contract'); | ||
var isBlock = info.directives && info.directives.hasOwnProperty('block'); | ||
var result; | ||
if (isContract) { | ||
contract = fieldName; | ||
contractDirectives = info.directives.contract; | ||
result = {}; | ||
} | ||
else if (contract) { | ||
else if (isBlock || contract) { | ||
var entry_1; | ||
if (isSubscription) { | ||
var observable_1 = ethereumResolver.subscribe(contract, contractDirectives, fieldName, args, info.directives); | ||
observable_1['fieldName'] = fieldName; | ||
entry_1 = { | ||
@@ -240,3 +239,2 @@ result: null, | ||
var dataObservable = new apolloLink.Observable(function (observer) { | ||
console.log("subscribing data update " + fieldName); | ||
observable_1.subscribe({ | ||
@@ -259,9 +257,9 @@ next: function (data) { | ||
} | ||
return entry_1; | ||
result = entry_1; | ||
} | ||
console.log("Returning alias for " + fieldName + "..."); | ||
return ( | ||
// Support nested fields | ||
(aliasNeeded ? aliasedNode : preAliasingNode) || | ||
{}); | ||
else { | ||
// Nested fields | ||
result = (aliasNeeded ? aliasedNode : preAliasingNode) || {}; | ||
} | ||
return result; | ||
}; | ||
@@ -296,5 +294,5 @@ var resolverAfter = function (fieldName, rootValue, args, context, info) { | ||
// Using some code taken from https://github.com/apollographql/apollo-link-state/blob/master/packages/apollo-link-state/src/index.ts | ||
var ContractLink = /** @class */ (function (_super) { | ||
__extends(ContractLink, _super); | ||
function ContractLink(ethereumResolver) { | ||
var EthereumLink = /** @class */ (function (_super) { | ||
__extends(EthereumLink, _super); | ||
function EthereumLink(ethereumResolver) { | ||
var _this = _super.call(this) || this; | ||
@@ -304,10 +302,11 @@ _this.ethereumResolver = ethereumResolver; | ||
} | ||
ContractLink.prototype.request = function (operation, forward) { | ||
EthereumLink.prototype.request = function (operation, forward) { | ||
var _this = this; | ||
var query = operation.query; | ||
var isContract = apolloUtilities.hasDirectives(['contract'], query); | ||
if (!isContract) { | ||
var isEthereum = apolloUtilities.hasDirectives(['contract', 'block'], query); | ||
console.log('isEthereum: ', isEthereum); | ||
if (!isEthereum) { | ||
return forward ? forward(operation) : null; | ||
} | ||
var nonContractQuery = removeContractSetsFromDocument(query); | ||
var nonContractQuery = removeEthereumSetsFromDocument(query); | ||
var defn = apolloUtilities.getMainDefinition(query); | ||
@@ -334,3 +333,2 @@ var isSubscription = defn.operation === 'subscription'; | ||
var data = args.data, errors = args.errors; | ||
console.log('NEXT!', args); | ||
var context = operation.getContext(); | ||
@@ -357,3 +355,2 @@ var _a = resolverFactory(_this.ethereumResolver, isSubscription), resolver = _a.resolver, resolverAfter = _a.resolverAfter, promises = _a.promises, subscriptions = _a.subscriptions; | ||
subscriptions.forEach(function (subscription) { | ||
console.log('subscribing...'); | ||
subscription.subscribe({ | ||
@@ -391,3 +388,3 @@ next: function (_) { | ||
}; | ||
return ContractLink; | ||
return EthereumLink; | ||
}(apolloLink.ApolloLink)); | ||
@@ -456,3 +453,3 @@ | ||
exports.ContractLink = ContractLink; | ||
exports.EthereumLink = EthereumLink; | ||
exports.AbiMapping = AbiMapping; | ||
@@ -459,0 +456,0 @@ exports.AbiDefinition = AbiDefinition; |
@@ -1,4 +0,4 @@ | ||
export * from './ContractLink'; | ||
export * from './EthereumLink'; | ||
export * from './EthereumResolver'; | ||
export * from './AbiMapping'; | ||
export * from './AbiDefinition'; |
@@ -1,4 +0,4 @@ | ||
export * from './ContractLink'; | ||
export * from './EthereumLink'; | ||
export * from './AbiMapping'; | ||
export * from './AbiDefinition'; | ||
//# sourceMappingURL=index.js.map |
@@ -14,19 +14,18 @@ import { Observable } from 'apollo-link'; | ||
var aliasNeeded = resultKey !== fieldName; | ||
console.log("resolverFactory for " + fieldName + " found aliases: " + aliasedNode + " " + preAliasingNode + " " + aliasNeeded); | ||
// if data already exists, return it! | ||
if (aliasedNode !== undefined || preAliasingNode !== undefined) { | ||
console.log("returning " + (aliasedNode || preAliasingNode)); | ||
return aliasedNode || preAliasingNode; | ||
} | ||
// otherwise, run the web3 resolver | ||
// debug(`resolver: `, fieldName, rootValue, args, context, info, contract) | ||
if (info.directives && info.directives.hasOwnProperty('contract')) { | ||
var isContract = info.directives && info.directives.hasOwnProperty('contract'); | ||
var isBlock = info.directives && info.directives.hasOwnProperty('block'); | ||
var result; | ||
if (isContract) { | ||
contract = fieldName; | ||
contractDirectives = info.directives.contract; | ||
result = {}; | ||
} | ||
else if (contract) { | ||
else if (isBlock || contract) { | ||
var entry_1; | ||
if (isSubscription) { | ||
var observable_1 = ethereumResolver.subscribe(contract, contractDirectives, fieldName, args, info.directives); | ||
observable_1['fieldName'] = fieldName; | ||
entry_1 = { | ||
@@ -37,3 +36,2 @@ result: null, | ||
var dataObservable = new Observable(function (observer) { | ||
console.log("subscribing data update " + fieldName); | ||
observable_1.subscribe({ | ||
@@ -56,9 +54,9 @@ next: function (data) { | ||
} | ||
return entry_1; | ||
result = entry_1; | ||
} | ||
console.log("Returning alias for " + fieldName + "..."); | ||
return ( | ||
// Support nested fields | ||
(aliasNeeded ? aliasedNode : preAliasingNode) || | ||
{}); | ||
else { | ||
// Nested fields | ||
result = (aliasNeeded ? aliasedNode : preAliasingNode) || {}; | ||
} | ||
return result; | ||
}; | ||
@@ -65,0 +63,0 @@ var resolverAfter = function (fieldName, rootValue, args, context, info) { |
{ | ||
"name": "apollo-link-ethereum", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"main": "./dist/bundle.umd.js", | ||
@@ -34,3 +34,3 @@ "modules": "./lib/index.js", | ||
}, | ||
"gitHead": "3db8eb1f5dab2b4cc99a5072e48c4efa75ad1ed0" | ||
"gitHead": "7bc4343ab513ec2009887f0d838aee5255ec6799" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
500067
45
1123