private TypeInitializer InitializeTypes( IServiceProvider services, IDescriptorContext descriptorContext, IBindingLookup bindingLookup, IEnumerable <ITypeReference> types, Func <ISchema> schemaResolver) { var initializer = new TypeInitializer( services, descriptorContext, types, _resolverTypes, _contextData, _isOfType, IsQueryType); foreach (FieldMiddleware component in _globalComponents) { initializer.GlobalComponents.Add(component); } foreach (FieldReference reference in _resolvers.Keys) { initializer.Resolvers[reference] = new RegisteredResolver( typeof(object), _resolvers[reference]); } foreach (RegisteredResolver resolver in bindingLookup.Bindings .SelectMany(t => t.CreateResolvers())) { var reference = new FieldReference( resolver.Field.TypeName, resolver.Field.FieldName); initializer.Resolvers[reference] = resolver; } initializer.Initialize(schemaResolver); return(initializer); }
public void Initializer_SchemaOptions_Are_Null() { // arrange var initialTypes = new List <ITypeReference>(); initialTypes.Add(new ClrTypeReference( typeof(Foo), TypeContext.Output)); var serviceProvider = new EmptyServiceProvider(); var typeInitializer = new TypeInitializer( serviceProvider, DescriptorContext.Create(), initialTypes, new List <Type>(), new Dictionary <string, object>(), null, t => t is ObjectType <Foo>); // act Action action = () => typeInitializer.Initialize(() => null, null); // assert Assert.Throws <ArgumentNullException>(action); }
public Schema Create() { IServiceProvider services = _services ?? new EmptyServiceProvider(); var descriptorContext = DescriptorContext.Create( _options, services, CreateConventions(services), _contextData); foreach (Action <IDescriptorContext> action in _onBeforeCreate) { action(descriptorContext); } IBindingLookup bindingLookup = _bindingCompiler.Compile(descriptorContext); IReadOnlyCollection <ITypeReference> types = GetTypeReferences(services, bindingLookup); var lazy = new LazySchema(); TypeInitializer initializer = CreateTypeInitializer( services, descriptorContext, bindingLookup, types); DiscoveredTypes discoveredTypes = initializer.Initialize(() => lazy.Schema, _options); SchemaTypesDefinition definition = CreateSchemaDefinition(initializer, discoveredTypes); if (definition.QueryType == null && _options.StrictValidation) { throw new SchemaException( SchemaErrorBuilder.New() .SetMessage(TypeResources.SchemaBuilder_NoQueryType) .Build()); } Schema schema = discoveredTypes.Types .Select(t => t.Type) .OfType <Schema>() .First(); schema.CompleteSchema(definition); lazy.Schema = schema; TypeInspector.Default.Clear(); return(schema); }
private static TypeRegistry InitializeTypes( SchemaBuilder builder, IDescriptorContext context, IReadOnlyList <ITypeReference> types, LazySchema lazySchema) { var typeRegistry = new TypeRegistry(context.TypeInterceptor); TypeInitializer initializer = CreateTypeInitializer(builder, context, types, typeRegistry); initializer.Initialize(() => lazySchema.Schema, builder._options); return(typeRegistry); }
public void Register_ClrType_InferSchemaTypes() { // arrange var initialTypes = new List <ITypeReference>(); initialTypes.Add(new ClrTypeReference( typeof(Foo), TypeContext.Output)); var serviceProvider = new EmptyServiceProvider(); var typeInitializer = new TypeInitializer( serviceProvider, DescriptorContext.Create(), initialTypes, new List <Type>(), new Dictionary <string, object>(), new AggregateTypeInitilizationInterceptor(), null, t => t is ObjectType <Foo>); // act typeInitializer.Initialize(() => null, new SchemaOptions()); // assert bool exists = typeInitializer.Types.TryGetValue( new ClrTypeReference( typeof(ObjectType <Foo>), TypeContext.Output), out RegisteredType type); Assert.True(exists); Assert.IsType <ObjectType <Foo> >(type.Type).Fields.ToDictionary( t => t.Name.ToString(), t => TypeVisualizer.Visualize(t.Type)) .MatchSnapshot(new SnapshotNameExtension("FooType")); exists = typeInitializer.Types.TryGetValue( new ClrTypeReference(typeof(ObjectType <Bar>), TypeContext.Output), out type); Assert.True(exists); Assert.IsType <ObjectType <Bar> >(type.Type).Fields.ToDictionary( t => t.Name.ToString(), t => TypeVisualizer.Visualize(t.Type)) .MatchSnapshot(new SnapshotNameExtension("BarType")); }
public void Register_SchemaType_ClrTypeExists() { // arrange var initialTypes = new List <ITypeReference>(); initialTypes.Add(new ClrTypeReference( typeof(FooType), TypeContext.Output)); var serviceProvider = new EmptyServiceProvider(); var typeInitializer = new TypeInitializer( serviceProvider, initialTypes, new List <Type>(), new Dictionary <string, object>(), null, t => t is FooType); // act typeInitializer.Initialize(() => null); // assert bool exists = typeInitializer.Types.TryGetValue( new ClrTypeReference(typeof(FooType), TypeContext.Output), out RegisteredType type); Assert.True(exists); Assert.IsType <FooType>(type.Type).Fields.ToDictionary( t => t.Name.ToString(), t => TypeVisualizer.Visualize(t.Type)) .MatchSnapshot(new SnapshotNameExtension("FooType")); exists = typeInitializer.Types.TryGetValue( new ClrTypeReference(typeof(BarType), TypeContext.Output), out type); Assert.True(exists); Assert.IsType <BarType>(type.Type).Fields.ToDictionary( t => t.Name.ToString(), t => TypeVisualizer.Visualize(t.Type)) .MatchSnapshot(new SnapshotNameExtension("BarType")); }