import { DirectiveNode } from "graphql" ; import * as RDF from "@rdfjs/types" ; import { Algebra } from "sparqlalgebrajs" ; import { IConvertContext } from "../../IConvertContext" ; import { IConvertSettings } from "../../IConvertSettings" ; import { Util } from "../../Util" ; import { ArgumentNode } from "graphql/language" ; /**
 * An abstract handler for GraphQL directives.
 */ export abstract class DirectiveNodeHandlerAdapter { public readonly targetKind : string ; protected readonly util : Util ; protected readonly settings : IConvertSettings ; constructor ( targetKind , util , settings ) { this . targetKind = targetKind ; this . util = util ; this . settings = settings ; } param { IDirectiveContext } directiveContext param { IConvertContext } convertContext return { IValueNodeHandlerOutput } public abstract handle ( directiveContext , convertContext ) ; param { DirectiveNode } directive param { IConvertContext } convertContext return { Term } public getDirectiveConditionalValue ( directive , convertContext ) { const arg = this . util . getArgument ( directive . arguments , 'if' ) ; if ( ! arg ) { throw new Error ( `The directive ${ directive . name . value } is missing an if-argument.` ) ; } const subValue = this . util . handleNodeValue ( arg . value , arg . name . value , convertContext ) ; if ( subValue . terms . length !== 1 ) { throw new Error ( `Can not apply the directive ${ directive . name . value } with a list.` ) ; } return subValue . terms [ 0 ] ; } param { DirectiveNode } directive return { boolean } public isDirectiveScopeAll ( directive ) { const scopeArg = this . util . getArgument ( directive . arguments , 'scope' ) ; return scopeArg && scopeArg . value . kind === 'EnumValue' && scopeArg . value . value === 'all' ; } } /**
 * The output of converting a directive node to an operation.
 */ export interface IDirectiveNodeHandlerOutput { /**
     * If the field should be ignored.
     */ ignore ? : boolean ; /**
     * The optional operation overrider.
     */ operationOverrider ? : ( operation : Algebra . Operation ) => Algebra . Operation ; } export interface IDirectiveContext { /**
     * The current directive.
     */ directive : DirectiveNode ; /**
     * The current field label.
     */ fieldLabel : string ; }