Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 28x 28x 28x 28x 28x 28x 589x 589x 496x 93x 95x 95x 95x 95x 92x 91x 89x 89x 9x 89x 89x 89x 89x 89x 75x 14x 89x 89x 89x | var invariant = require('invariant');
export var DocumentType;
(function (DocumentType) {
DocumentType[DocumentType["Query"] = 0] = "Query";
DocumentType[DocumentType["Mutation"] = 1] = "Mutation";
DocumentType[DocumentType["Subscription"] = 2] = "Subscription";
})(DocumentType || (DocumentType = {}));
var cache = new Map();
export function parser(document) {
var cached = cache.get(document);
if (cached)
return cached;
var variables, type, name;
invariant(!!document && !!document.kind, "Argument of " + document + " passed to parser was not a valid GraphQL " +
"DocumentNode. You may need to use 'graphql-tag' or another method " +
"to convert your operation into a document");
var fragments = document.definitions.filter(function (x) { return x.kind === 'FragmentDefinition'; });
var queries = document.definitions.filter(function (x) { return x.kind === 'OperationDefinition' && x.operation === 'query'; });
var mutations = document.definitions.filter(function (x) { return x.kind === 'OperationDefinition' && x.operation === 'mutation'; });
var subscriptions = document.definitions.filter(function (x) { return x.kind === 'OperationDefinition' && x.operation === 'subscription'; });
invariant(!fragments.length || (queries.length || mutations.length || subscriptions.length), "Passing only a fragment to 'graphql' is not yet supported. " +
"You must include a query, subscription or mutation as well");
invariant(queries.length + mutations.length + subscriptions.length <= 1, "react-apollo only supports a query, subscription, or a mutation per HOC. " +
(document + " had " + queries.length + " queries, " + subscriptions.length + " ") +
("subscriptions and " + mutations.length + " mutations. ") +
"You can use 'compose' to join multiple operation types to a component");
type = queries.length ? DocumentType.Query : DocumentType.Mutation;
if (!queries.length && !mutations.length)
type = DocumentType.Subscription;
var definitions = queries.length ? queries : mutations.length ? mutations : subscriptions;
invariant(definitions.length === 1, "react-apollo only supports one defintion per HOC. " + document + " had " +
(definitions.length + " definitions. ") +
"You can use 'compose' to join multiple operation types to a component");
var definition = definitions[0];
variables = definition.variableDefinitions || [];
if (definition.name && definition.name.kind === 'Name') {
name = definition.name.value;
}
else {
name = 'data';
}
var payload = { name: name, type: type, variables: variables };
cache.set(document, payload);
return payload;
}
//# sourceMappingURL=parser.js.map |