Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JsonObjectTypeExtensions.cs #5649

Merged
merged 5 commits into from
Jan 20, 2023
Merged

Conversation

vickytr44
Copy link
Contributor

Root cause: When GetDateTimeOffset() is performed on null, we will get an error stating "The requested operation requires an element of type 'String', but the target element has type 'Null' ". This will happen when the value of DateTime field is null.

Code fix: The proposed change will ensure that the system returns null when DateTime field is null instead of throwing an error.

Root cause: When GetDateTimeOffset() is performed on null, we will get an error stating "The requested operation requires an element of type 'String', but the target element has type 'Null' ". This will happen when the value of DateTime field is null. 

Code fix: The proposed change will ensure that the system returns null when DateTime field is null instead of throwing an error.
@CLAassistant
Copy link

CLAassistant commented Jan 1, 2023

CLA assistant check
All committers have signed the CLA.

@michaelstaib
Copy link
Member

Can you provide a minimal test showing the issue you are referring to? I have the feeling that this does not really fix the the issue or rather applies some logic that overlays an issue here.

@michaelstaib
Copy link
Member

@vickytr44 do you want to advance this PR?

@vickytr44
Copy link
Contributor Author

Yes, I would like to move forward with the pull request. Let me also create a sample project where we can reproduce this issue.

@vickytr44
Copy link
Contributor Author

vickytr44 commented Jan 19, 2023

I have created a sample project to reproduce the issue. I've included the link for the project.
GraphQl_IntegratingRestService

Here Book type will get its Author details from a rest service and for one of the author the birthdate is null . When you try to query the author's details the query will throw an error.
Note: Here the DateTime is nullable.

Query:
{ bookById(id:4){ title id author{ id name birthdate } } }

Result:
{ "errors": [ { "message": "Unexpected Execution Error", "locations": [ { "line": 8, "column": 7 } ], "path": [ "bookById", "author", "birthdate" ], "extensions": { "message": "The requested operation requires an element of type 'String', but the target element has type 'Null'.", "stackTrace": " at System.Text.Json.JsonDocument.TryGetValue(Int32 index, DateTimeOffset& value)\r\n at HotChocolate.Types.JsonObjectTypeExtensions.<>c__DisplayClass2_0.<InferResolver>b__12(IPureResolverContext ctx)\r\n at HotChocolate.Execution.Processing.Tasks.ResolverTaskFactory.ResolveAndCompleteInline(OperationContext operationContext, MiddlewareContext resolverContext, ISelection selection, Path path, Int32 responseIndex, ObjectType parentType, Object parent, ObjectResult parentResult, List1 bufferedTasks)"
}
}
],
"data": {
"bookById": {
"title": "Pro WPF: Windows Presentation Foundation in .NET 3.0",
"id": 4,
"author": {
"id": 3,
"name": "Matthew MacDonald",
"birthdate": null
}
}
}
}
`

@michaelstaib michaelstaib merged commit b1b8445 into ChilliCream:main Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants