import { FieldNode , FragmentDefinitionNode , FragmentSpreadNode } from "graphql/language" ; import { Algebra } from "sparqlalgebrajs" ; import { IConvertContext } from "../IConvertContext" ; import { IConvertSettings } from "../IConvertSettings" ; import { Util } from "../Util" ; import { NodeHandlerSelectionAdapter } from "./NodeHandlerSelectionAdapter" ; /**
 * Converts GraphQL fragment spread to one or more quad patterns with a given type within an optional.
 */ export class NodeHandlerSelectionFragmentSpread extends NodeHandlerSelectionAdapter < FragmentSpreadNode > { constructor ( util , settings ) { super ( 'FragmentSpread' , util , settings ) ; } public handle ( fragmentSpreadNode , convertContext ) { const fragmentDefinitionNode = convertContext . fragmentDefinitions [ fragmentSpreadNode . name . value ] ; if ( ! fragmentDefinitionNode ) { throw new Error ( 'Undefined fragment definition: ' + fragmentSpreadNode . name . value ) ; } const fieldNode = { alias : undefined , arguments : undefined , directives : fragmentDefinitionNode . directives , kind : 'Field' , name : fragmentSpreadNode . name , selectionSet : fragmentDefinitionNode . selectionSet , } ; const auxiliaryPatterns = [ this . util . newTypePattern ( convertContext . subject , fragmentDefinitionNode . typeCondition , convertContext ) , ] ; return this . util . operationFactory . createLeftJoin ( this . util . operationFactory . createBgp ( [ ] ) , this . fieldToOperation ( convertContext , fieldNode , false , auxiliaryPatterns ) ) ; } }