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

getGraphQLScriptChildDocument

Gets the gql-parsed DocumentNode from a direct <script type="application/graphql"> child of an element.

function getGraphQLScriptChildDocument(element: HTMLElement): DocumentNode | null;

gqlFromInnerText

Gets an element's innerText and parses it as GraphQL.

function gqlFromInnerText(element: HTMLScriptElement): DocumentNode | null

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

getGraphQLScriptChild

  • Get the child of the element that is a graphql script

    Parameters

    Returns HTMLScriptElement

getGraphQLScriptChildDocument

  • Parameters

    Returns DocumentNode | null

getPrototypicalPropertyDescriptor

  • getPrototypicalPropertyDescriptor<T, Key>(o: T, key: Key extends keyof T ? keyof T : never): PropertyDescriptor
  • 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

gqlFromInnerText

  • gqlFromInnerText :: (HTMLScriptElement a, DocumentNode b) => a -> b Parses the text content of a graphql script element.

    Parameters

    Returns DocumentNode | null

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

isGraphQLScript

  • isGraphQLScript(el: Element): boolean
  • Is it a <script type="application/graphql">

    Parameters

    Returns boolean

Const isValidGql

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

    Parameters

    Returns boolean

splitCommasAndTrim

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

    Parameters

    • value: string

    Returns string[]

stripUndefinedValues

  • stripUndefinedValues<X>(o: X): X
  • Type parameters

    • X

    Parameters

    • o: X

    Returns X