private IGraphField MakeGraphField(IGraphTypeFieldTemplate fieldTemplate) { var testServer = new TestServerBuilder().Build(); var maker = new GraphFieldMaker(testServer.Schema); return(maker.CreateField(fieldTemplate).Field); }
/// <summary> /// Adds the type extension to the schema for the configured concrete type. If the type /// is not registered to the schema the field extension is queued for when it is added (if ever). /// </summary> /// <param name="extension">The extension to add.</param> private void AddTypeExtension(IGraphTypeFieldTemplate extension) { var fieldMaker = new GraphFieldMaker(this.Schema); var fieldResult = fieldMaker.CreateField(extension); if (fieldResult != null) { this.Schema.KnownTypes.EnsureGraphFieldExtension(extension.SourceObjectType, 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="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> /// Creates a mocked context for the execution of a single field of data against the given concrete type and field name. This /// context can be submitted against the field execution pipeline to generate a result. /// </summary> /// <typeparam name="TType">The concrete type to create the request against. /// Either a graph type, directive or controller.</typeparam> /// <param name="fieldName">Name of the field, on the type, as it exists in the schema.</param> /// <param name="sourceData">The source data to use as the input to the field. This can be changed, but must be supplied. A /// generic <see cref="object"/> will be used if not supplied.</param> /// <returns>IMockFieldRequest.</returns> public FieldContextBuilder CreateFieldContextBuilder <TType>(string fieldName, object sourceData = null) { var template = TemplateHelper.CreateFieldTemplate <TType>(fieldName); var fieldMaker = new GraphFieldMaker(this.Schema); var fieldResult = fieldMaker.CreateField(template); var builder = new FieldContextBuilder( this.ServiceProvider, _userAccount, fieldResult.Field, this.Schema, template as IGraphMethod); if (sourceData == null) { builder.AddSourceData(new object()); } else { builder.AddSourceData(sourceData); } return(builder); }