UNPKG

@nestjs/graphql

Version:

GraphQL for NestJS: code-first and schema-first APIs, resolvers as providers, subscriptions, federation and generated SDL, on Apollo or Mercurius.

35 lines (34 loc) • 1.25 kB
import { GqlParamtype } from '../enums/gql-paramtype.enum.js'; import { normalizeResolverArgs } from '../utils/normalize-resolver-args.js'; /** * @publicApi */ export class GqlParamsFactory { exchangeKeyForValue(type, data, args) { if (!args) { return null; } args = normalizeResolverArgs(args); switch (type) { case GqlParamtype.ROOT: return args[0]; case GqlParamtype.ARGS: if (!data || !args[1]) { return args[1]; } // An argument the client left out is missing from the arguments // object, so it must not resolve to a member of "Object.prototype" // (e.g., "constructor" or "toString") return !Object.prototype.hasOwnProperty.call(args[1], data) && data in Object.prototype ? undefined : args[1][data]; case GqlParamtype.CONTEXT: return data && args[2] ? args[2][data] : args[2]; case GqlParamtype.INFO: return data && args[3] ? args[3][data] : args[3]; default: return null; } } }