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

Client type provider fails to compile using local json schema, .NET Core 3.0

Open aggieben opened this issue 5 years ago • 7 comments

Description

I'm trying to use the type provider in a .NET Core 3.0 app and experience the following compiler error:

error FS3021: Unexpected exception from provided type 'FSharp.Data.GraphQL.GraphQLProvider,introspection="shopify_schema.json"' member 'GetMethods': The type provider 'FSharp.Data.GraphQL.Client.GraphQLTypeProvider' reported an error: Object reference not set to an instance of an object.

image

Snippet of affected code:

module Client =
    type private ShopifyProvider = GraphQLProvider<"shopify_schema.json">
    let private getRuntimeContext (shop:string) (token:string) =
        { ServerUrl = sprintf "https://%s.myshopify.com/admin/api/2019-10/graphq.json" shop
          HttpHeaders = [("X-Shopify-Access-Token", token)] }

    let createMetafields (sl:ServiceLocator) shop token =
        let logger = sl.GetLogger (_moduleType.FullName)
        let http = sl.GetService<IHttpClientFactory>().CreateClient()
        let context = getRuntimeContext shop token

        ShopifyProvider.Operation<"""mutation product {

        }""">()

Repro steps

Please provide the steps required to reproduce the problem

  1. Used apollo to download schema in json format from Shopify's Admin GraphQL API

  2. Add FSharp.Data.GraphQL.Client nupkg to paket.dependencies and paket.references for this project.

  3. Use type provider as indicated in the examples and in the README

Expected behavior

Type provider compiles, and compiled types interact correctly with autocomplete/intellisense.

Actual behavior

Compiler fails.

Known workarounds

Please provide a description of any known workarounds.

Related information

  • Operating system: Windows 10 1903
  • Branch: unsure
  • .NET Runtime, CoreCLR or Mono Version: .NET Core 3.0

aggieben avatar Oct 15 '19 22:10 aggieben

@aggieben Do you mind sending me the schema? Also, can you send me the actual mutation you're submitting (or one that reproduces the issue)?

Thanks, John

johnberzy-bazinga avatar Oct 16 '19 22:10 johnberzy-bazinga

Sure, I don't mind. This is what I generated using apollo against the Shopify API (documented here: https://help.shopify.com/en/api/graphql-admin-api). shopify_schema.zip

The mutation above is just cruft, really. The issue manifests before I even wrote those lines. This line:

type private ShopifyProvider = GraphQLProvider<"shopify_schema.json">

failed all by itself.

aggieben avatar Oct 17 '19 19:10 aggieben

I think this must have been caused by the particular json schema that was generated by apollo. I generated schema with a different tool (graphql schema with the graphql cli) and the type provider seems to be happier with that. That's not to say there isn't still an issue here, but at least we can know it's not completely broken.

For reference, the schema that seems to be working: shopify_admin.json.zip

aggieben avatar Oct 26 '19 03:10 aggieben

Another bit: I generated a json schema using the introspection query from the README, and the provider seems happy enough with that. I don't know the differences between the produced schemas.

aggieben avatar Oct 29 '19 02:10 aggieben

@aggieben It may be that the introspection query in Apollo has changed (or maybe you're using an old version of apollo server?). In the near future we are hoping to also support the SDL format. We're going to need to update the parser before we can do that.

johnberzy-bazinga avatar Oct 29 '19 05:10 johnberzy-bazinga

I have this same problem using graphql schema form github.

joshuapassos avatar Dec 10 '19 23:12 joshuapassos

Try with the latest preview packages from the GitHub feed

xperiandri avatar Nov 05 '23 23:11 xperiandri

It should work in 2.0.0, try again, please

xperiandri avatar Apr 05 '24 04:04 xperiandri