question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Unexpected execution error" on Custom objects

See original GitHub issue

Describe the bug I’m trying to setup a very simple test console application, where my Query object, have a User field, which return a User type object.

To Reproduce In a basic .Net Core console application, use the code below

class Program
{
    static void Main(string[] args)
    {
        var schema = Schema.Create(c =>
        {
            c.RegisterType<ObjectType<Query>>();
            c.RegisterType<ObjectType<User>>();
        });

        Console.WriteLine(schema.Execute("query UserQuery { user() }"));

        Console.ReadLine();
    }
}

public class Query
{
    public User User() => new User { Name = "Username" };
}

public class User
{
    public string Name { get; set; }
}

On run, this will prompt:

 {
   "errors": [
     {
       "Message": "Unexpected execution error."
     }
   ]
 }

Expected behavior

 {
   "data": {
     "user": {
        "name": "Username"
      }
   }
 }

Or at least a comprehensive error, explaining what is going wrong.

Desktop:

  • Windows 10
  • HotChocolate 0.4.0
  • .Net Core 2.1

Additional context If I use this code, it works:

class Program
{
    static void Main(string[] args)
    {
        var schema = Schema.Create(c =>
        {
            c.RegisterType<ObjectType<Query>>();
            c.RegisterType<ObjectType<User>>();
        });

        Console.WriteLine(schema.Execute("query UserQuery { user() }"));

        Console.ReadLine();
    }
}

public class Query
{
    //public User User() => new User { Name = "Username" };
    public string User() => "Username";
}

public class User
{
    public string Name { get; set; }
}

Output:

{
  "data": {
    "user": "Username"
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
glucacicommented, Aug 8, 2018

Hi @jbuiss0n ,

You should register your query with:

c.RegisterQueryType<Query>();

You can use your User object also but the query should look like this:

schema.Execute("query UserQuery { user { name } }")
// or
schema.Execute("{ user { name } }")

On your second example only with a string and not a User object, you can simplify your query:

schema.Execute("query UserQuery { user }")
// or
schema.Execute("{ user }")

I don’t know if it’s possible and how, to request for the whole user, without setting any property.

It’s not possible, by design GraphQL is giving you back only what you request.

0reactions
jbuiss0ncommented, Aug 9, 2018

Thanks for the information! I’m looking forward to try this then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Unexpected execution error" on Custom objects · Issue #211
I'm trying to setup a very simple test console application, where my Query object, have a User field, which return a User type...
Read more >
c# - How can I get more error details or logging, when an ...
I'm building out a simple HotChocolate GraphQl server and HotChocolate throws an Unexpected Execution Error , but doesn't expose any ...
Read more >
Error Filter - Hot Chocolate - ChilliCream GraphQL Platform
An error filter has to be registered with the execution builder or with your dependency injection. C#. IQueryExecuter executer = schema ...
Read more >
Error handling - Apollo GraphQL Docs
When Apollo Server formats an error in a response, it sets the code extension to this value if no other code is set....
Read more >
Top GraphQL Errors and How to fix them
Technically this error came out of using a field which doesn't exist (either due to Auth or schema not really having the field)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found