react-apollo

useQuery returns undefined, But returns data on gql playground

馋奶兔 提交于 2020-05-24 05:58:06
问题 "@apollo/react-hooks": "^3.1.3", "apollo-client": "^2.6.8", Apollo client return undefined on react app but return the data on gql playground, I don't understand why don't it works on client-side but works on graphql playground. Schema I have defined union for user query for error handling. type Query { user(id: ID!): UserReturn! } union UserReturn = User | Error type User { id: ID! username: String! email: String profileUrl: String createdAt: Date ads: [Doc!]! } type Error { message: String

Auto-update of apollo client cache after mutation not affecting existing queries

人盡茶涼 提交于 2020-05-19 13:01:29
问题 I have a mutation (UploadTransaction) returning certain list of certain object named Transaction. #import "TransactionFields.gql" mutation UploadTransaction($files: [Upload!]!) { uploadFile(files: $files){ transactions { ...TransactionFields } } } Transaction returned from backend (graphene) has id and typename field. Hence it should automatically update Transaction in the cache. In chrome dev tools for Apollo, I can see new transactions: I also have a query GetTransactions fetching all

Auto-update of apollo client cache after mutation not affecting existing queries

坚强是说给别人听的谎言 提交于 2020-05-19 12:55:14
问题 I have a mutation (UploadTransaction) returning certain list of certain object named Transaction. #import "TransactionFields.gql" mutation UploadTransaction($files: [Upload!]!) { uploadFile(files: $files){ transactions { ...TransactionFields } } } Transaction returned from backend (graphene) has id and typename field. Hence it should automatically update Transaction in the cache. In chrome dev tools for Apollo, I can see new transactions: I also have a query GetTransactions fetching all

“Rendered more hooks than during the previous render” error when the initial value for the hook is a query result from a database

爱⌒轻易说出口 提交于 2020-05-17 06:08:23
问题 I'm using React's hook and I want to have a value that is retrieved from the database as the initial value. However, I'm getting the following error: Invariant Violation: Invariant Violation: Rendered more hooks than during the previous render. const { data, loading, error } = useQuery(GET_DATA) const { initialValue } = data const [value, setValue] = useState(initialValue) I'm using the React Apollo hook. Update export default NotificationScreen = ({ navigation }) => { const { data:

Store data from useQuery with useState

夙愿已清 提交于 2020-05-15 07:54:08
问题 I'm using React hooks both to fetch GraphQL data with react-apollo and to store local state: const [userData, setUserData] = useState({}) const { loading, error, data } = useQuery(USER_QUERY) However, I'm wondering how to store data to userData . Is this how it's supposed to work: useEffect(() => { setUserData(data) }, [Object.entries(data).length]) 回答1: Looks like what you have probably works. There is also a onCompleted option available in the options parameter. it takes a callback of type:

How to chain useQuery hooks using react-apollo-hooks [duplicate]

萝らか妹 提交于 2020-04-13 17:55:26
问题 This question already has answers here : How to chain two GraphQL queries in sequence using Apollo Client (2 answers) Closed last month . I would like to execute 2 queries with hooks where the second query uses information retrieved in the first one. For example: const { data, error, loading } = useQuery(GET_DOGS); const result2 = useQuery(GET_BREEDS, { variables: { dogId: data[0].id } }); Right now I do it using some state and setting the skip parameter on the second hook, however I figure

How can I use the useQuery hook to populate state in other hooks?

巧了我就是萌 提交于 2020-04-08 10:21:44
问题 I have been dealing with a few hook-related issues recently as I have been implementing hooks into a project of mine. I keep getting the error "Rendered more hooks than during the previous render." It seems that the only way I can get my code to work is by putting the useQuery hook after all of the other hooks. This is a problem however as I want to populate some values of state with values from data on the query. // code that doesn't error, but am not able to initialize state with query

How can I use the useQuery hook to populate state in other hooks?

做~自己de王妃 提交于 2020-04-08 10:19:53
问题 I have been dealing with a few hook-related issues recently as I have been implementing hooks into a project of mine. I keep getting the error "Rendered more hooks than during the previous render." It seems that the only way I can get my code to work is by putting the useQuery hook after all of the other hooks. This is a problem however as I want to populate some values of state with values from data on the query. // code that doesn't error, but am not able to initialize state with query

How can I use the useQuery hook to populate state in other hooks?

南楼画角 提交于 2020-04-08 10:18:27
问题 I have been dealing with a few hook-related issues recently as I have been implementing hooks into a project of mine. I keep getting the error "Rendered more hooks than during the previous render." It seems that the only way I can get my code to work is by putting the useQuery hook after all of the other hooks. This is a problem however as I want to populate some values of state with values from data on the query. // code that doesn't error, but am not able to initialize state with query

How can I use the useQuery hook to populate state in other hooks?

时光总嘲笑我的痴心妄想 提交于 2020-04-08 10:18:15
问题 I have been dealing with a few hook-related issues recently as I have been implementing hooks into a project of mine. I keep getting the error "Rendered more hooks than during the previous render." It seems that the only way I can get my code to work is by putting the useQuery hook after all of the other hooks. This is a problem however as I want to populate some values of state with values from data on the query. // code that doesn't error, but am not able to initialize state with query