graphql-dotnet: Unable to use object in mutation.

I’ve been trying to get a mutation to work in graphiql for several days. Here’s the mutation:

public class DataViewMutation : ObjectGraphType
   {
       public DataViewMutation(IDataViewRepository data)
       {
           Name = "DataViewMutation";

           Field<DataViewType>(
               "createDataView",
               arguments: new QueryArguments(
                   new QueryArgument<NonNullGraphType<DataViewInputType>> { Name = "dataView" }
               ),
               resolve: context =>
               {
                   var dataView = context.GetArgument<DataViewInputType>("dataView");
                   
                   var name = context.GetArgument<string>("viewName");
                   var fields = context.GetArgument<ListGraphType<StringGraphType>>("viewColumns");

                   return data.Query(new string[] { "" }, "");//This is empty for now, but I don't even get this far.
               });
       }
   }
}

Here’s the input type:

public class DataViewInputType : InputObjectGraphType<DataViewType>
{
        public DataViewInputType()
	{
	   Name = "DataViewInput";
            Field<NonNullGraphType<StringGraphType>>("viewName");
            Field<NonNullGraphType<StringGraphType>>("clientName",
            resolve: context =>
            {
                return context.GetArgument<List<string>>("clientName");
            });
            Field<ListGraphType<StringGraphType>>("viewColumns",
                resolve: context => {
                    var columns = context.GetArgument<List<string>>("viewColumns");
                    return columns;
                    }
                );
	 }
}

Here’s the call to the mutation:

mutation DataView($dataView: DataViewInput!) {
  createDataView(dataView: $dataView) {
    viewName
    viewColumns {
      columnName
      
    }
  }
}

variables:

{
  "dataView": {
    "viewName": "v_ReadyReports",
    "clientName": "Suntime",
    "viewColumns": [
      "id",
      "product"
    ]
  }
}

And here’s the error:

{
  "errors": [
    {
      "message": "GraphQL.ExecutionError: Variable '$dataView' is invalid. Unable to parse input as a 'DataViewInput' type. Did you provide a List or Scalar value accidentally? ---> GraphQL.Execution.InvalidValueException: Variable '$dataView' is invalid. Unable to parse input as a 'DataViewInput' type. Did you provide a List or Scalar value accidentally?\r\n   at GraphQL.DocumentExecuter.AssertValidValue(ISchema schema, IGraphType type, Object input, String fieldName)\r\n   at GraphQL.DocumentExecuter.AssertValidValue(ISchema schema, IGraphType type, Object input, String fieldName)\r\n   at GraphQL.DocumentExecuter.GetVariableValue(Document document, ISchema schema, VariableDefinition variable, Object input)\r\n   at GraphQL.DocumentExecuter.<>c__DisplayClass28_0.<GetVariableValues>b__0(VariableDefinition v)\r\n   at GraphQL.EnumerableExtensions.Apply[T](IEnumerable`1 items, Action`1 action)\r\n   at GraphQL.DocumentExecuter.GetVariableValues(Document document, ISchema schema, VariableDefinitions variableDefinitions, Inputs inputs)\r\n   at GraphQL.DocumentExecuter.BuildExecutionContext(ISchema schema, Object root, Document document, Operation operation, Inputs inputs, Object userContext, CancellationToken cancellationToken, Metrics metrics)\r\n   at GraphQL.DocumentExecuter.<ExecuteAsync>d__12.MoveNext()\r\n   --- End of inner exception stack trace ---"
    }
  ]
}

I’ve tried everything I can think of but I’ve been stuck for several days. How do I get this to work?

-Erick

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 30 (13 by maintainers)

Most upvoted comments

Switch back to my previous deserialization with the JObject and it seems to be working. Thanks!

@JSanchezIO It all depends on your server setup. string seems to work fine with old ASP.NET MVC. JObject seems to work better with .NET Core. JObject should work in both places though, so I have started to just suggest that. You still use .ToInputs with JObject. If you use .ToInputs with a string it essentially just converts it to a JObject first.