fsprojects / FSharp.TypeProviders.SDK

The SDK for creating F# type providers
https://fsprojects.github.io/FSharp.TypeProviders.SDK/
MIT License
298 stars 94 forks source link

Knowing which provided types are in use by design time code #308

Closed ivelten closed 3 years ago

ivelten commented 5 years ago

Our company is working on a complete redesign of a GraphQL type provider. One of the features we would like to develop is to provide a meaningful type name for any GraphQL operation.

For example, say that we have this GraphQL operation:

query HeroName {
  hero(id: "1000") {
    name
  }
}

And in our actual design, this operation would be generated by a code similar to this one:

type MyProvider = GraphQLProvider<"http://localhost:8084">

let operation = MyProvider.Operation<"""query HeroName {
  hero(id: "1000") {
    name
  }
}""">()

At the moment, the Operation method generates a provided type with a name following a pattern "Operation" + [MD5 hash of query string]. We would like to allow the user to pass a custom type name, or generate one based on the kind and name of the operation (in this case, would be something like HeroNameQuery). If neither of those can be achieved, then we fallback to our current naming strategy. But by doing that, we would also like to avoid collisions if the user defines two operations using the same name. We could easily store all the provided type names in a hashtable or something similar, but the question is: how we could know the time to remove a type from it? Is there any way to know if the user removed a piece of code which declares an provided type at design time, and discard this type to allow the user to define another with the same name?

I am not sure if this sounds clear, but what I would like to have is a way to know if a type is invalidated (not used anymore by the design time code because its definition was removed from the code itself). On the other way, I want to keep track of the ones that are still in use, so I can prevent the user to define two provided types with the same type name. I would like to provide a design time error saying something like "The provided type name %s is in use by the design time code, please choose another name.".

Is there any way to achieve this using erased types?

dsyme commented 3 years ago

@ivelten Closing out this old discussion