Пример #1
0
        private void DeclareFields(
            IObjectTypeDescriptor typeDescriptor,
            IReadOnlyCollection <FieldDefinitionNode> fieldDefinitions)
        {
            foreach (FieldDefinitionNode fieldDefinition in fieldDefinitions)
            {
                IObjectFieldDescriptor fieldDescriptor = typeDescriptor
                                                         .Field(fieldDefinition.Name.Value)
                                                         .Description(fieldDefinition.Description?.Value)
                                                         .Type(fieldDefinition.Type)
                                                         .SyntaxNode(fieldDefinition);

                foreach (DirectiveNode directive in fieldDefinition.Directives)
                {
                    fieldDescriptor.Directive(directive);
                }

                string deprecactionReason = fieldDefinition.DeprecationReason();
                if (!string.IsNullOrEmpty(deprecactionReason))
                {
                    fieldDescriptor.DeprecationReason(deprecactionReason);
                }

                DeclareFieldArguments(fieldDescriptor, fieldDefinition);
            }
        }
Пример #2
0
        private static void DeclareFields(
            ITypeBindingInfo bindingInfo,
            IObjectTypeDescriptor typeDescriptor,
            IReadOnlyCollection <FieldDefinitionNode> fieldDefinitions)
        {
            foreach (FieldDefinitionNode fieldDefinition in fieldDefinitions)
            {
                bindingInfo.TrackField(fieldDefinition.Name.Value);

                IObjectFieldDescriptor fieldDescriptor = typeDescriptor
                                                         .Field(fieldDefinition.Name.Value)
                                                         .Description(fieldDefinition.Description?.Value)
                                                         .Type(fieldDefinition.Type)
                                                         .SyntaxNode(fieldDefinition);

                if (bindingInfo.TryGetFieldMember(
                        fieldDefinition.Name.Value,
                        MemberKind.ObjectField,
                        out MemberInfo member))
                {
                    fieldDescriptor.Extend().OnBeforeCreate(
                        t => t.Member = member);
                }

                foreach (DirectiveNode directive in fieldDefinition.Directives)
                {
                    if (!directive.IsDeprecationReason())
                    {
                        fieldDescriptor.Directive(directive);
                    }
                }

                string deprecactionReason = fieldDefinition.DeprecationReason();
                if (!string.IsNullOrEmpty(deprecactionReason))
                {
                    fieldDescriptor.DeprecationReason(deprecactionReason);
                }

                DeclareFieldArguments(fieldDescriptor, fieldDefinition);
            }
        }