mst-gql
mst-gql copied to clipboard
investigate genql
I just ran across https://genql.now.sh and am curious about looking into using it for mst-gql. If anyone wants to take a look before I have time, please feel free!
What's your idea about its use? Would you like to use it to replace some part of mst-gql (eg. the generator)?
my current though was when it comes to fragments, right now we're just using strings, but I would much rather use something like this with actual types. That being said, I haven't looked very deeply, so there might be more / nothing here :D
I just took a look at it and following this guide https://genql.now.sh/docs/usage/usage-with-other-clients it is quite easy to define a query using genql and then run it via mst-gql query:
Assuming you have a graphql schema with a countries query and a Country type you can do something like:
// genql
const { query, variables } = generateQueryOp({
countries: {
name: 1,
code: 1,
},
})
// mst-gql
const countryQuery = gqlStore.query<{countries: CountryModelType[]}>(
gql(query),
variables
)
The one thing I find useful about it is that genql generates static TS typings, whereas in mst-gql all types are inferred from the MST type definitions and in case you have a huge schema (Hasura) IntelliJ is very slow figuring out autocompletion as you use the generated queries from RootStoreBase. With generateQueryOp autocompletion is instant but in the mst-gql query you have to type the return value on your own and of course you have to generate schemas using genql as well and you practically double the code size (you need both msq-gql and genql generated schemas).