graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Exception when using enum in schema first

Open featherbits opened this issue 7 years ago • 4 comments

Object of type 'System.String' cannot be converted to type '....ProductType'. at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) at HotChocolate.Types.InputField.SetValue(Object obj, Object value) at HotChocolate.Utilities.ObjectValueToInputObjectConverter.VisitObjectField(ObjectFieldNode node, ConverterContext context) at HotChocolate.Utilities.ObjectValueToInputObjectConverter.VisitObjectValue(ObjectValueNode node, ConverterContext context) at HotChocolate.Utilities.ObjectValueToInputObjectConverter.Convert(ObjectValueNode from, InputObjectType to) at HotChocolate.Execution.ArgumentValueBuilder.CoerceArgumentValue(String argumentName, IInputType argumentType, IValueNode defaultValue, IVariableCollection variables, Dictionary2 argumentValues) at HotChocolate.Execution.ArgumentValueBuilder.CoerceArgumentValues(FieldSelection fieldSelection, IVariableCollection variables) at HotChocolate.Execution.ResolverContext..ctor(IExecutionContext executionContext, ResolverTask resolverTask, CancellationToken requestAborted) at HotChocolate.Execution.ResolverTask..ctor(IExecutionContext executionContext, ObjectType objectType, FieldSelection fieldSelection, Path path, IImmutableStack1 source, OrderedDictionary result) at HotChocolate.Execution.ExecutionStrategyBase.CreateRootResolverTasks(IExecutionContext executionContext, OrderedDictionary result)+MoveNext() at HotChocolate.Execution.MutationExecutionStrategy.ExecuteResolverBatchSeriallyAsync(IExecutionContext executionContext, IEnumerable`1 currentBatch, BatchOperationHandler batchOperationHandler, CancellationToken cancellationToken) at HotChocolate.Execution.MutationExecutionStrategy.ExecuteMutationAsync(IExecutionContext executionContext, CancellationToken cancellationToken) at HotChocolate.Execution.ExecuteOperationMiddleware.InvokeAsync(IQueryContext context) at HotChocolate.Execution.ExceptionMiddleware.InvokeAsync(IQueryContext context)

Usage in query type: SERVICE

featherbits avatar Jan 09 '19 10:01 featherbits

Fixed with #484

michaelstaib avatar Jan 14 '19 22:01 michaelstaib

Enum works if used directly as query input field but still fails when used as field in input object.

0.7.0-preview.30

using HotChocolate;
using HotChocolate.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace webapi
{
    public enum SomeEnum {
        EnumVal1
    }
    public class InputObj
    {
        public SomeEnum EnumVal { get; set; }
    }
    public class Mutation
    {
        public bool DoesNotWork(InputObj input) => true;
        public bool DoesWork(SomeEnum input) => true;
    }

    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddGraphQL(sp => Schema.Create(@"
                enum SomeEnum {
                    ENUMVAL1
                }
                input InputObj {
                    enumVal: SomeEnum!
                }
                type Mutation {
                    doesNotWork(input: InputObj!): Boolean!
                    doesWork(input: SomeEnum!): Boolean!
                }
            ", c => {
                c.BindType<Mutation>();
                c.BindType<InputObj>();
            }));
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseGraphQL("/graphql");
            app.UseGraphiQL();
        }
    }
}

featherbits avatar Jan 15 '19 09:01 featherbits

I will write another test ... for this one.

michaelstaib avatar Jan 15 '19 09:01 michaelstaib

Fixed with #489

michaelstaib avatar Jan 15 '19 14:01 michaelstaib