-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support TypedDocumentString via DocumentTypeDecoration in @apollo/client #390
Comments
@benasher44 thanks for bring this to our attention! I don't think any of us realized this was a new addition. We can certainly take a look and figure out what kind of compatibility there is.
Unfortunately we still need access to the underlying AST of the query because Apollo Client performs some underlying query transformations that require the AST (such as adding Thanks a bunch for the request! |
👍 even if deserializing the queries is still required for Apollo Client, it looks like it might still be a win for web bundling. Thanks for the consideration! |
@jerelmiller what would be the problem on clients (devs) doing something like this? export function useQuery<
TData = any,
TVariables extends OperationVariables = OperationVariables,
>(
query: TypedDocumentString<TData, TVariables>,
options?: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>
) {
return useApolloQuery<TData, TVariables>(gql(document.toString()), options);
} the re-parsing on every call for the hook? edit: think that if this ^ is the problem we can prob cache by instance (need to confirm if new instances of the class will actually be different entries on map) const queryMap = new Map()
// ...useQuery....
const query = (queryMap[document] || queryMap[document] = gql(document.toString())) edit 2: |
@Grohden looking into No need to create your own cache as Apologies we haven't had time to evaluate this yet. If we adopt this change, it will likely cascade throughout the entire codebase (there are a lot of places that accept |
@jerelmiller oh, nice to know! I was already exploring using weak maps for the cache 😅 And that has been working for us here for like 2 months, I just didn't bother to check the cache part. So while we don't get the support in apollo I'll be sticking with that solution (its just a pain to import types but I can live with that) |
Haha no worries! I've been using Apollo Client for years before I was a maintainer and I only recently discovered this 😆. Seems we have a bit of education to do!
I definitely hear you there. At least Thanks for the questions! |
Chiming in with a little bit of a curveball here: Right now, the "document parsing" part of If we made a choice like this, it would mean that We might be able to find a way around that (e.g. we could accept a Just as a warning: we will evaluate this at some point, but there is a chance that we find that it doesn't integrate nicely and actually complicates DX more than it helps. |
Hi there! As of v4 of graphql-code-generator, there is now a
string
alternative to using TypedDocumentNode, which still brings along the type.I think
@apollo/client
could support this by accepting DocumentTypeDecoration as its type in react hooks, and then it would get the benefit of not having to convert the query to a string for the network request (while still having nice types)The text was updated successfully, but these errors were encountered: