/// <summary> /// Applies all fields known extension fields for the interface to the given object graph type. /// </summary> /// <param name="interfaceType">The interface type to search for associated fields.</param> /// <param name="objectGraphType">The object graph type to recieve new fields.</param> private void ApplyAllFields(IInterfaceGraphType interfaceType, IObjectGraphType objectGraphType) { foreach (var field in _fieldsByInterface[interfaceType]) { objectGraphType.Extend(field); } }
/// <summary> /// Iterates the given <see cref="ControllerActionGraphFieldTemplate" /> and adds /// all found types to the type system for this <see cref="ISchema" />. Generates /// a field reference on the provided parent with a resolver pointing to the provided graph action. /// </summary> /// <param name="parentField">The parent which will own the generated action field.</param> /// <param name="action">The action.</param> private void AddActionAsField(IObjectGraphType parentField, IGraphTypeFieldTemplate action) { // apend the action as a field on the parent var maker = new GraphFieldMaker(this.Schema); var fieldResult = maker.CreateField(action); if (fieldResult != null) { parentField.Extend(fieldResult.Field); this.EnsureDependents(fieldResult); } }
/// <summary> /// Iterates the given <see cref="ControllerActionGraphFieldTemplate" /> and adds /// all found types to the type system for this <see cref="ISchema" />. Generates /// a field reference on the provided parent with a resolver pointing to the provided graph action. /// </summary> /// <param name="parentType">The parent which will own the generated action field.</param> /// <param name="action">The action.</param> private void AddActionAsField(IObjectGraphType parentType, IGraphTypeFieldTemplate action) { // apend the action as a field on the parent var maker = GraphQLProviders.GraphTypeMakerProvider.CreateFieldMaker(this.Schema); var fieldResult = maker.CreateField(action); if (fieldResult != null) { if (parentType.Fields.ContainsKey(fieldResult.Field.Name)) { throw new GraphTypeDeclarationException( $"The '{parentType.Kind}' graph type '{parentType.Name}' already contains a field named '{fieldResult.Field.Name}'. " + $"The action method '{action.InternalFullName}' cannot be added to the graph type with the same name."); } parentType.Extend(fieldResult.Field); this.EnsureDependents(fieldResult); } }
/// <summary> /// Performs an out-of-band append of a new graph field to a parent. Accounts for type updates in this schema ONLY. /// </summary> /// <param name="parentType">the parent type to add the new field to.</param> /// <param name="fieldName">Name of the field.</param> /// <param name="path">The path segment to represent the new field.</param> /// <param name="definition">The definition item from which graph attributes should be used, if any. Attributes will be set to an empty string if not supplied.</param> /// <returns>The type associated with the field added to the parent type.</returns> private IObjectGraphType CreateVirtualFieldOnParent( IObjectGraphType parentType, string fieldName, GraphFieldPath path, IGraphItemTemplate definition = null) { var childField = new VirtualGraphField( fieldName, path, this.MakeSafeTypeNameFromRoutePath(path)) { IsDepreciated = false, DepreciationReason = string.Empty, Description = definition?.Description ?? string.Empty, }; parentType.Extend(childField); this.Schema.KnownTypes.EnsureGraphType(childField.AssociatedGraphType); this.EnsureDependents(childField); return(childField.AssociatedGraphType); }