Closed bkniffler closed 2 years ago
Yes, I have thought about this problem, but there are so many frameworks that users may adopt, and it is impossible to exhaust them one by one. Therefore, the current design is like this
In the NodeJS file of the code generator, 3 generators are supported, user can choose one of them
ApolloGenerator: Generates code with react hook & apollo. User need to import'graphql' and'@apollo/client'
AsyncGenerator: Generates async methods that only with network fetch. No local cache, no state manangement, no react dependency. User need to import 'graphql-request'. Please see async demo to know more
Generator: Only generates types for object, interface, union and input, ignore queris and mutations and they must be implemented by user.
In fact, there is another way that users extend the code generator themselves and create a new derived class from Generator (in fact, both ApolloGenerator and AsyncGenerator inherit from Generator), but this is too difficult for users
Fwiw: I have a use case where I would like to use Apollo in a NextJS React project, but I don't want to use the hooks provided.
I would like to use the Apollo Client directly outside of the React element tree, inside of NextJS's getStaticPaths.
I'm not sure if this is possible with the current exports from the Apollo file.
Currently, the generated code is tightly coupled with react. Would be amazing to also use outside of react by maybe outsourcing the react hooks and specific wrappers to another library. Would make it easier to use different clients under the hood also like urql.
If decoupled, it could look something like: