Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @apollo-elements/lib

@apollo-elements/lib

Published on npm ISC License Release

Helper functions for Apollo Elements

createApolloClient

Creates a simple ApolloClient instance given a URI and some params.

createApolloClient({
  uri: '/graphql',
  typePolicies: {
    User: {
      fields: {
        fullName(_, { readField }) {
          return `${readField('firstName')} ${readField('lastName')}`;
        }
      }
    }
  }
});

hasAllVariables

Predicate that validates a GraphQL request (a DocumentNode and a variables object) as having all of its required (i.e. non-nullable) variables defined.

function hasAllVariables(params: { query: DocumentNode, variables: any }): boolean

isClientOperation

Predicate that validates a DocumentNode as being an exclusively client-side operation, i.e. all of it's requests are modified by a @client directive.

function isClientOperation(operation: Operation): boolean

isValidGql

Predicate that validates an object as a DocumentNode.

function isValidGql(document: DocumentNode | any): boolean

Index

Functions

apply

  • apply<T>(host: T, klass: Constructor<T> | typeof ApolloElementElement, type: Type, effects?: (host: T) => void): PropertyDescriptorMap
  • Type parameters

    Parameters

    • host: T
    • klass: Constructor<T> | typeof ApolloElementElement
    • type: Type
    • Default value effects: (host: T) => void = noop
        • (host: T): void
        • Parameters

          • host: T

          Returns void

    Returns PropertyDescriptorMap

applyPrototype

  • applyPrototype<S>(target: S, source: Constructor<S>): PropertyDescriptorMap
  • Type parameters

    Parameters

    Returns PropertyDescriptorMap

booleanAttr

  • booleanAttr<C>(attr: string): PropertyDescriptor
  • Type parameters

    Parameters

    • attr: string

    Returns PropertyDescriptor

createApolloClient

cuid

  • cuid(): string
  • Returns string

effect

  • effect<C>(options: PropertyEffectOptions<C>): PropertyDescriptor
  • Type parameters

    Parameters

    • options: PropertyEffectOptions<C>

    Returns PropertyDescriptor

fingerprint

  • fingerprint(): string
  • Returns string

getDescriptor

  • getDescriptor<T>(host: T): PropertyDescriptorMap
  • Type parameters

    Parameters

    • host: T

    Returns PropertyDescriptorMap

getPrototypicalPropertyDescriptor

  • getPrototypicalPropertyDescriptor<T, Key>(o: T, key: Key extends keyof T ? keyof T : never): PropertyDescriptor | undefined
  • Similar to Object.getOwnPropertyDescriptor, except it traverses the entire prototype chain

    Type parameters

    • T: unknown

    • Key: keyof T

    Parameters

    • o: T
    • key: Key extends keyof T ? keyof T : never

    Returns PropertyDescriptor | undefined

gqlDocument

  • gqlDocument<C>(): PropertyDescriptor
  • Type parameters

    Returns PropertyDescriptor

hasAllVariables

  • hasAllVariables(operation: Partial<Operation>): boolean
  • Checks whether an operation includes all its non-nullable variables

    hasAllVariables :: Operation -> Bool

    Parameters

    • operation: Partial<Operation>

    Returns boolean

isClientOperation

  • isClientOperation(operation: Operation): boolean
  • Parameters

    • operation: Operation

    Returns boolean

isEmpty

  • isEmpty(x: object | Array<unknown>): boolean
  • Parameters

    • x: object | Array<unknown>

    Returns boolean

Const isValidGql

  • isValidGql :: DocumentNode a => a -> Bool Validates a graphql document node.

    Parameters

    Returns boolean

pad

  • pad(num: string, size: number): string
  • cuid.js Collision-resistant UID generator for browsers and node. Sequential for fast db lookups and recency sorting. Safe for element IDs and server-side lookups.

    Extracted from CLCTR

    Copyright (c) Eric Elliott 2012 MIT License

    Parameters

    • num: string
    • size: number

    Returns string

splitCommasAndTrim

  • splitCommasAndTrim(value: string): string[]
  • Splits a string by , then trims each of the results

    Parameters

    • value: string

    Returns string[]

writable

  • writable(init?: unknown): PropertyDescriptor
  • Parameters

    • Optional init: unknown

    Returns PropertyDescriptor