UNPKG

@vendure/core

Version:

A modern, headless ecommerce framework

37 lines (36 loc) 1.45 kB
import { GraphQLResolveInfo } from 'graphql'; /** * Recursive map of selected GraphQL fields. Leaf fields map to an empty object; * fields with sub-selections map to the same shape nested. * * Example query: `{ user { id orders { code } } }` yields: * ``` * { user: { id: {}, orders: { code: {} } } } * ``` */ export type FieldTree = { [fieldName: string]: FieldTree; }; /** * Walks a `GraphQLResolveInfo` and produces a nested object describing the * fields the client has selected on this resolver's return type. * * Vendored from `graphql-fields@2.0.3`: * - Source: https://github.com/robrichard/graphql-fields * - Copyright (c) 2016 Rob Richard * - Licence: MIT (https://github.com/robrichard/graphql-fields/blob/master/LICENSE) * * Trimmed to the subset Vendure actually uses — the `processArguments` and * `excludedFields` options upstream supports are omitted because the single * call site (`@Relations()` decorator) never passes them. * * Supports: * - direct field selections * - inline fragments (`... on Type { ... }`) * - named fragment spreads (`...FragmentName`) * - `@skip(if: ...)` and `@include(if: ...)` directives, including those * reading from `info.variableValues` * - field merging when the same field appears multiple times across * fragments (later occurrences extend earlier ones) */ export declare function graphqlFields(info: GraphQLResolveInfo): FieldTree;