private IGraphField MakeGraphField(IGraphTypeFieldTemplate fieldTemplate) { var testServer = new TestServerBuilder().Build(); var maker = new GraphFieldMaker(testServer.Schema); return(maker.CreateField(fieldTemplate).Field); }
public void Parse_MethodWithNullableEnum_ParsesCorrectly() { var server = new TestServerBuilder().Build(); var template = TemplateHelper.CreateControllerTemplate <NullableEnumController>(); Assert.AreEqual(1, template.FieldTemplates.Count); var field = template.FieldTemplates.FirstOrDefault().Value; Assert.AreEqual(nameof(NullableEnumController.ConvertUnit), field.Name); Assert.AreEqual(typeof(int), field.ObjectType); var arg = field.Arguments[0]; Assert.AreEqual(typeof(NullableEnumController.LengthType), arg.ObjectType); Assert.AreEqual(NullableEnumController.LengthType.Yards, arg.DefaultValue); var graphField = new GraphFieldMaker(server.Schema).CreateField(field).Field; Assert.IsNotNull(graphField); var graphArg = graphField.Arguments.FirstOrDefault(); Assert.IsNotNull(graphArg); Assert.IsEmpty(graphArg.TypeExpression.Wrappers); Assert.AreEqual(GraphArgumentModifiers.None, graphArg.ArgumentModifiers); }
/// <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); } }
public void Parse_PolicyOnController_IsInheritedByField() { var server = new TestServerBuilder().Build(); var template = TemplateHelper.CreateControllerTemplate <SecuredController>(); // method declares no polciies // controller declares 1 var actionMethod = template.Actions.FirstOrDefault(x => x.Name == nameof(SecuredController.DoSomething)); Assert.AreEqual(1, template.SecurityPolicies.Count()); Assert.AreEqual(0, actionMethod.SecurityPolicies.Count()); var graphField = new GraphFieldMaker(server.Schema).CreateField(actionMethod).Field; Assert.AreEqual(1, graphField.SecurityGroups.Count()); var group = graphField.SecurityGroups.First(); Assert.AreEqual(template.SecurityPolicies.First(), group.First()); }
public void Parse_PolicyOnController_AndOnMethod_IsInheritedByField_InCorrectOrder() { var server = new TestServerBuilder().Build(); var template = TemplateHelper.CreateControllerTemplate <SecuredController>(); // controller declares 1 policy // method declares 1 policy var actionMethod = template.Actions.FirstOrDefault(x => x.Name == nameof(SecuredController.DoSomethingSecure)); Assert.AreEqual(1, template.SecurityPolicies.Count()); Assert.AreEqual(1, actionMethod.SecurityPolicies.Count()); var graphField = new GraphFieldMaker(server.Schema).CreateField(actionMethod).Field; Assert.AreEqual(2, graphField.SecurityGroups.Count()); // ensure policy order of controller -> method var controllerTemplateGroup = graphField.SecurityGroups.First(); var fieldTemplateGroup = graphField.SecurityGroups.Skip(1).First(); Assert.AreEqual(template.SecurityPolicies.First(), controllerTemplateGroup.First()); Assert.AreEqual(actionMethod.SecurityPolicies.First(), fieldTemplateGroup.First()); }
/// <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); }