apollo-client
Version:
A simple yet functional GraphQL client.
44 lines • 1.98 kB
JavaScript
;
function getMutationDefinition(doc) {
if (doc.kind !== 'Document') {
throw new Error("Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
}
if (doc.definitions.length > 1) {
throw new Error('Mutation query must have exactly one operation definition.');
}
var mutationDef = doc.definitions[0];
if (mutationDef.kind !== 'OperationDefinition' || mutationDef.operation !== 'mutation') {
throw new Error('Must be a mutation definition.');
}
return mutationDef;
}
exports.getMutationDefinition = getMutationDefinition;
function getQueryDefinition(doc) {
if (doc.kind !== 'Document') {
throw new Error("Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
}
if (doc.definitions.length > 1) {
throw new Error('Query must have exactly one operation definition.');
}
var queryDef = doc.definitions[0];
if (queryDef.kind !== 'OperationDefinition' || queryDef.operation !== 'query') {
throw new Error('Must be a query definition.');
}
return queryDef;
}
exports.getQueryDefinition = getQueryDefinition;
function getFragmentDefinition(doc) {
if (doc.kind !== 'Document') {
throw new Error("Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a \"gql\" tag? http://docs.apollostack.com/apollo-client/core.html#gql");
}
if (doc.definitions.length > 1) {
throw new Error('Fragment must have exactly one definition.');
}
var fragmentDef = doc.definitions[0];
if (fragmentDef.kind !== 'FragmentDefinition') {
throw new Error('Must be a fragment definition.');
}
return fragmentDef;
}
exports.getFragmentDefinition = getFragmentDefinition;
//# sourceMappingURL=getFromAST.js.map