/// <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)
        {
            if (_rawDefaultValue == null)
            {
                return;
            }

            if (_rawDefaultValue is bool boolValue)
            {
                // microsoft returns "True" and "False" for boolean conversions to string
                // #sad face
                this.DefaultValue = boolValue.ToString().ToLowerInvariant();
            }
            else if (_rawDefaultValue is string stringValue)
            {
                // graphql requires and defaultValue parameters be encoded as a string
                // see spec: https://graphql.github.io/graphql-spec/June2018/#sec-The-__InputValue-Type
                // any strings must be escaped to be treated as a string
                // e.g. convert "myString" => "\"myString\""
                var delimiter = stringValue.Contains("\n") ? ParserConstants.BLOCK_STRING_DELIMITER : ParserConstants.NORMAL_STRING_DELIMITER;
                this.DefaultValue = $"{delimiter}{stringValue}{delimiter}";
            }
            else if (this.IntrospectedGraphType.Kind == TypeKind.ENUM)
            {
                this.DefaultValue = schema.Schema.Configuration.DeclarationOptions.GraphNamingFormatter.FormatEnumValueName(_rawDefaultValue?.ToString());
            }
            else
            {
                this.DefaultValue = _rawDefaultValue.ToString();
            }
        }
        /// <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;
            }
        }
 /// <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 void Initialize(IntrospectedSchema schema)
 {
     this.LoadFields(schema);
     this.LoadInterfaces(schema);
     this.LoadEnumValues();
     this.LoadInputValues(schema);
     this.LoadPossibleTypes(schema);
 }
Пример #4
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;
            }
        }