Ejemplo n.º 1
0
        internal InputObjectType()
        {
            InputObjectTypeDescriptor descriptor = CreateDescriptor();

            Configure(descriptor);

            if (string.IsNullOrEmpty(descriptor.Name))
            {
                throw new ArgumentException(
                          "An input object type name must not be null or empty.");
            }

            if (!descriptor.Fields.Any())
            {
                throw new ArgumentException(
                          $"The input object `{descriptor.Name}` must at least " +
                          "provide one field.");
            }

            foreach (InputFieldDescriptor fieldDescriptor in descriptor.Fields)
            {
                _fieldMap[fieldDescriptor.Name] = fieldDescriptor.CreateField();
            }

            _nativeType = descriptor.NativeType;

            Name        = descriptor.Name;
            Description = descriptor.Description;
        }
Ejemplo n.º 2
0
        private void Initialize(InputObjectTypeDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (string.IsNullOrEmpty(descriptor.Name))
            {
                throw new ArgumentException(
                          "An input object type name must not be null or empty.");
            }

            foreach (InputField field in
                     descriptor.GetFieldDescriptors()
                     .Select(t => new InputField(t)))
            {
                _fieldMap[field.Name] = field;
            }

            _nativeType = descriptor.NativeType;

            SyntaxNode  = descriptor.SyntaxNode;
            Name        = descriptor.Name;
            Description = descriptor.Description;
        }
Ejemplo n.º 3
0
        protected override InputObjectTypeDefinition CreateDefinition(
            IInitializationContext context)
        {
            var descriptor = InputObjectTypeDescriptor.New <T>(
                context.DescriptorContext);

            _configure(descriptor);
            return(descriptor.CreateDefinition());
        }
Ejemplo n.º 4
0
        protected override InputObjectTypeDefinition CreateDefinition(
            ITypeDiscoveryContext context)
        {
            var descriptor = InputObjectTypeDescriptor.FromSchemaType(
                context.DescriptorContext,
                GetType());

            _configure(descriptor);
            return(descriptor.CreateDefinition());
        }
Ejemplo n.º 5
0
        protected override InputObjectTypeDefinition CreateDefinition(
            ITypeDiscoveryContext context)
        {
            var descriptor =
                InputObjectTypeDescriptor.New <T>(context.DescriptorContext);

            _configure !(descriptor);
            _configure = null;

            return(descriptor.CreateDefinition());
        }
Ejemplo n.º 6
0
        private void Initialize(Action <IInputObjectTypeDescriptor> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            InputObjectTypeDescriptor descriptor = CreateDescriptor();

            configure(descriptor);
            Initialize(descriptor);
        }
Ejemplo n.º 7
0
        public void Ignore_ExpressionIsNull_ArgumentNullException()
        {
            // arrange
            InputObjectTypeDescriptor <SimpleInput> descriptor =
                InputObjectTypeDescriptor.New <SimpleInput>(
                    DescriptorContext.Create());

            // act
            Action action = () =>
                            InputObjectTypeDescriptorExtensions
                            .Ignore(descriptor, null);

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
        public void Field_Ignore_PropertyIsExcluded()
        {
            // arrange
            var descriptor = new InputObjectTypeDescriptor <SimpleInput>();
            IInputObjectTypeDescriptor <SimpleInput> descriptorItf = descriptor;

            // act
            descriptorItf.Field(t => t.Id).Ignore();

            // assert
            InputObjectTypeDescription description =
                descriptor.CreateDescription();

            Assert.Collection(description.Fields,
                              t => Assert.Equal("name", t.Name));
        }
        public void Field_Ignore_PropertyIsExcluded()
        {
            // arrange
            var descriptor =
                InputObjectTypeDescriptor.New <SimpleInput>(Context);

            // act
            descriptor.Field(t => t.Id).Ignore();

            // assert
            InputObjectTypeDefinition description =
                descriptor.CreateDefinition();

            Assert.Collection(description.Fields,
                              t => Assert.Equal("name", t.Name));
        }
Ejemplo n.º 10
0
        private void Initialize(Action <IInputObjectTypeDescriptor> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            InputObjectTypeDescriptor descriptor = CreateDescriptor();

            configure(descriptor);

            InputObjectTypeDescription description = descriptor.CreateDescription();

            NativeType  = description.NativeType;
            SyntaxNode  = description.SyntaxNode;
            Name        = description.Name;
            Description = description.Description;
            Fields      = new FieldCollection <InputField>(
                description.Fields.Select(t => new InputField(t)));
        }
        protected override InputObjectTypeDefinition CreateDefinition(ITypeDiscoveryContext context)
        {
            try
            {
                if (Definition is null)
                {
                    var descriptor = InputObjectTypeDescriptor.FromSchemaType(
                        context.DescriptorContext,
                        GetType());
                    _configure !(descriptor);
                    return(descriptor.CreateDefinition());
                }

                return(Definition);
            }
            finally
            {
                _configure = null;
            }
        }
Ejemplo n.º 12
0
        private void Initialize(Action <IInputObjectTypeDescriptor> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            InputObjectTypeDescriptor descriptor = CreateDescriptor();

            configure(descriptor);

            InputObjectTypeDescription description =
                descriptor.CreateDescription();

            ClrType    = description.ClrType ?? typeof(object);
            SyntaxNode = description.SyntaxNode;
            Fields     = new FieldCollection <InputField>(
                description.Fields.Select(t => new InputField(t)));

            Initialize(description.Name, description.Description,
                       new DirectiveCollection(this,
                                               DirectiveLocation.InputObject,
                                               description.Directives));
        }