MCPcopy
hub / github.com/graphql/graphql-js / constructor

Method constructor

src/type/directives.ts:171–196  ·  view source on GitHub ↗

* Creates a GraphQLDirective instance. * @param config - Configuration describing this object. * @example * ```ts * import { DirectiveLocation, parse } from 'graphql/language'; * import { * GraphQLBoolean, * GraphQLDirective, * GraphQLInt, * GraphQLNonNull, * }

(config: Readonly<GraphQLDirectiveConfig>)

Source from the content-addressed store, hash-verified

169 * ```
170 */
171 constructor(config: Readonly<GraphQLDirectiveConfig>) {
172 this.__kind = directiveSymbol;
173 this.name = assertName(config.name);
174 this.description = config.description;
175 this.locations = config.locations;
176 this.isRepeatable = config.isRepeatable ?? false;
177 this.deprecationReason = config.deprecationReason;
178 this.extensions = toObjMapWithSymbols(config.extensions);
179 this.astNode = config.astNode;
180 this.extensionASTNodes = config.extensionASTNodes ?? [];
181
182 devAssert(
183 Array.isArray(config.locations),
184 `@${this.name} locations must be an Array.`,
185 );
186
187 const args = config.args ?? {};
188 devAssert(
189 isObjectLike(args) && !Array.isArray(args),
190 `@${this.name} args must be an object with argument names as keys.`,
191 );
192
193 this.args = Object.entries(args).map(
194 ([argName, argConfig]) => new GraphQLArgument(this, argName, argConfig),
195 );
196 }
197
198 /**
199 * Returns the value used by `Object.prototype.toString`.

Callers

nothing calls this directly

Calls 4

assertNameFunction · 0.90
toObjMapWithSymbolsFunction · 0.90
devAssertFunction · 0.90
isObjectLikeFunction · 0.90

Tested by

no test coverage detected