graphql-to-sparql
Version:
Converts GraphQL queries to SPARQL queries
85 lines (84 loc) • 2.35 kB
TypeScript
import type * as RDF from '@rdfjs/types';
import type { FragmentDefinitionNode, ValueNode } from 'graphql/language';
import type { JsonLdContextNormalized } from 'jsonld-context-parser';
/**
* A context object that is passed through conversion steps.
*
* This is defined for each query conversion within a converter instance.
*/
export interface IConvertContext {
/**
* A JSON-LD context.
*/
context: JsonLdContextNormalized;
/**
* The current JSON path within the GraphQL query.
*/
path: string[];
/**
* The subject term.
*/
subject: RDF.Term;
/**
* The graph term.
*/
graph: RDF.Term;
/**
* All variables that have no deeper child and should be selected withing the GraphQL query.
*/
terminalVariables: RDF.Variable[];
/**
* All available fragment definitions.
*/
fragmentDefinitions: Record<string, FragmentDefinitionNode>;
/**
* A variable dictionary in case there are dynamic arguments in the query.
*/
variablesDict: IVariablesDictionary;
/**
* A dictionary of variable metadata.
*/
variablesMetaDict: IVariablesMetaDictionary;
/**
* The fields that are to be singularized.
*/
singularizeVariables?: ISingularizeVariables;
/**
* The current singularization state.
*/
singularizeState: SingularizeState;
/**
* If unknown variables that are being used should NOT throw an error.
*/
ignoreUnknownVariables?: boolean;
}
/**
* A variable dictionary in case there are dynamic arguments in the query.
*/
export type IVariablesDictionary = Record<string, ValueNode>;
/**
* A dictionary of variable metadata.
*/
export type IVariablesMetaDictionary = Record<string, {
mandatory: boolean;
list: boolean;
type: string;
}>;
/**
* A mapping from (nested) field names to a boolean indicating whether or not this field should be singularized.
* If the field is not present, singularization for this field is false.
*/
export type ISingularizeVariables = Record<string, boolean>;
/**
* A singularization state for variable values.
*/
export declare enum SingularizeState {
/**
* If only a first matching value should be picked.
*/
SINGLE = 0,
/**
* If all matching values should be picked.
*/
PLURAL = 1
}