"Unexpected execution error" on Custom objects
See original GitHub issueDescribe 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:
- Created 5 years ago
- Comments:9 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @jbuiss0n ,
You should register your query with:
You can use your
User
object also but the query should look like this:On your second example only with a string and not a
User
object, you can simplify your query:It’s not possible, by design GraphQL is giving you back only what you request.
Thanks for the information! I’m looking forward to try this then.