/// <summary> /// Initializes the schema: /// * Add any controllers to the schema instance that were configured during startup. /// * add all methods, virtual graph types, return types parameters and property configuration. /// * Add any additional types added at startup. /// * Register introspection meta-fields. /// * Compile and instantiate the resolution pipeline. /// </summary> /// <param name="schema">The schema to initialize.</param> public virtual void Initialize(ISchema schema) { Validation.ThrowIfNull(schema, nameof(schema)); if (schema.IsInitialized) { return; } lock (schema) { if (schema.IsInitialized) { return; } schema.Configuration.Merge(_options.CreateConfiguration()); var manager = new GraphSchemaManager(schema); manager.AddIntrospectionFields(); manager.AddBuiltInDirectives(); // add any configured types to this instance foreach (var type in _options.RegisteredSchemaTypes) { var typeDeclaration = type.SingleAttributeOrDefault <GraphTypeAttribute>(); if (typeDeclaration != null && typeDeclaration.PreventAutoInclusion) { continue; } manager.EnsureGraphType(type); } manager.BuildIntrospectionData(); schema.IsInitialized = true; } }
public void AddIntrospectionFields_AllFieldsAdded() { var schema = new GraphSchema() as ISchema; var manager = new GraphSchemaManager(schema); manager.AddIntrospectionFields(); Assert.AreEqual(2, schema.KnownTypes.Count(x => x.Kind == TypeKind.SCALAR)); Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.STRING))); Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.BOOLEAN))); Assert.AreEqual(2, schema.KnownTypes.Count(x => x.Kind == TypeKind.ENUM)); Assert.IsTrue(schema.KnownTypes.Contains(typeof(DirectiveLocation), TypeKind.ENUM)); Assert.IsTrue(schema.KnownTypes.Contains(typeof(TypeKind), TypeKind.ENUM)); Assert.AreEqual(7, schema.KnownTypes.Count(x => x.Kind == TypeKind.OBJECT)); Assert.IsTrue(schema.KnownTypes.Contains(Constants.ReservedNames.QUERY_TYPE_NAME)); Assert.IsTrue(schema.KnownTypes.Contains(Constants.ReservedNames.DIRECTIVE_TYPE)); Assert.IsTrue(schema.KnownTypes.Contains(Constants.ReservedNames.ENUM_VALUE_TYPE)); Assert.IsTrue(schema.KnownTypes.Contains(Constants.ReservedNames.FIELD_TYPE)); Assert.IsTrue(schema.KnownTypes.Contains(Constants.ReservedNames.INPUT_VALUE_TYPE)); Assert.IsTrue(schema.KnownTypes.Contains(Constants.ReservedNames.SCHEMA_TYPE)); Assert.IsTrue(schema.KnownTypes.Contains(Constants.ReservedNames.TYPE_TYPE)); }