@nestjs/graphql
Version:
GraphQL for NestJS: code-first and schema-first APIs, resolvers as providers, subscriptions, federation and generated SDL, on Apollo or Mercurius.
27 lines (26 loc) • 929 B
JavaScript
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host.js';
import { normalizeResolverArgs } from '../utils/normalize-resolver-args.js';
export class GqlArgumentsHost extends ExecutionContextHost {
static create(context) {
const type = context.getType();
// Reference and "resolveType" resolvers get no "args" argument: align the
// positions with those of a field resolver (as "GqlExecutionContext" does)
const gqlContext = new GqlArgumentsHost(type === 'graphql'
? normalizeResolverArgs(context.getArgs())
: context.getArgs());
gqlContext.setType(type);
return gqlContext;
}
getRoot() {
return this.getArgByIndex(0);
}
getArgs() {
return this.getArgByIndex(1);
}
getContext() {
return this.getArgByIndex(2);
}
getInfo() {
return this.getArgByIndex(3);
}
}