FSharp.Data.GraphQL icon indicating copy to clipboard operation
FSharp.Data.GraphQL copied to clipboard

Schema file not found when using the type provider from a separate project

Open Yakimych opened this issue 5 years ago • 0 comments

Description

I am trying to create a shared reusable library for accessing a GraphQL API via the F# Type Provider. Everything works fine if the Provider is defined in the same project that uses it (WebApi), but as soon as I move the provider and schema.json file to a ClassLib, I get an error regarding the schema not being found any more (see Actual Behaviour section).

Note: The class library compiles, the error appears in the project that references this class library, since the schema is not in the root of this project, but in the root of the class library itself.

Repro steps

  1. I start by following the basic tutorial I end up with the following code in the GraphCoolProvider.fs file:
module WebApp.GraphCool

open FSharp.Data.GraphQL

type MyProvider = GraphQLProvider<"schema.json">

let allPersonsOperation =
    MyProvider.Operation<"""query q {
      allPersons {
        name
        id
      }
    }""">()
  1. I use it from my controller as follows:
namespace WebApp.Controllers

open Microsoft.AspNetCore.Mvc
open WebApp.GraphCool
open FSharp.Data.GraphQL

[<ApiController>]
[<Route("[controller]")>]
type MyController() =
    inherit ControllerBase()

    let runtimeContext =
        { ServerUrl = "https://api.graph.cool/simple/v1/cjdgba1jw4ggk0185ig4bhpsn"
          HttpHeaders = [] }

    [<HttpGet("persons")>]
    member __.GetPersons(): string [] =
        let result = allPersonsOperation.Run(runtimeContext)

        match (result.Data, result.Errors) with
        | Some data, [||] -> data.AllPersons |> Array.map (fun p -> p.Name)
        | _ -> [||]
  1. Everything works fine at this point (the master branch: https://github.com/Yakimych/fsharp-graphql-test), but as soon as I move the GraphCoolProvider.fs to a class library, I get the error. See the other-project branch: https://github.com/Yakimych/fsharp-graphql-test/tree/other-project

Expected behavior

No error, everything works as when the type provider was defined in the same project as it was used from

Actual behavior

Getting the following error:

error FS3033: The type provider 'FSharp.Data.GraphQL.Client.GraphQLTypeProvider'
reported an error: Could not determine location of introspection.
The introspection should be a valid GraphQL server URL,
or a introspection JSON file on the path of the project or script.

Known workarounds

Include the schema file into every project the type provider is used from.

Related information

  • Operating system MacOS, Windows
  • Branch dev
  • .NET Runtime, CoreCLR or Mono Version .NET Core 3.1

Yakimych avatar May 04 '20 09:05 Yakimych