import { typeSymbol , GraphQLType , GraphQLScalar , GraphQLInlineFragment } from './render' ; type ValueOf < T > = T [ keyof T ] ; type ElementType < T extends ReadonlyArray < unknown > > = T extends ReadonlyArray < infer ElementType > ? ElementType : never ; /**
 * Add `types.optional` or `optional` helper method to define optional field.
 *
 * ```typescript
 * import { optional, query, types } from 'typed-graphqlify'
 *
 * query('getUser', {
 *   user: {
 *     id: types.number,
 *     name: types.optional.string, // <-- user.name is `string | undefined`
 *     bankAccount: optional({      // <-- user.bankAccount is `{ id: number } | undefined`
 *       id: types.number,
 *     }),
 *   },
 * }
 * ```
 */ export function optional < T > ( obj ) { return obj ; } export function on < T extends { } > ( typeName , internal ) { const fragment = { [ typeSymbol ] : GraphQLType . INLINE_FRAGMENT , typeName , internal , } ; return { [ Symbol ( `InlineFragment(${ typeName })` ) ] : fragment } as any ; } export function onUnion < T > ( types ) { let fragments = { } ; for ( const [ typeName , internal ] of Object . entries ( types ) ) { fragments = { ... fragments , ... on ( typeName , internal ) , } ; } return fragments as any ; } function scalarType ( ) { const scalar = { [ typeSymbol ] : GraphQLType . SCALAR , } ; return scalar ; } export class types { static get number ( ) : number { return scalarType ( ) ; } static get string ( ) : string { return scalarType ( ) ; } static get boolean ( ) : boolean { return scalarType ( ) ; } static constant < T extends string > ( _c ) { return scalarType ( ) ; } static oneOf < T extends ReadonlyArray < string > > ( _e ) ; static oneOf < T extends { } > ( _e ) ; static oneOf < T extends { } | ReadonlyArray < string > > ( _e ) { return scalarType ( ) ; } static custom < T > ( ) { return scalarType ( ) ; } static optional : { number ? : number ; string ? : string ; boolean ? : boolean ; constant : < T extends string > ( _c : T ) => T | undefined ; oneOf : < T extends { } > ( _e : T ) => ValueOf < T > | undefined ; custom : < T > ( ) => T | undefined ; } = types ; }