/// <summary>
        /// Loads the possible types field for for unions or interfaces.
        /// </summary>
        /// <param name="schema">The schema.</param>
        private void LoadPossibleTypes(IntrospectedSchema schema)
        {
            var possibleTypes = new List<IntrospectedType>();
            if (this.GraphType is IUnionGraphType unionType)
            {
                // find all the graph types in the schema that implement this interface
                foreach (var typeName in unionType.PossibleGraphTypeNames)
                {
                    var foundType = schema.FindIntrospectedType(typeName);
                    if (foundType != null)
                        possibleTypes.Add(foundType);
                }

                this.PossibleTypes = possibleTypes;
            }
            else if (this.GraphType is IInterfaceGraphType interfaceType)
            {
                var graphTypes = schema.FindIntrospectedTypesByInterface(interfaceType.Name);
                foreach (var possibleType in graphTypes)
                {
                    possibleTypes.Add(possibleType);
                }

                this.PossibleTypes = possibleTypes;
            }
        }
Example #2
0
        /// <summary>
        /// When overridden in a child class,populates this introspected type using its parent schema to fill in any details about
        /// other references in this instance.
        /// </summary>
        /// <param name="schema">The schema.</param>
        public override void Initialize(IntrospectedSchema schema)
        {
            var list = new List <IntrospectedInputValueType>();

            foreach (var arg in _field.Arguments.Where(x => !x.ArgumentModifiers.HasFlag(GraphArgumentModifiers.Internal)))
            {
                var introspectedType = schema.FindIntrospectedType(arg.TypeExpression.TypeName);
                introspectedType = Introspection.WrapBaseTypeWithModifiers(introspectedType, arg.TypeExpression);
                var inputValue = new IntrospectedInputValueType(arg, introspectedType);
                inputValue.Initialize(schema);
                list.Add(inputValue);
            }

            this.Arguments = list;
        }
        /// <summary>
        /// When overridden in a child class,populates this introspected type using its parent schema to fill in any details about
        /// other references in this instance.
        /// </summary>
        /// <param name="schema">The schema.</param>
        public override void Initialize(IntrospectedSchema schema)
        {
            var list = new List <IntrospectedInputValueType>();

            foreach (var arg in this.GraphType.Arguments)
            {
                var introspectedType = schema.FindIntrospectedType(arg.TypeExpression.TypeName);
                introspectedType = Introspection.WrapBaseTypeWithModifiers(introspectedType, arg.TypeExpression);
                var inputValue = new IntrospectedInputValueType(arg, introspectedType);
                list.Add(inputValue);
            }

            this.Arguments = list;
            this.Locations = this.GraphType.Locations.GetIndividualFlags <DirectiveLocation>().ToList();
            this.Publish   = this.GraphType.Publish;
        }
        /// <summary>
        /// Loads the fields into this instance for any <see cref="IGraphType"/> that supports them.
        /// </summary>
        /// <param name="schema">The schema.</param>
        private void LoadFields(IntrospectedSchema schema)
        {
            if (!(this.GraphType is IGraphFieldContainer fieldContainer))
                return;

            var fields = new List<IntrospectedField>();
            foreach (var field in fieldContainer.Fields.Where(x => x.Publish))
            {
                IntrospectedType introspectedType = schema.FindIntrospectedType(field.TypeExpression.TypeName);
                introspectedType = Introspection.WrapBaseTypeWithModifiers(introspectedType, field.TypeExpression);
                var introField = new IntrospectedField(field, introspectedType);
                fields.Add(introField);
                introField.Initialize(schema);
            }

            this.Fields = fields;
        }
        private void LoadInputValues(IntrospectedSchema schema)
        {
            if (!(this.GraphType is IInputObjectGraphType inputType))
                return;

            // populate inputFields collection
            // populate the fields for this object type
            var inputFields = new List<IntrospectedInputValueType>();
            foreach (var field in inputType.Fields)
            {
                var introspectedType = schema.FindIntrospectedType(field.TypeExpression.TypeName);
                introspectedType = Introspection.WrapBaseTypeWithModifiers(introspectedType, field.TypeExpression);
                var inputField = new IntrospectedInputValueType(field, introspectedType);
                inputField.Initialize(schema);
                inputFields.Add(inputField);
            }

            this.InputFields = inputFields;
        }
        /// <summary>
        /// Loads the interfaces for any graph type that supports them.
        /// </summary>
        /// <param name="schema">The schema.</param>
        private void LoadInterfaces(IntrospectedSchema schema)
        {
            if (this.GraphType is IGraphInterfaceContainer interfaceContainer)
            {
                // populate the interfaces for this object type, if any are defined and exist
                var interfaceList = new List<IntrospectedType>();
                foreach (var ifaceName in interfaceContainer.InterfaceNames)
                {
                    // if the schema doesn't know of the interface, skip it.
                    var introspectedType = schema.FindIntrospectedType(ifaceName);
                    if (introspectedType == null)
                        continue;

                    interfaceList.Add(introspectedType);
                }

                this.Interfaces = interfaceList;
            }
        }