import type { EvaluateConfig, InputTypeConfig, OutputTypeConfig } from './config' import type { Resolver, Subscription } from './Resolver' import type { AnyField, GQLInputObject, GQLObject, GQLScalar, GQLUnion, InputRecord } from './types' import type { _Root, TypeofInputRecord } from './util' import type { Integer } from '@principia/base/Integer' import type { _A, _E, _R } from '@principia/base/util/types' import { memoize } from '@principia/base/function' import { GQLField, GQLInputField, GQLObjectField, GQLScalarField, GQLSubscriptionField, GQLUnionField } from './types' export const GqlFieldURI = 'graphql/algebra/field' export type GqlFieldURI = typeof GqlFieldURI export const GqlInputURI = 'graphql/algebra/input' export type GqlInputURI = typeof GqlInputURI declare module './HKT' { interface AURItoFieldAlgebra { readonly [GqlFieldURI]: GQLFieldAlgebra } interface AURItoInputAlgebra { readonly [GqlInputURI]: GQLInputAlgebra } } export interface GQLFieldAlgebra { readonly boolean: (config?: C) => GQLScalarField> readonly field: , Args extends InputRecord, R, E>(def: { type: F resolve: Resolver, Ctx, R, E, _A> args?: Args }) => GQLField, Ctx, R, E, _A> readonly float: (config?: C) => GQLScalarField> readonly id: (config?: C) => GQLScalarField> readonly int: (config?: C) => GQLScalarField> readonly string: (config?: C) => GQLScalarField> readonly union: , C extends OutputTypeConfig>( type: () => U, config?: C ) => GQLUnionField>> readonly object: , C extends OutputTypeConfig>( type: () => O, config?: C ) => GQLObjectField<_Root, Ctx, _R, _E, EvaluateConfig>> readonly scalar: , C extends OutputTypeConfig>( scalar: () => S, config?: C ) => GQLScalarField>> } export interface GQLInputAlgebra { readonly booleanArg: >>( config?: C ) => GQLInputField> readonly floatArg: >>( config?: C ) => GQLInputField> readonly idArg: >>( config?: C ) => GQLInputField> readonly intArg: >>( config?: C ) => GQLInputField> readonly objectArg: , C extends InputTypeConfig>>>( type: () => X, config?: C ) => GQLInputField>> readonly stringArg: >>( config?: C ) => GQLInputField> readonly scalarArg: , C extends InputTypeConfig>>>( scalar: () => X, config?: C ) => GQLInputField>> } export interface GQLSubscriptionAlgebra { readonly subscription: , Args extends InputRecord, SR, SE, SA, RR, RE>(def: { type: F resolve: Subscription<{}, TypeofInputRecord, SR, SE, SA, RR, RE, _A> args?: Args }) => GQLSubscriptionField> } export const GqlSubscriptionInterpreter = memoize>(() => ({ subscription: ({ args, type, resolve }) => new GQLSubscriptionField(type, args, resolve) })) export const GQLFieldInterpreter = memoize>( (): GQLFieldAlgebra => ({ boolean: (config) => new GQLScalarField('Boolean', config), field: ({ args, resolve, type }) => new GQLField(type, args, resolve), union: (type, config) => new GQLUnionField(type().name, config), float: (config) => new GQLScalarField('Float', config), id: (config) => new GQLScalarField('ID', config), int: (config) => new GQLScalarField('Int', config), string: (config) => new GQLScalarField('String', config), object: (type, config) => new GQLObjectField(type().name, config), scalar: (scalar, config) => new GQLScalarField(scalar().name, config) }) ) export const GQLInputInterpreter = memoize( (): GQLInputAlgebra => ({ booleanArg: (config) => new GQLInputField('Boolean', config), floatArg: (config) => new GQLInputField('Float', config), idArg: (config) => new GQLInputField('ID', config), intArg: (config) => new GQLInputField('Int', config), objectArg: (type, config) => new GQLInputField(type().name, config), stringArg: (config) => new GQLInputField('String', config), scalarArg: (scalar, config) => new GQLInputField(scalar().name, config) }) ) export const DefaultGQLInterpreters = { ...GQLFieldInterpreter(), ...GQLInputInterpreter(), ...GqlSubscriptionInterpreter() }