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

mock-apollo-client

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-apollo-client - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0-feature-fragments.0

45

dist/mockLink.js

@@ -19,2 +19,3 @@ "use strict";

var printer_1 = require("graphql/language/printer");
var visitor_1 = require("graphql/language/visitor");
var MockLink = (function (_super) {

@@ -28,11 +29,7 @@ __extends(MockLink, _super);

MockLink.prototype.setRequestHandler = function (requestQuery, handler) {
var identifiers = getIdentifiers(requestQuery);
for (var _i = 0, identifiers_1 = identifiers; _i < identifiers_1.length; _i++) {
var identifier = identifiers_1[_i];
var key = requestToKey(identifier);
if (this.requestHandlers[key]) {
throw new Error("Request handler already defined for query: " + format(identifier));
}
this.requestHandlers[key] = handler;
var key = requestToKey(requestQuery);
if (this.requestHandlers[key]) {
throw new Error("Request handler already defined for query: " + format(requestQuery));
}
this.requestHandlers[key] = handler;
};

@@ -70,16 +67,26 @@ MockLink.prototype.request = function (operation) {

exports.MockLink = MockLink;
var getIdentifiers = function (requestQuery) {
if (!apollo_utilities_1.hasDirectives(['client', 'connection'], requestQuery)) {
return [requestQuery];
}
var withoutDirectives = apollo_utilities_1.removeClientSetsFromDocument(requestQuery);
withoutDirectives = withoutDirectives !== null
? apollo_utilities_1.removeConnectionDirectiveFromDocument(withoutDirectives)
var normalise = function (requestQuery) {
var stripped = apollo_utilities_1.removeClientSetsFromDocument(requestQuery);
stripped = stripped !== null
? apollo_utilities_1.removeConnectionDirectiveFromDocument(stripped)
: null;
return withoutDirectives === null
? [requestQuery]
: [requestQuery, withoutDirectives];
stripped = stripped !== null
? stripTypenames(stripped)
: null;
return stripped === null
? requestQuery
: stripped;
};
var stripTypenames = function (document) {
return visitor_1.visit(document, {
Field: {
enter: function (node) { return node.name.value === '__typename'
? null
: undefined; },
},
});
};
var requestToKey = function (query) {
var queryString = printer_1.print(query);
var normalised = normalise(query);
var queryString = printer_1.print(normalised);
var requestKey = { query: queryString };

@@ -86,0 +93,0 @@ return JSON.stringify(requestKey);

{
"name": "mock-apollo-client",
"version": "0.5.0",
"version": "0.6.0-feature-fragments.0",
"description": "Library to help unit testing when using apollo-client",

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

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