/// <summary> /// Initializes a new instance of the <see cref="IntrospectedType"/> class. /// </summary> /// <param name="ofType">The type this meta type is encapsulating.</param> /// <param name="metaKind">The type kind of this meta type (must be LIST or NON_NULL).</param> public IntrospectedType(IntrospectedType ofType, TypeKind metaKind) { Validation.ThrowIfNull(ofType, nameof(ofType)); if (metaKind != TypeKind.LIST && metaKind != TypeKind.NON_NULL) { throw new ArgumentOutOfRangeException( nameof(metaKind), $"Only {nameof(TypeKind.LIST)} and {nameof(TypeKind.NON_NULL)} are " + $"acceptable meta {nameof(TypeKind)} enumerations."); } if (ofType.Kind == TypeKind.NON_NULL && metaKind == TypeKind.NON_NULL) { throw new GraphTypeDeclarationException( "A non-null type cannot supply a non-null type as its contained type."); } this.OfType = ofType; this.Kind = metaKind; this.Publish = true; this.Name = null; this.Description = null; this.Fields = null; this.Interfaces = null; this.InputFields = null; this.PossibleTypes = null; this.EnumValues = null; this.InputFields = null; }
/// <summary> /// Attempts to find a single introspected object representing the given graph type. If not found /// it will attempt to create it. This method does not support directives. Use the <see cref="Directives"/> /// properties to find directives. /// </summary> /// <param name="graphType">Type of the graph.</param> private void CreateAndStoreIntrospectedType(IGraphType graphType) { if (_typeList.TryGetValue(graphType.Name, out _)) { return; } Func <IGraphType, IntrospectedType> creator; switch (graphType) { case IObjectGraphType _: case IInterfaceGraphType _: case IInputObjectGraphType _: case IScalarGraphType _: case IEnumGraphType _: case IUnionGraphType _: creator = (gt) => new IntrospectedType(gt); break; default: throw new GraphExecutionException($"Invalid graph type. '{graphType.Kind}' is not supported by introspection."); } IntrospectedType foundValue = creator(graphType); _typeList.Add(graphType.Name, foundValue); }
/// <summary> /// Initializes a new instance of the <see cref="IntrospectedInputValueType"/> class. /// </summary> /// <param name="inputField">The field of an input object used to populate this value.</param> /// <param name="introspectedGraphType">The meta data representing the type of this argument.</param> public IntrospectedInputValueType(IGraphField inputField, IntrospectedType introspectedGraphType) { Validation.ThrowIfNull(inputField, nameof(inputField)); this.IntrospectedGraphType = Validation.ThrowIfNullOrReturn(introspectedGraphType, nameof(introspectedGraphType)); this.Name = inputField.Name; this.Description = inputField.Description; }
/// <summary> /// Initializes a new instance of the <see cref="IntrospectedInputValueType" /> class. /// </summary> /// <param name="argument">The field argument used to populate this input value.</param> /// <param name="introspectedGraphType">The meta data representing the type of this argument.</param> public IntrospectedInputValueType(IGraphFieldArgument argument, IntrospectedType introspectedGraphType) { this.IntrospectedGraphType = Validation.ThrowIfNullOrReturn(introspectedGraphType, nameof(introspectedGraphType)); Validation.ThrowIfNull(argument, nameof(argument)); this.Name = argument.Name; this.Description = argument.Description; _rawDefaultValue = argument.DefaultValue; }
/// <summary> /// Loads the fields into this instance for any <see cref="IGraphType"/> that supports them. /// </summary> /// <param name="schema">The schema.</param> private void LoadFields(IntrospectedSchema schema) { if (!(this.GraphType is IGraphFieldContainer fieldContainer)) return; var fields = new List<IntrospectedField>(); foreach (var field in fieldContainer.Fields.Where(x => x.Publish)) { IntrospectedType introspectedType = schema.FindIntrospectedType(field.TypeExpression.TypeName); introspectedType = Introspection.WrapBaseTypeWithModifiers(introspectedType, field.TypeExpression); var introField = new IntrospectedField(field, introspectedType); fields.Add(introField); introField.Initialize(schema); } this.Fields = fields; }
/// <summary> /// Wraps the base type with any necessary modifier types to generate the full type declaration. /// </summary> /// <param name="baseType">The base type to wrap.</param> /// <param name="wrappers">The wrappers.</param> /// <returns>IIntrospectedType.</returns> public static IntrospectedType WrapBaseTypeWithModifiers(IntrospectedType baseType, IReadOnlyList <MetaGraphTypes> wrappers) { for (var i = wrappers.Count - 1; i >= 0; i--) { switch (wrappers[i]) { case MetaGraphTypes.IsNotNull: baseType = new IntrospectedType(baseType, TypeKind.NON_NULL); break; case MetaGraphTypes.IsList: baseType = new IntrospectedType(baseType, TypeKind.LIST); break; } } return(baseType); }
/// <summary> /// Initializes a new instance of the <see cref="IntrospectedField" /> class. /// </summary> /// <param name="field">The field itself.</param> /// <param name="introspectedType">The introspected object representing the graph type returned /// by this field.</param> public IntrospectedField(IGraphField field, IntrospectedType introspectedType) { this.IntrospectedGraphType = Validation.ThrowIfNullOrReturn(introspectedType, nameof(introspectedType)); _field = Validation.ThrowIfNullOrReturn(field, nameof(field)); }
/// <summary> /// Wraps the base type with any necessary modifier types to generate the full type declaration. /// </summary> /// <param name="baseType">The base type to wrap.</param> /// <param name="typeExpression">The type expression.</param> /// <returns>IIntrospectedType.</returns> public static IntrospectedType WrapBaseTypeWithModifiers(IntrospectedType baseType, GraphTypeExpression typeExpression) { return(Introspection.WrapBaseTypeWithModifiers(baseType, typeExpression.Wrappers)); }
/// <summary> /// Wraps the base type with any necessary modifier types to generate the full type declaration. /// </summary> /// <param name="baseType">The base type to wrap.</param> /// <param name="wrappers">The wrappers.</param> /// <returns>IIntrospectedType.</returns> public static IntrospectedType WrapBaseTypeWithModifiers(IntrospectedType baseType, params MetaGraphTypes[] wrappers) { return(Introspection.WrapBaseTypeWithModifiers(baseType, wrappers.ToList())); }