graphql-anywhere
Advanced tools
Comparing version 0.2.3 to 0.2.4
# Change log | ||
### v0.2.4 | ||
- Added support for fragments. If there are multiple fragments in the provided document, the first one is used as the query. | ||
### v0.2.3 | ||
@@ -4,0 +8,0 @@ |
@@ -13,1 +13,2 @@ import { Document, OperationDefinition, FragmentDefinition } from 'graphql'; | ||
export declare function addFragmentsToDocument(queryDoc: Document, fragments: FragmentDefinition[]): Document; | ||
export declare function getMainDefinition(queryDoc: Document): OperationDefinition | FragmentDefinition; |
@@ -101,2 +101,18 @@ "use strict"; | ||
exports.addFragmentsToDocument = addFragmentsToDocument; | ||
function getMainDefinition(queryDoc) { | ||
checkDocument(queryDoc); | ||
try { | ||
return getQueryDefinition(queryDoc); | ||
} | ||
catch (e) { | ||
try { | ||
var fragments = getFragmentDefinitions(queryDoc); | ||
return fragments[0]; | ||
} | ||
catch (e) { | ||
throw new Error("Expected a parsed GraphQL query with a query or a fragment."); | ||
} | ||
} | ||
} | ||
exports.getMainDefinition = getMainDefinition; | ||
//# sourceMappingURL=getFromAST.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
if (execOptions === void 0) { execOptions = {}; } | ||
var queryDefinition = getFromAST_1.getQueryDefinition(document); | ||
var mainDefinition = getFromAST_1.getMainDefinition(document); | ||
var fragments = getFromAST_1.getFragmentDefinitions(document); | ||
@@ -24,3 +24,3 @@ var fragmentMap = getFromAST_1.createFragmentMap(fragments) || {}; | ||
}; | ||
return executeSelectionSet(queryDefinition.selectionSet, rootValue, execContext); | ||
return executeSelectionSet(mainDefinition.selectionSet, rootValue, execContext); | ||
} | ||
@@ -27,0 +27,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
{ | ||
"name": "graphql-anywhere", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Run GraphQL queries with no schema and just one resolver", | ||
@@ -5,0 +5,0 @@ "main": "./lib/src/index.js", |
@@ -132,1 +132,17 @@ import { | ||
} | ||
export function getMainDefinition(queryDoc: Document): OperationDefinition | FragmentDefinition { | ||
checkDocument(queryDoc); | ||
try { | ||
return getQueryDefinition(queryDoc); | ||
} catch (e) { | ||
try { | ||
const fragments = getFragmentDefinitions(queryDoc); | ||
return fragments[0]; | ||
} catch (e) { | ||
throw new Error(`Expected a parsed GraphQL query with a query or a fragment.`) | ||
} | ||
} | ||
} |
@@ -10,3 +10,3 @@ import { | ||
import { | ||
getQueryDefinition, | ||
getMainDefinition, | ||
getFragmentDefinitions, | ||
@@ -81,3 +81,3 @@ createFragmentMap, | ||
) { | ||
const queryDefinition = getQueryDefinition(document); | ||
const mainDefinition = getMainDefinition(document); | ||
@@ -102,3 +102,3 @@ const fragments = getFragmentDefinitions(document); | ||
return executeSelectionSet( | ||
queryDefinition.selectionSet, | ||
mainDefinition.selectionSet, | ||
rootValue, | ||
@@ -105,0 +105,0 @@ execContext |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54041
886