What is the correct way to access related items using the F # Freebase Type Provider

I have the following piece of code that aims to list the exchange websites listed in Freebase:

#if INTERACTIVE
#r @"C:\Users\kit\Documents\Visual Studio 11\Projects\Demo\packages\FSharpx.TypeProviders.1.7.4\lib\40\FSharpx.TypeProviders.dll"
#r @"C:\Users\kit\Documents\Visual Studio 11\Projects\Demo\packages\FSharpx.TypeProviders.Freebase.1.7.4\lib\40\FSharpx.TypeProviders.Freebase.dll"
#r @"C:\Users\kit\Documents\Visual Studio 11\Projects\Demo\packages\FSharpx.TypeProviders.Freebase.1.7.4\lib\40\FSharpx.TypeProviders.Freebase.DesignTime.dll"
#endif 

let GetExchanges() =
    let dc = FreebaseData.GetDataContext()
    dc.DataContext.SendingRequest.Add(fun e -> printfn "url: %s" e.RequestUri.AbsoluteUri)

    dc.``Products and Services``.Business.``Stock exchanges``
    |> Seq.truncate 10
    |> Seq.iter (fun exchange -> printfn "Exchange: %s" exchange.Name
                                 exchange.``Official website``
                                 |> Seq.iter (fun site -> printfn "%s" site.Name))

      

Without the last two lines (i.e. just listing Exchange names), the code works fine. With these lines, I am getting 400 (bad query).

The URL generated by this line is:

https://www.googleapis.com/freebase/v1/mqlread?query=%5B%7B%22/type/object/id%22:null,%20%22/type/object/name%22:null% 20,% 20% 22optional% 22: true,% 20% 22 / type / object / type% 22:% 22 / type / uri% 22,% 20% 22! / Common / topic / official_website% 22:% 20% 5B% 7B% 22 / type / object / id% 22:% 22 / en / amex% 22,% 22 / type / object / type% 22:% 22 / common / topic% 22% 20,% 20% 22limit% 22:% 20500% 7D% 5D% 7D% 5D & cursor

... and if I go to this I get this from Freebase:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "badRequest",
    "message": "Can't reverse /common/topic/official_website as it expects /type/uri, not an object"
   }
  ],
  "code": 400,
  "message": "Can't reverse /common/topic/official_website as it expects /type/uri, not an object"
 }
}

      

Am I using the correct approach for accessing related objects? If so, is it a bug in the type provider? I am getting similar errors when accessing other related objects.

+3


source to share


2 answers


This was a bug in the type provider and has since been fixed: https://github.com/fsharp/FSharp.Data/issues/68



+4


source


Like the error, you cannot override a property that is a primitive value property. You need to turn the query inside out so that it looks like this:

[{
  "/type/object/id": "/en/amex",
  "/common/topic/official_website": [{
    "value":    null,
    "optional": true
  }]
}]​

      



The library should have some knowledge of primitive values, so maybe it's as simple as adding / type / uri to any list that contains / type / text, / type / rawstring, etc.

+4


source







All Articles