Apollo client usequery github. You switched accounts on another tab or window.
Apollo client usequery github ts within apollo-client. match support partial matching by supplying a default tag of _. As long as the Issue Description I have a strange issue where two successive calls to fetchMore will cause a bug only if the query was changed once before. We use the Apollo client useQuery hook for fetching data all over our app. 6 (also was able to reproduce with 3. 53 but it looks like it has another issue. If the client is hydrating after SSR, it attempts a readQuery to synchronously check the cache for values You signed in with another tab or window. export function useQuery<TResult = any, TVariables extends OperationVariables = OperationVariables> (document: DocumentParameter<TResult, TVariables> // Apollo Client. On the first render, the query is still in progress, so you will have { loading = true, data = undefined }. In fact, I'm willing to bet you'll have a better time with those hooks than useQuery 🙂. 6. client: ApolloClient: An ApolloClient instance. How to reproduce the issue: I cloned the demo codesandbox from the documentation and added the minimum reproducible code. How to reproduce the issue: We have an existing app that we are migrating from Apollo Client 2 to 3. I think we can do any one of the below to close this issue: Remove the re execution of the query when the options passed changes in the case of useLazyQuery. After disabling React. 67. @MaxwellGover I can't seem to re-create this issue using a fork of the hooks example app. I think it has to do with the cache, but there is nothing mentioned on I'm experiencing a similar issue with 3. 8. If I clicked on button,which open confirm window,then I call useLazyQuery function called load({variables:{id}}), query runs and give me a Expected result: The query consults the type policy, and returns undefined. But onCompleted is called on every re-render of my component This is a quick demo to show how Apollo Client and GraphQL work together, also how we can use apollo-link-state for local state management, in such a way that Redux (and other state management libraries) can be removed in favour of using Apollo Client as a single source of truth for everything. Since I'm using SSG, using the with-apollo I just ran into this upgrading from apollo-client/v2 to @apollo/client@3. Their focus is different now. Skip to content. You signed out in another tab or window. 126) before the React application finishes You signed in with another tab or window. Is that correct? Regardless, you'll want to make sure you're using @apollo/client in both places. From what I understand (according to the name), I guessed that useQuery would do just that (a bit like useContext or Intended outcome: When I write directly to my InMemoryCache, I want the updated data to be used the next time my React component renders. There's a server and client folder. This article demonstrates how to fetch GraphQL data in React with the useQuery hook and attach the Fetching data in a simple, predictable way is one of the core features of Apollo Client. 9. . Reverting to 3. * * > Refer to the Apollo Client is a fully-featured caching GraphQL client with integrations for React, Use Apollo Client as React hooks. e. To address this problem (which is not a bug in Apollo Client), either ensure all objects of type NestedObject have an ID or a custom merge function, or define a custom merge function for the RootObject. 0-rc-4. You can find the code used in this post on GitHub. It does trigger the onCompleted callback when query finishes. tsx which is rendered client side and used to wrap the children in the layout. The resulting object is a POJO. Any RemoteData states no supplied subsequent to the _ will fallback to the function supplied at _. ; Pass false directly, and it correctly triggers an HTTP request. On top, at the time of writing Apollo client does not export Common JS files needed for a SvelteKit build, but there is a workaround. Not being able to reliably subscribe/listen for (refetches/polling) responses via onCompleted without also setting notifyOnNetworkStatusChange: true has lead to our codebase having to wrap the returned query. Previously it's picking the cjs bundle that nextjs cannot analyse the imports properly, by picking up ESM bundle now we can analyze which is not expected to be used on RSC server side. context options. I don't want to "decorate" every useQuery with a usePrevious or similar or replace useQuery with our own function that includes usePrevious. apollo-lcient conatins client components imports which shoudn't be bundled on RSC server layer side as those hooks are only available in SSR and client browser. I'm using "@apollo/client": "^3. @benjamn Thanks, can confirm that the @apollo/client@3. You signed in with another tab or window. In my case the 1st call should not skip but later ones should. If all data is available locally, useQuery returns that data and doesn't query your GraphQL server. Actual outcome: refetch triggers the new request but didn't update the loading state variable. Before the refactor, changes to query and/or variables would result in passing the whole watchQueryOptions to reobserve, thereby updating ObservableQuery with This issue is for tracking progress on the new useSuspenseQuery hook. store. Now the problem arises when I need to have an Authorization: 'Bearer <jwt token here> header set with my Apollo client so my requests to my backend are authorized. Using a suspense query will differ from useQuery in the following ways:. Actual outcome: useQuery triggers on second render. Use useQuery from @apollo/client@^3. eg: @benjamn @hwillson. refetch, its hard to work with it, but still apollo project is a nice project. 0 and React 18. AWS AppSync packages are provided by a third party, however. After that, disableNetworkFetches switches over to false. ; Add a new sentence in the doc When I use useQuery with fetchPolicy: 'cache-and-network' for loading data from the server it is doing infinity loop like this: If I remove fetchPolicy: 'cache-and-network' it works correctly. - Rewrite big parts of useQuery and useLazyQuery to be more compliant with the Rules of React and React Compiler #11936 1b23337 Thanks @jerelmiller! - Add the ability to specify a name for the client instance for use with Apollo Client Devtools. skip ? {} : opts. I am following the apollo client docs for typescript and i see a parameter that appears the root level in Apollo dev tools but it does not get passed to my query. 5), the data is set to undefined while loading the first query (and that makes sense), but whenever I update the query, like updating its variables, the data remains unchanged while loading until it sets to the new value when the query finishes. I've done a lot of digging on fetchPolicy / skip / variables-changed on recent betas (3. The new options. ; The undefined result mean the query executes the resolver. This is a wrapper around useQuery that returns loading as false if you have a cache. We either don't need to show a loading UI at all, or only care about showing a loading UI while t @karansinghgit Ahh, I think the problem is that you're calling useQuery before you've created your <ApolloProvider client={client}/> component, so useQuery can't find any ApolloProvider above it in the Additional information. However, I have a big problem when I try to understand the need to use server components having already the useSuspenseQuery, which uses the ApolloNextProvider and handle data in an amazing way. How to reproduce the Notable changes in behavior from useQuery. But the end result is that the loading state is turned false. 0-rc. The matcher attributes the RemoteData value to a case and applies the matched function. returnPartialData options. @apollo/client: ^3. This is especially true with mutations (since those should run only on the client based on user interaction). How you want your component to interact with the Apollo cache. 4, StrictMode is not set). As an example, import { ApolloClient } from '@apollo/client/core'. Both lazy and non-lazy queries are hanging. In the component which uses the useQuery I also retrieved the client with useApolloClient() and when I use the readQuery() with the same query this contains the Contribute to jimmyn/apollo-client development by creating an account on GitHub. They have their federation to evolve. The Apollo client library includes a MockedProvider component which allows Cache data may be lost when replacing the nestedObject field of a RootObject object. I was hoping that I could use a refetch (returned from useQuery) to pull only from the cache, but from debugging and looking throug With the refactor for useSuspenseQuery in #10672, we lost the ability to update the watchQueryOptions on the ObservableQuery when changed between renders (i. The issue is especially bad because skip only intermittently fails: it appears it correctly skips the first useQuery but fails for later queries (the second time the query is @davismariotti Just to make sure I understand your expectations, would it be fair to say you never want data to be the (unrelated) previous data, but data could be something other than undefined when variables change? For example, if the new variables produce a cache hit, you'd be ok with getting a loading: true result with data from the cache?. query and client. 5672. 0, because in version 3. The core Apollo Client API itself is not opinionated about how to handle Websockets connections, so I recommend looking at the aws This is happening for me in React Native with @apollo/client >= 3. 3 fixed the issue. I was having the same issue, I believe the problemas was that when importing import { gql, useQuery } from "@apollo/client" you are importing a . This behavior causes infinite loops when the mutation call depends on the query Hello, I am working on a NextJs application and I have an issue while rendering the result to send to the client. We noticed an issue that is affecting our upgrade. Due to circumstances outside of our control we are unable to stray away from using ssrForceFetchDelay. When we end up with a lot of useQuery hooks on the page, we've noticed significant performance issues trying to unmount the components on navigation. Useful for setting headers from props or sending information to the request function of Apollo Boost. * * When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, and `data` properties you can use to render your UI. 0 it works correctly. Now the loading should work as you expect, your UI will not show a loading Reliable delivery of loading results is one of the core benefits that Apollo Client strives to provide, expecially since handling loading states tends to be such an annoying, error-prone task in hand-written state management code, and Apollo Client is all about keeping hand-written state management code to a minimum. Oh and the refetch function actually works :) P. However, after updating to @apollo/client v3 (or Intended outcome: I have a query which might cause the server to return a 401 status, with additional GraphQL errors in the body. In the docs, it says: “Client-side schema. This seems undesirable because the variables However, my issue was caused because I'm using apollo-client on the server, to query my Hasura db. The only source code in Apollo Client that uses . Something useful I discovered while debugging: if you install the Apollo Client Devtools extension on chrome, select the failing query, click "run in GraphiQL", click "Load from cache", and then run the query, you will get a Intended outcome: In code like this: useQuery(QUERY_FOR_POLL, { variables, pollInterval: 10000, // 10s skip, }); Polling should start when skip is set to false. I tried to use userLazyQuery, I get to pass different variables to it every time I manually call to query. On page load, useQuery will be stuck on loading: true. Now, when we were changing the sub field So I've been trying to use the next-iron-session example to save a JWT securely in my app, so far it works fine, I can see in my cookies the encrypted JWT. The network request completes successfully, however the hook does not reliably update – occasionally (maybe 50% of the time) it stalls out and remains in a loading state. 0+) and it looks like there's some scenarios where skip is not honoured when variables change. The issue in my case seems to be when I add fetchPolicy: 'network-only' to it. 4 and found this happening in any existing components that use refetch, downgrading back to 3. Notice how much less code you have to use to get this to work, simply because useQuery is reactive to its inputs. Actual outcome: The singular useQuery is never supplied any data. Both packages can be used together, if you want to try out using hooks and retain Query, Mutation, Subscription, etc. How to reproduce the issue: Add any query. One of the advantages of this API is that it feels simpler. Contribute to vuejs/apollo development by creating an account on GitHub. I switch to new version of Apollo client. Actual outcome: When the variable of a query changes, and the result for the new variable value is cached (and used, according to the fetchPolicy), there is an iteration in which data from useQuery is incorrect. I tried several hacks and read many post without finding an answer so far. 👍 8 prabhuignoto, kkak10, marianocodes, alobato, antsav, david29832, khangtu22, and bvsbharat reacted with thumbs up emoji 👀 3 SyedAsimAliSE, kkak10, and Cannot find module '@apollo/client' or its corresponding type declarations. 2, react-native@0. I confirmed this with both the provided example code in this issue as well as an actual app where I first noticed this problem. query inside Server Components for data fetching, which makes a lot of sense, but there are cases where people might mix and match Server Components and Client Components. ; Log loading. Using useQuery for asynchronous logic (user events etc. You can access the client object through render props via the ApolloProvider or component props the withApollo higher order function. This behaviour is same for useLazyQuery and useQuery. notifyOnNetworkStatusChange is true; We have a ComponentB that has a useQuery hook executing a query query BooksForList_B(listid) { Given the nature of useQuery, I expect it should trigger immediately when variables change. I can see that the cache is populated properly on the server-side and hydrated on the client-side (I run extract I've tried change the version of @apollo/client to older one like 3. For these goals useQuery can be rewritten by useLazyQuery. I'm not really sure if its an intended behavior or a bug so I'm posting this as a question. Here you have chance to render a spinner to illustrate that data is loading. Contribute to trojanowski/react-apollo-hooks development by creating an account on GitHub. StrictMode works fine. 9, which has been released last week - see this blog post. Generally, when using Apollo Client on the server, you As explained over at #11894 (comment) by @jerelmiller, Apollo Client seems to rely on inactive queries to be removed from queryManager. We were using fetchPolicy: 'cache-and-network' and the useQuery was fired only if the component is mounted on the 2. This is an issue because I would like to show a loading indicator to the end By default, the useQuery hook checks the Apollo Client cache to see if all the data you requested is already available locally. Because suspense now handles the loading state for us, we no longer need a loading boolean returned Ok had a discussion with the team about this and we agree that we should provide a way to do this. One idea was to allow useApolloClient (the hook we use under the hood that validates client exists) to accept skipToken as its argument and skip the validation. x. HOCs from react-apollo without having to rewrite existing components throughout your app. I I am on @apollo/react-hooks v3. How to reproduce the issue: I think it is something wrong after version 3. when the breed variable changes, it should set loading = true and return the past data until it resolves. Reproduction. const { resolveClient } = useApolloClient() function getClient Intended outcome: useQuery hook that is polling with a fetchPolicy: no-cache should not update the cache. 7. Hi, I have react-table working with apollo-client when react-table is fetching all the data via GraphQL endpoint and it's working great. I should be able to see the following console logs after clicking the button. ; The data variable in the component will equal { organization: null } once the query is resolved. writeQuery will cause an infinite loop of As per this line, the query will be executed again if any of the options passed to the useLazyQuery hook changes. You're using Apollo Client useQuery for fetchPolicy 'cache-and-network' that checks the cache before refetching in the background, but you still always get a loading spinner showing until the network query returns. I'm having a similar issue with useQuery in React Native. from @apollo/react-hooks v3. Issue Description I am having issues grabbing data from my endpoint when I use apollo/client inside an expo application. "@apollo/client": This seems pretty straight forward in the apollo client documentation but i cant figure out how to pass a parameter using usequery. ) as we can see not a good idea. getObservableQueries() gets passed an explicit list by queryManager. I downloaded code and I am r Saved searches Use saved searches to filter your results more quickly Drop-in replacements for @apollo/client's useQuery, useMutation and useSubscription hooks with reduced overhead and additional functionality. variables options. Actual outcome: When I write directly to my InMemoryCache, there is a short time period in which my React component uses old data. Looks like the issue author, @felixchan, found a fix for their specific case, so I'm going to close this issue out. So sorry to hear about the regression! FWIW we spent a lot of time iterating on the new suspense hooks with and without inference so I'd encourage you to give them a try (here are the type tests to give you an idea). I had to resort to wrapping useQuery with variables: opts. I guess this is related somehow. This could be considered a breaking change, but it's also a regression from Apollo Client 2. Since updating from apollo client 2 to @apollo/client 3 (3. When your component renders, useQuery returns an object from Apollo Client that contains loading, error, and data properties you can use to Shared context between your component and your network interface (Apollo Link). High level: In our app a list has many books; We have a ComponentA that has a useQuery hook executing a query query BooksForList_A(listid) { books { id status } }. The initial load is fine but any updates to data in that query using cache. nestedObject field, so InMemoryCache can safely merge these objects: I think our recommendation would be to use await client. All that said, on the client it should make a request and then eventually come back with a result. There seems to be an optimization in place to prevent redundant re-renders when useQuery produces the same response, but I believe that same code path is inadvertently preventing a re-render when that hook's refetch passes a new set of variables to execute a new query. 4. On the flip-side, this one feels a bit Issue Writeup #10540. I want to avoid that if possible. Uses Apollo's watchQuery, for fetching from the network and watching the local cache for changes. Work in progress can be found on this branch Options options. Actual outcome: when the breed variable changes, it sets loading = true and returns undefined for data until it resolves. refetch() function (and any other functions that could trigger a new request) with Makes sense that apollo is not aware of aborterRef. A common use case for this is combining the functions for Initialized and Pending into one It's a major improvement for Apollo to support this, and we are now going to stick with Apollo until these experimental hooks are released so that we can utilize them before making a decision. Whilst using the impressive @apollo/client library, I ran into issues while trying to unit test components which used the GraphQL Query and Mutation components. json", uses @apollo/client. Is there a hack to get Apollo Client to work with SvelteKit? # At the time of writing, the latest version of Apollo Client is 3. Refreshing the page will then let useQuery resolve correctly. ; Pass a variable with a true value, and it correctly skips. 6, and the problem remains, maybe I did not understand the documentation, or something broken after upgrade to React 17? All reactions Don't waste your time on Apollo. The problem doesn't exist with version 3. In this repro, I set up 2000 useQuery hooks using the same query, resulting in a full minute's wait on my device (using Chromium 113. Everything works as expected. Glad to hear that you're looking into this @alessbell!. Hi Prior to v3, when I use useQuery (i. Is there a way to not get the first undefined on initial render? Similar to ApolloProvider from react-apollo. tsx as stated in their docs, but since i'm adding the apollo state to the app in my useApollo() I have a query like this, const { data, error, refetch } = useQuery(QUERY, { fetchPolicy: "network-only", nextFetchPolicy: "network-only" }) When I call refetch and if the API returns an error, bot Intended outcome: I would expect Data and Loading to reflect the completed nature of the query Actual outcome: Immediately following onCompleted Data is still null and Loading is still true, I am guessing it has to do with async state up We are running into a similar issue. @hwillson I tried to create a small program in which the problem reproduces, this was without success, the small program works perfectly. Workaround: Manually updating the cache like this And what is the strangest thing is that to use useQuery for goals for which it wasn't created. Reload to refresh your session. 43" and still some additional rerenders happend. For some reason the response data type get set to 'any' causing implicit any errors all over our codebase. Network requests are still sent on the server, but following the Apollo Client API, not the Remix APIs, because Apollo Client is a client-side library. Sign in Product {useMutation, useQuery} from '@jimmyn/apollo-client'; import {createTodoMutation, todosQuery} Intended outcome: I'm using react-native and I have a Flatlist that gets it's data from a useQuery hook. "@apollo/client": "^3. I am using a TypePolicy to get the results from the cache, not sure if that is important to this issue. 7 but was introduced in 3. fetchPolicy after the intial network request, without calling observableQuery. Everyone else moved on to URQL and so should you. ; Apollo updates the MyField cache to merge in data from Component B; The cache update changes the value for SyncExternalStore, an internal of the useQuery Drop-in replacements for @apollo/client's useQuery, useMutation and useSubscription hooks with reduced overhead and additional functionality. Intended outcome: useQuery hook should return data if query lo Fixes #8370 by postponing all context. Actual outcome: The loading state is always true. x version. 2 to be exact) a useQuery(GET_CART) will ALWAYS return an undefined first in the child components before returning the data from the cache. client options. This used to work in Apollo 2. ; Versions Apologies if this has been addressed, I feel like i've look high and low. new props passed into the hook). The reason codegen defines Maybe<T> = T | undefined | null by default is because codegen is intended to be used Once the query is complete it loading should be false. 10 It seems that when calling useQuery while passing through a client the query always returns loading true and reruns infinitely. It looks like the polling ignores the skip property. S Most Api of urql is adopted from Apollo Client so it's easy to migrate. I did a quick experiment with this in useSuspenseQuery and unfortunately it causes a cascade of changes Intended outcome: I have a component that retrieves some data using useQuery and renders a chart. ; Actual outcome: The query consults the type policy, and This is a question that appears to have been repeatedly asked, but due to archiving repos and package evolution there is no documented answer. 5. 6 The text was updated successfully, but these errors were encountered: 👍 4 rossmartin, GabrielNastase, jmacpherson, and yobananaboy15 reacted with thumbs up emoji ️ 3 brainkim, xbaun, and genintho reacted with heart emoji When variables change in useQuery, Apollo Client should repeat the full request lifecycle exactly as for the initial set of options, including checking the cache for possible hits. Library Version: v3. Use cases: Pass true directly, and it correctly skips. Until now I used these options: fetchPolicy: 'cache-and-network', nextFetchPolicy: 'cache-first' But now I realized that I have some data t I have one project that uses apollo v2 and we decided not to update it until apollo v3 has a solution for that. 1 fixes the issue with StrictMode and works properly on both React 18. Here's a summary of what I'm experiencing: I use useQuery to load a query. This issue is similar With the new Next13 AppDir they suggest creating a provider. 3 setting notifyOnNetworkStatusChange: true does not make onCompleted to run after refetch is finished. nextFetchPolicy option allows updating options. I have a first step that uses the getDataFromTree to fetch all the data and then renders the app providing the apollo client that has the cache. Generally, a positive ssrForceFetchDelay essentially implies ssrMode for a certain time, I'm a similar issue to this as well as of v3. Take the given example: import {useState} from 'react' import { DocumentNode, gql, useQuery } from '@apollo/clie Issue Description. Is it the correct Intended outcome: A typical reason for skiping a useQuery() is the query is not yet ready to be called, for whatever reason. cjs and my react-scripts version did not support that extension on jest. 0-beta. (react@17. This doesn't happen when using the client from the context. setOptions. I am using the latest versions and am seeing the same issue with the custom NextJS app that implements isomorphic rendering. @ITSWYoo Especially the second issue you are bringing up here looks like you are creating one Apollo Client instance and sharing that over multiple requests. x that needs fixing. I'm currently having some troubles when setting errorPolicy: 'all' because the onCompleted callback is being called even if data is null. mutate methods, so I have to be able to access client instance. There's a bug here somewhere for sure. Apollo Client version: 2. I have tried both adding: function makeClient() { const httpLink = new Http I taught to use the skip option of useQuery but I don't think that's the best approach because I'm fetching in response to an event hence the use of useLazyQuery. Versions "@apollo/client": "3 I'm using newest "@apollo/client": "3. Intended outcome: After I setup my ApolloProvider in the top le Hey @jxdp 👋. canonizeResults options. Actual out In latest versions of Expo React Native (also newest versions of Apollo Client for React) useQuery no longer works. Actual outcome: Sometimes polling won't start. For any one else who ends up trying to do something similar—you can always create custom query functionality by directly calling the client. Instead of showing the cached value, or even undefined, the value of data is the previous result of the query, corresponding to the former variable value. We have exactly the same issue for our use case. How to reproduce the issue: See code above. 2 as @cc-dev-leader suggested seems to be an okay work-around so far. apollo-client 3. In this guide, you’ll learn how to build Query components in order to fetch GraphQL data and attach Mirrors the functionality of Apollo client's useQuery hook, but with a "query" being any async function rather than GQL statement. Please feel free to open a new issue if any other problems are still persisting, thanks! Using Apollo Client and useQuery hook I found issue when we try to get data witch loading more the 10 seconds useQuery returns nothing but seems websoket client returns data. This can cause bugs if you have code that assumes that writing to the cache I'm using @apollo/client: ^3. - appmotion/apollo-augmented-hooks Intended outcome: @client query with fetchPolicy no-cache or network-only should always hit local resolver. There is no loading state; With a suspense enabled query, a promise is thrown and the nearest <Suspense /> boundary fallback is rendered. I'm willing to bet #10506 might have had something to do Thanks for the quick reply @Ellarddekoeijer - if you're noticing that manually unsetting disableNetworkFetches solves the problem then I'm curious to learn more about this statement from the issue description:. v3. If it's still happening for you consistently, could you share your fork so I could try it out directly? @Bedotech The internals of react-apollo-hooks are quite a bit different than this project, so I'm not surprised to hear it's working with react-apollo-hooks. @apollo/client is version 3 of the library and apollo-client is Takes a matcher and a RemoteData value. This cache-first policy is Intended outcome: Get data from graphql server provided by graphql documentation using useQuery hook from @apollo/react-hooks Actual outcome: The data is fetched twice instead of once. 0 without strict mode. That way the server could query the latest data, and thus, would serve it to the client. Is it right way to use apollo client outside component? I would expect that on initial page load and any subscription updates to cats that my singular cat query will always update based on the cache value supplied by the cats query/subscription. This will result in null being passed for the data argument but the function signature does not reflect this circumstance. The server sets up a simple API that uses a You signed in with another tab or window. I am not aware of how it internally works, but when a request gets 200 or 500 response, for that Hi @objectiveSee 👋🏻 there are several different protocols that can handle GraphQL subscriptions, some of which are handled by modules we officially support. 4, client built in React, using hooks. merge updates until after all processSelectionSet work is done, performing the store updates at the end of StoreWriter#writeToStore, whereas previously those updates happened at the end of each StoreWriter#processSelectionSet call. In most cases for our application, we render leaf nodes that are keyed by id, like you mentioned, and use useQuery hooks with cache-only fetch policies I'm looking for a way to automatically re-run requests (re-render my component) every time the Apollo client is updated (based on an other available state/context, like in my case, depending on the user which I rely on to generate my tokens). The postponement of store updates gives the You signed in with another tab or window. 23", "@apollo/link The HOC have in general continuously configuration issues and misbehaviours, like for example the refetchQueries also don't trigger the data. 1 the problem no longer appears with useLazyQuery where similar This is correct behavior. 10 still works perfectly, so it's We have workarounds but it is important for us that Apollo Client is reliable. It seemed that doing the above wasn't enough, so I had to set certain queries as fetchPolicy: 'network-only' on the server's apollo-client too. nextFet After thinking more about this, I agree with @Akryum the extra network fetch after fetchMore is not a reasonable consequence of using network-only or cache-and-network fetch policies. I have configured a brand new app with the following dependencies: { "name": Thanks for some more of the context! Would you be willing to share the Apollo client and React version version you're using? That would go a long way toward helping us understand if it's an Apollo bug or something else! when the fastest query (the five-day one) solves, but it crashes - as the stockData initially passed is always an empty array When using pagination and doing a fetchMore request the cache is not used to read data, While data is already in the cache and having implementations for 'read' and 'merge' field policies, it looks like the 'fetchMore' is not using the t Issue Due to the compatible issue, I am using ApolloClient to form my AWS AppSync API client, so that I can use ApolloProvider to pass the client to different sub-component. Defaults to "cache-first". Since queryManager. useQuery usually used for making calls on the component mounting life-circle. @phryneas I could narrow it a little bit down: It seems that in my case the problem appears when combined with polling. Actual outcome: Resolver is only called once, all subsequent requests are cached. 3 our useQuery hook stopped working correctly. But I found some additional information which might be helpful. Spectrum discussion is ineffective at surfacing and maintaining knowledge of a solution; this I've encountered similar scalability issues when using a large amount (around the scale of thousands) of useQuery hooks pointing to the same few query documents and variables. You can optionally set a client-side schema to be used with Apollo Client, through either the ApolloClient constructor typeDefs parameter, or the local state API setTypeDefs method. The other issue: When fetchMore is invoked, the loading prop from the useQuery or useLazyQuery doesn't seem to update with true. - mindnektar/apollo-augmented-hooks Intended outcome: I have a local field named "displayedGame": gql`query GetDisplayedGame { displayedGame @client { id myPlayerId players { id name } } }` It references a Game in the cache: ROOT_QUE @macrael Although I truthfully haven't read the spec top-to-bottom, I believe that to be the case. @layerssss Thanks for the heads up. Actually v 3. The ssr-package useQuery is just a modified version that will latch onto values that might exist in the server's Apollo Client (probably because you ran useBackgroundQuery in a parant component) and makes sure that hydrates correctly on the client. This is useful when instantiating multiple clients to identify the client instance more easily. Yes, you may be able to work around the problem with nextFetchPolicy: "cache-first", but I no longer think using nextFetchPolicy should be necessary in this case. Sign up for a free GitHub account to open an issue and contact its maintainers and the community. That means, the client wil stay in disableNetworkFetches mode for 100ms. In addition, with 3. I want to be able to get both the network status code, and the graphQL errors out of the result. How to reproduce the issue: See the example above. Any query executed with Apollo client works well in the web, but on mobile devices (both real device and emulator) is stu The data reference returned by useQuery changes when a useMutation returns the same type, even if it's the same resulting object. In Apollo Client 3. Looking at your It's not realistic to add all the above accepts for skipToken, so my proposal would be either only as the whole options object (worse DX for non-variable queries), or both the options object and query object (good DX for both cases). Reproduction outline fetchpolicy = "network-only" paginating with a: custom merge function custo You signed in with another tab or window. This results in the page loading infinitely. json", uses the apollo-client package and your MFEs HostMFE and AdminMFE, what you call "MFE package. Navigation Menu Toggle navigation. Setting ssr: false fixes the issue, but there is no warning or anything in the console on the server and it doesn't hang on client-side routing, just on full page loads of a page that uses useLazyQuery which took a few days to figure out. To run a query within a React component, call useQuery and pass it a GraphQL query string. current. useLazyQuery requires you to interact with its execute function in order to work, so you need some additional code to ensure the fetch kicks off. query function that returns a promise. I don't know if my issue is only related to Apollo or to the relation between react and Apollo hooks. 0). Hopefully this is not intended behavior, as simply updating the variables in the useQuery call allows for declaratively representing data dependencies, consistent with React principles, whereas forcing to use fetchMore and manually update the cache is very You signed in with another tab or window. Hi, I've stumbled on an issue with auto refetching. If I put the option notifyOnNetworkStatusChange to true, it will update the loading state variable. I fetch list of items that I render on a screen using GET_ITEMS query (first and last argumen This performs a watchQuery on the ApolloClient. variables, to make sure that the client does not send queries that should @y-a-v-a the memory leaks you've been seeing should have been solved in Apollo Client 3. ; The resolver will go to the network and resolve with { organization: null }. By default useSubscription / Subscription uses the client passed down via context, but a As a professional React developer with over 15 years of experience building web applications, I‘ve found Apollo Client to be an indispensable tool for managing remote data in Fetching data in a simple, predictable way is one of the core features of Apollo Client. ; Pass a variable with a I am just setting up my project using these new apollo client features on NextJS 13. 0. Now I'm trying to implement server side pagination based on Intended outcome: Polling has two general use cases: We want to poll in the background to get notified of an update to some external state. Issue #6334 exposed a problem where the `lastResult` mechanism we use to prevent duplicate subscription notifications (when data hasn't changed) can unintentionally block certain results from propagating through Apollo Client. In order for this package to work, you need to wrap your component tree with ApolloProvider at an appropriate level, encapsulating Intended outcome: I am using refetch from useQuery hook in order to retry if something fails or timeout (remote graphql taking too long). I use useLazyQuery in component with useQuery and useMutation. Some of the lazy queries are actually returning data but loading is still true, and some non-lazy ones are just never even returning data. This leads to issues like loading states not being updated properly, due to new partial results looking similar to last results. Saved searches Use saved searches to filter your results more quickly @PrakashC1 if I'm reading this right, CustomLib, what you call "Library package. refetchQueries() , it simply returns all observables for given queries regardless Prerequisities When using useQuery with options Fetch-Policy: "network-only" Intended outcome: One network request for fetch policy "network-only" Actual outcome: Module: useBaseQuery. 2. In this situation, I extracted client instance as separate module and import that instance. I think the provider of a GraphQL API should always explicitly return null for a field rather than omitting it in the response, but someone please correct me if I'm wrong. 44. I wanna use client. It usually happens after star Query an Apollo client, returning a readable store of result values. 3. Description: An ApolloClient is rendered with a positive ssrForceFetchDelay on the client. I cannot find a way to attach headers to queries made with useQuery on the client side. If a subsequent query (such as a mutation) happens to fetch the same data while this query's subscription is still active, the object will immediately receive the latest attributes (just like ember-data). 1. You switched accounts on another tab or window. queries for refetchQueries. fetchMore does seem to be working again in version @apollo/client@3. Its easy, maintained since years and years, and extremely well documented. I have to use apollo client without react component, it means that I cannot use useApolloClient hook and withApollo HOC. I want to call the fetchMore function when the user reaches the end of the list, to grab the next page of data, and append it to the Hi all. 7". This becomes a huge issue on pages where we do infinite scroll **Note: Using Apollo Client with Remix results in using Apollo Client’s hooks in lieu of Remix’s loader and action functions. Here's the pattern as I see it: ComponentA runs a query on MyField, and includes an ID for caching; ComponentB runs a different query on MyField. is popping up all over my application after installing msw. nkfn jelkul akds tfat goha sxyqb lhpyh hmhu ker suvhy