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

GraphQLProvider based on ISchema

Open nightroman opened this issue 4 years ago • 6 comments

Is it possible, in theory, to have GraphQLProvider based on ISchema instead of schema input as just text, file, or URL?

If yes, why is it not there? For no particular reason, or was it considered not practically useful, or something else?

I am thinking of some useful applications in scripting scenarios, for example:

  • A host exposes its data model as MySchema<MyRoot>.
  • A consumer (F# script) creates GraphQLProvider<MySchema<MyRoot>> and works with strongly checked / typed operations and results.

nightroman avatar Feb 09 '21 11:02 nightroman

It's currently not possible since Type Providers can't accept types as static input.

see: https://github.com/fsharp/fslang-suggestions/issues/212

Also, not sure this is desirable as clients would need to take a dependency on server related binaries. I guess it's possible we have some sort of interface that both the client and server model their schema based off of, but I'm not sure if that will really buy us much over our current mechanism.

Best Regards, John

jberzy avatar Feb 09 '21 18:02 jberzy

Also, not sure this is desirable as clients would need to take a dependency on server related binaries.

Like I mentioned, my primary potential scenario is F# scripting, for example using FSharp.Compiler.Service library.

That is, I have a host app or library which exposes its data model via FSharp.Data.GraphQL ISchema. All the "server related binaries" are there, together with this app or library. F# scripting does not mind to take dependency on them, there is nothing extra needed to install or download.

nightroman avatar Feb 09 '21 20:02 nightroman

I'm not sure if that will really buy us much over our current mechanism.

With our current mechanism, what steps do you recommend in my scenario? What should F# scripts do in order to invoke GraphQL query on a referenced library which defines and exposes ISchema and the executor? They can use the executor of course but the results are not strongly typed. That is why I think that engaging GraphQLProvider would be very useful for scripting (but not limited to).

nightroman avatar Feb 09 '21 20:02 nightroman

It's currently not possible since Type Providers can't accept types as static input.

But this of course answers and probably closes my question. Closing?

nightroman avatar Feb 09 '21 21:02 nightroman

@nightroman

In your scripting scenario, would the host application be able to initialize the executor and have the executor dump the graphql schema as a json file?

If that's the case, maybe the GraphQLProvider can just consume it after the host outputs the file the first time?

Thanks John

jberzy avatar Feb 11 '21 04:02 jberzy

@jberzy Yes, we probably can do that. May I ask how? (sorry, still learning and there is not much manuals or examples). Namely, how to dump JSON schema and how to engage the executor with GraphQLProvider? The provider is supposed to invoke queries by Run(ctx) with context based on some URL. In our scenario there is no URL or HTTP server as such.

nightroman avatar Feb 11 '21 07:02 nightroman

See Build project, Program.fs, UpdateIntrospectionFile target. Feel free to reopen if necessary

xperiandri avatar Nov 05 '23 23:11 xperiandri