Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "common"

Index

Type aliases

FetchPolicy

FetchPolicy: "cache-first" | "cache-and-network" | "network-only" | "cache-only" | "no-cache"

Fetch policy based in Apollo fetchPolicy behaviour https://www.apollographql.com/docs/react/api/react-apollo/#optionsfetchpolicy

FetchState

FetchState: "waiting" | "loading" | "error" | "done"

Possible fetch states

Headers

Headers: Record<string, string | number | boolean>

Serializable headers

IVariables

IVariables: Record<string, unknown>

GraphQL variables

Maybe

Maybe<T>: T | null | undefined

Possible missing type

Type parameters

  • T

Functions

Const clearCacheKey

Const getAccessorFields

  • getAccessorFields<TAccesorData, TAccesorKeys>(accessor: TAccesorData, ...keys: TAccesorKeys[]): {}
  • Shorthand utility function to return data from accessors

    example
    useQuery((schema, variables) => {
       // This is the long way
       // const { title, content, publishedData } =
       // schema.blog({ id: variables.id });
       // return { title, content, publishedData };
    
       // This is the quicker way
       return getAccessorFields(schema.blog({ id: variables.id }), "title", "content", "publishedDate");
    })

    Type parameters

    • TAccesorData

    • TAccesorKeys: keyof TAccesorData

    Parameters

    • accessor: TAccesorData
    • Rest ...keys: TAccesorKeys[]

    Returns {}

Const getArrayAccessorFields

  • getArrayAccessorFields<TArrayValue, TArrayValueKeys>(accessorArray: TArrayValue[], ...keys: TArrayValueKeys[]): {}[]
  • Shorthand utility function to return data from an accessor array

    example
    useQuery((schema) => {
       // This is the long way
       // return schema.blogList.map({ title, content, publishedData }
       // => ({ title, content, publishedData }));
    
       // This is the quicker way
       return getArrayAccessorFields(schema.blogList, "title", "content","publishedData");
    })

    Type parameters

    • TArrayValue

    • TArrayValueKeys: keyof TArrayValue

    Parameters

    • accessorArray: TArrayValue[]
    • Rest ...keys: TArrayValueKeys[]

    Returns {}[]

Const setCacheData

  • setCacheData<Key>(cacheKey: Key, data: Maybe<gqlessSharedCache[Key]> | ((prevData: Maybe<gqlessSharedCache[Key]>) => Maybe<gqlessSharedCache[Key]>)): void
  • Set imperatively the data of a key in the Shared cache.

    You can give the data right away or a function that receives the previous cacheData and returns the new data

    It can be useful for preparing an specific hook data and prevent unnecessary fetches

    To improve it's type-safety you can declare anywhere it's types following the example

    example
    declare global {
      interface gqlessSharedCache {
        anyCacheKey: string[]
      }
    }

    Type parameters

    Parameters

    • cacheKey: Key
    • data: Maybe<gqlessSharedCache[Key]> | ((prevData: Maybe<gqlessSharedCache[Key]>) => Maybe<gqlessSharedCache[Key]>)

    Returns void

Generated using TypeDoc