react-apollo

updateQueries after GraphQL mutation not working with the Apollo client

微笑、不失礼 提交于 2019-12-31 02:07:25
问题 After I'm sending a createMessage mutation in my app, I want to update the local ApolloStore using updateQueries. My setup looks as follows: const ChatWithAllMessages = graphql(allMessages, {name: 'allMessagesQuery'})(Chat) export default graphql(createMessage, { props({ownProps, mutate}) { return { createMessageMutation(text, conversationId) { return mutate({ variables: { text, conversationId }, updateQueries: { allConversations: (previousState, {mutationResult}) => { console.log('Chat - did

GraphQL - How to respond with different status code?

℡╲_俬逩灬. 提交于 2019-12-29 04:43:50
问题 I'm having a trouble with Graphql and Apollo Client. I always created differents responses like 401 code when I using REST but here I don't know how I to do a similar behavior. When I get the response I want it go to the catch function. I have this code in the front: client.query({ query: gql` query TodoApp { todos { id text completed } } `, }) .then(data => console.log(data)) .catch(error => console.error(error)); Can anybody help me? 回答1: The way to return errors in GraphQL (at least in

refreshing a token with apollo-client + firebase auth

落爺英雄遲暮 提交于 2019-12-25 18:56:09
问题 I'm having some trouble figuring out token refreshes when using apollo-client and firebase's auth service. I've setup token refresh using apollo client before. Typically I use the apollo-link-error package (apollo-link-error docs). My understanding is you get the latest token from firebase auth with a promise like: firebase.auth().currentUser.getIdToken How to use the Firebase refreshToken to reauthenticate? reading the answer from this post: When you make call from a browser .getIdToken(true

Issue with automatic UI updates in Apollo: `updateQuery` not working properly with `subscribeToMore`

ⅰ亾dé卋堺 提交于 2019-12-25 07:46:55
问题 I'm using GraphQL subscriptions for my chat application, but I have an issue with the UI updates. Here are the query and the mutation I'm using: const createMessage = gql` mutation createMessage($text: String!, $sentById: ID!) { createMessage(text: $text, sentById: $sentById) { id text } } ` const allMessages = gql` query allMessages { allMessages { id text createdAt sentBy { name location { latitude longitude } } } } ` Then, when exporting, I'm wrapping my Chat component like so: export

Invariant Violation setting state in Apollo mutate callback

本小妞迷上赌 提交于 2019-12-25 05:19:09
问题 I'm calling a mutate function from an event handler and getting an Invariant Violation error when I try to use this.setState in the catch clause. saveToken({data}){ let {userId, token, expires} = data.login; storeLoginToken(userId, token, expires); history.push('/dogs'); } setErrors(error){ this.setState('error', error.graphQLErrors); } handleSubmit(event) { event.preventDefault(); let {email, password} = this.state; let {history} = this.props; let clientKey = getClientKey(); this.props

How to show data from GraphQL server to npm react-table?

夙愿已清 提交于 2019-12-25 02:46:23
问题 I've been starting working with GraphQL server and Apollo client . The code is written in Reactjs . Now I want to get data from GraphQL server using any queries, and show data to the table in the UI. I use npm react-table for table. The table could look like this: I can easily get and show data if the query response has no array. For example, I have the query input string below: { account { firstName lastName id } } And query result with no array { "data": { "account": { "firstName": "Marlen"

Trying call useQuery in function with react-apollo-hooks

做~自己de王妃 提交于 2019-12-24 15:24:09
问题 I want to call useQuery whenever I need it, but useQuery can not inside the function. My trying code is: export const TestComponent = () => { ... const { data, loading, error } = useQuery(gql(GET_USER_LIST), { variables: { data: { page: changePage, pageSize: 10, }, }, }) ... ... const onSaveInformation = async () => { try { await updateInformation({...}) // I want to call useQuery once again. } catch (e) { return e } } ... How do I call useQuery multiple times? Can I call it whenever I want?

How to fix this warning “useLayoutEffect” related warning?

这一生的挚爱 提交于 2019-12-24 11:29:58
问题 I am using NextJS with Material UI and Apollo. Although, everything is working properly but the warning is not going. It seems to me that a lot of Material UI components are using useLayoutEffect which is warned by React. The error is below. Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect

React Apollo - Strange Effect When Making Mutation?

荒凉一梦 提交于 2019-12-24 09:19:08
问题 I've set up a React application with React-Apollo and can successfully query my API. However, when I make a mutation, a strange effect occurs. I get all the data back successfully (as seen in the Network tab of the Chrome Dev Tools), but when trying to console.log the data, it says that it is null . Here's the relevant code: // mutation file import gql from "graphql-tag"; export default gql` mutation CreateReservation($name: String!, $time: String!, $persons: String, $specialMessage: String,

How to dynamically set variables in mutation with react-adopt?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:59:50
问题 In my component, I am using react-adopt, to compose graphql queries and mutations, so that my render props don't get too messy. I have the following code: This is my mutation, it takes one argument - planID. const CREATE_ORDER_MUTATION = gql` mutation CREATE_ORDER_MUTATION($planID: String!) { createOrder(planID: $planID) { planID name description subscriptionType images subscriptionType pricePerMonth } } This is the adopt function, it takes a couple of mutations, one of which is createOrder.