Sha256: 022bc62a0955f87768a78a4caaa1224d8af7936248fefc7d87aaeeffdf3e34c0

Contents?: true

Size: 1.45 KB

Versions: 26

Compression:

Stored size: 1.45 KB

Contents

import { keyValMap } from '../jsutils/keyValMap.mjs';
import { Kind } from '../language/kinds.mjs';
/**
 * Produces a JavaScript value given a GraphQL Value AST.
 *
 * Unlike `valueFromAST()`, no type is provided. The resulting JavaScript value
 * will reflect the provided GraphQL value AST.
 *
 * | GraphQL Value        | JavaScript Value |
 * | -------------------- | ---------------- |
 * | Input Object         | Object           |
 * | List                 | Array            |
 * | Boolean              | Boolean          |
 * | String / Enum        | String           |
 * | Int / Float          | Number           |
 * | Null                 | null             |
 *
 */

export function valueFromASTUntyped(valueNode, variables) {
  switch (valueNode.kind) {
    case Kind.NULL:
      return null;

    case Kind.INT:
      return parseInt(valueNode.value, 10);

    case Kind.FLOAT:
      return parseFloat(valueNode.value);

    case Kind.STRING:
    case Kind.ENUM:
    case Kind.BOOLEAN:
      return valueNode.value;

    case Kind.LIST:
      return valueNode.values.map((node) =>
        valueFromASTUntyped(node, variables),
      );

    case Kind.OBJECT:
      return keyValMap(
        valueNode.fields,
        (field) => field.name.value,
        (field) => valueFromASTUntyped(field.value, variables),
      );

    case Kind.VARIABLE:
      return variables === null || variables === void 0
        ? void 0
        : variables[valueNode.name.value];
  }
}

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.25 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.24 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.23 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.22 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.21 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.20 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.19 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.18 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.17 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.16 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.15 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.14 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.13 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.12 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.11 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.10 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.9 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.8 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs
clapton-0.0.7 lib/clapton/javascripts/node_modules/graphql/utilities/valueFromASTUntyped.mjs