Closed johnridesabike closed 3 years ago
I just learned about the templateTagReturnType
config option, which seems to mostly satisfy what I’m trying to do. I still think it would be useful to be able to have a unique type per module, if that’s feasible.
Actually can you not pass the whole query to useStaticQuery
? Like:
useStaticQuery((module MyQuery))
or as a extension:
MyQuery.useStatic()
Actually, for your specific example, you can use the query inside of the passed module in the functor right?
module ExtendQuery: (M: GraphQLQuery) => {
// you can hide this in the interface
@bs.module("gatsby")
external useStaticQueryJs: string => M.Raw.t = "useStaticQuery"
let useStatic = () => {
useStaticQueryJs(GraphQLQuery.query)
}
}
That was one of my first thoughts too, but sadly it is not possible in Gatsby. The input to useStaticQuery
can’t be a variable (like a function argument). See https://www.gatsbyjs.com/docs/use-static-query/#known-limitations
Anyway, this suggestion is probably low-priority since templateTagReturnType
almost completely solves my use case.
Ok, I'll close it then. It shouldn't be too hard to implement, perhaps even an "opaque" value to templateTagReturnType
?
It would be useful if queries could be given an opaque type instead of
string
The motivation is that this would make adding type-safe extensions easier. For example:
You can’t implement an opaque
query
type in the functor and redefine the query because Gatsby requires query values to be static--they can’t get passed through different functions before use.