Questions tagged [apollo-client]

Apollo Client is a JavaScript library for building client UIs that fetch data using GraphQL.

Apollo Client is the best way to use GraphQL to build client applications. The client is designed to help you quickly build a UI that fetches data with GraphQL, and can be used with any JavaScript front-end.

Apollo Client

Repository

3353 questions
14
votes
5 answers

Wait for useLazyQuery response

I need to call a query when submit button is pressed and then handle the response. I need something like this: const [checkEmail] = useLazyQuery(CHECK_EMAIL) const handleSubmit = async () => { const res = await checkEmail({ variables: { email:…
14
votes
1 answer

GraphQL - variable not defined by operation

My GraphQL schema is defined as: type Query { getEntity(id: Int!): Entity getEntityUsers(entityId: Int!, statusId: Int): [User] } type Entity { id: Int! name: String! email: String! logo: String createdAt: DateTime! …
jrkt
  • 2,615
  • 5
  • 28
  • 48
14
votes
2 answers

How can i run one mutation multiple times with different arguments in one request?

I have a mutation: const createSomethingMutation = gql` mutation($data: SomethingCreateInput!) { createSomething(data: $data) { something { id name } } } `; How do I create many Somethings in one request? Do…
Maxim Zubarev
  • 2,403
  • 2
  • 29
  • 48
14
votes
1 answer

How to set a timeout on a request with Apollo-Client

I have a React-Native app where I make requests to a GraphQL server. Everything works fine except I need a way to set the timeout on the request/client to 5 or 10 seconds. Currently the request takes a very long time before it times out (around 1…
menderleit
  • 141
  • 1
  • 1
  • 4
13
votes
1 answer

What does notifyOnNetworkStatusChange do exactly?

I had an issue where the loading property was not true when performing a refetch. I read somewhere notifyOnNetworkStatusChange to true would fix this. However we've notice after using this property we have some use case where we end up in infinite…
plus-
  • 45,453
  • 15
  • 60
  • 73
13
votes
1 answer

Apollo client fragments not embedding data

This is the first time I've ventured into fragments and I can't see where I'm screwing up, but it definitely isn't working! In GraphiQL it's working fine: query Tasks($taskIds: [String]!) { tasks(taskIds: $taskIds) { ...taskDisplay …
Scott
  • 3,204
  • 3
  • 31
  • 41
13
votes
2 answers

how to unsubscribe with useQuery and subscribeToMore

Another post shared an example of how to unsubscribe, where the Apollo docs don't. The Apollo docs do mention what subscribeToMore returns... subscribeToMore: A function that sets up a subscription. subscribeToMore returns a function that you can…
Chance Smith
  • 1,211
  • 1
  • 15
  • 32
13
votes
1 answer

How to acess React context from Apollo set Context Http Link

I am trying to access a react context values within the setContext function for my Apollo client. I would like to be able to dynamically update the header for each graphql request with the react context value. But I face an error with no visible…
john
  • 1,057
  • 1
  • 17
  • 28
13
votes
1 answer

Differences between new HttpLink and createHttpLink from package apollo-link-http

In tutorial https://www.howtographql.com/vue-apollo/1-getting-started/ there is presented new HttpLink syntax, but in official docs https://www.apollographql.com/docs/link/links/http/ function createHttpLink is applied. None of these two sources…
Daniel
  • 7,684
  • 7
  • 52
  • 76
13
votes
2 answers

React: UI Flickering When State Updated

I have a component that displays search data returned from the Spotify API. However, every time I update the state the UI flickers: Input:
Travis S.
  • 343
  • 1
  • 4
  • 14
13
votes
1 answer

Apollo Client sending OPTIONS instead of GET HTTP method

I'm having trouble understanding Apollo Client library as it does not work as intended. Instead of sending the GET HTTP method, it sends the OPTIONS HTTP method even though I've put to use GET only when retrieving data from GraphQL server. const…
Vladimir Jovanović
  • 5,143
  • 5
  • 21
  • 42
13
votes
3 answers

Is graphql's ID type necessary if I've set an unique identifier with dataIdFromObject in Apollo Client

I'm using graphql + mysql + react-apollo and here's one of the graphql type for User table: type User { id: ID! name: String! } My issue with ID scalar type in graphql is that it is returned as a string when primary keys are int in mysql and it…
RedGiant
  • 4,444
  • 11
  • 59
  • 146
13
votes
5 answers

How to use Apollo Client + React Router to implement private routes and redirection based on user status?

I am using React Router 4 for routing and Apollo Client for data fetching & caching. I need to implement a PrivateRoute and redirection solution based on the following criteria: The pages a user is permitted to see are based on their user status,…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
13
votes
1 answer

How do I create a GraphQL subscription with Apollo Client in Vanilla JS

Recently Apollo Client released a websocket subscription feature, but so far I've only seen it used by launching a query using subscribeToMore inside the componentWillMount lifecycle hook. Here is an example taken from…
xabitrigo
  • 1,341
  • 11
  • 24
12
votes
4 answers

How to use UseQuery with useEffect?

How to use UseQuery in React.UseEffect? this is my simple query const {allrecord} = useQuery(ME, { onCompleted: ({ meTeacher}) => { setUser(meIAM); getRecords({ variables: { orgId: meIAM.organization.id, …
Roger
  • 293
  • 1
  • 4
  • 15