Azure/data-api-builder

[Bug]: Int fields are stored as string in cosmosdb

Closed this issue · 4 comments

What happened?

when you have a graphql schema that contains an Int field for example:

type User {
  name: string
  age: Int
}

and you update the age field using DAB then i get the following error

"the requested operation requires an element of type 'Number', but the target element has type 'String'." and when i look up the document in cosmos the int is stored as a string. i even tried passing in a hardcoded value to make sure the value passed in is a number.

Version

0.11.130

What database are you using?

CosmosDB NoSQL

What hosting model are you using?

Container Apps

Which API approach are you accessing DAB through?

GraphQL

Relevant log output

Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/1.1 POST http://127.0.0.1:5000/graphql application/json 891 - 200 - application/json;+charset=utf-8 3.8640ms
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/1.1 POST http://127.0.0.1:5000/graphql application/json 1334
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[4]
      CORS policy execution successful.
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
      Executing endpoint 'Hot Chocolate GraphQL Pipeline'
fail: Azure.DataApiBuilder.Service.Startup[0]
      A GraphQL request execution error occurred.
      System.InvalidOperationException: The requested operation requires an element of type 'Number', but the target element has type 'String'.
         at System.Text.Json.JsonDocument.TryGetValue(Int32 index, Int32& value)
         at System.Text.Json.JsonElement.GetInt32()
         at Azure.DataApiBuilder.Service.Services.ExecutionHelper.ExecuteLeafField(IPureResolverContext context) in /_/src/Core/Services/ExecutionHelper.cs:line 176     
         at HotChocolate.Execution.Processing.Tasks.ResolverTaskFactory.<ResolveAndCompleteInline>g__TryExecute|4_0(Object& result, <>c__DisplayClass4_0& )
fail: Azure.DataApiBuilder.Service.Startup[0]
      A GraphQL request execution error occurred.
      System.InvalidOperationException: The requested operation requires an element of type 'Number', but the target element has type 'String'.
         at System.Text.Json.JsonDocument.TryGetValue(Int32 index, Int32& value)
         at System.Text.Json.JsonElement.GetInt32()
         at Azure.DataApiBuilder.Service.Services.ExecutionHelper.ExecuteLeafField(IPureResolverContext context) in /_/src/Core/Services/ExecutionHelper.cs:line 176     
         at HotChocolate.Execution.Processing.Tasks.ResolverTaskFactory.<ResolveAndCompleteInline>g__TryExecute|4_0(Object& result, <>c__DisplayClass4_0& )

Code of Conduct

  • I agree to follow this project's Code of Conduct

@dgcaron, can you provide the GraphQL mutation you're sending to DAB?

It is expected error, data should be in the same format as what you define in GraphQL schema. Here data type is integer in Schema but data is actually in string format.

Did you create this data from older version of DAB? because we had a bug in older version, where it would convert the data into string #1959

i understand that the error is expected as the data is stored as string. i'll get an example of what i posted. i am experiencing this with the 0.11.132 version that is running as a container in containerapps

It should be working, if you an item created with same version of DAB. Since DAB is GA now, I would recommend you to use latest GA DAB version i.e. https://www.nuget.org/packages/Microsoft.DataApiBuilder/1.1.7