apollo

Angular - Apollo: Client has not been defined yet

半世苍凉 提交于 2020-07-20 07:59:35
问题 I'm using apollo client for graphql. I set up the client in AppApolloModule that I'm importing in AppModule. I'm making a query in a service which is also imported right in the AppModule. Although the service runs before the AppApolloModule runs and hence apollo is not initialized when the query is made and I get this error Error: Client has not been defined yet AppApolloModule imports .... export class AppApolloModule { constructor( apollo: Apollo, httpLink: HttpLink, private userService:

Unexpected end of JSON on GraphQL query with React while no issue with GraphiQL

心已入冬 提交于 2020-07-18 15:36:09
问题 I am trying to do a very basic query via React with Apollo. When I do this query in GraphiQL I nicely get my results back but in my app I get an undefined data object. And a error with a message: Network error: Unexpected end of JSON input The query is: query { category(id: 3) { id children { id name } } } This is my component import React, { Component } from 'react'; import { Query } from 'react-apollo'; import gql from 'graphql-tag'; const CATEGORIES_LIST = gql` query CATEGORIES_LIST {

how to unsubscribe with useQuery and subscribeToMore

浪尽此生 提交于 2020-07-18 05:05:44
问题 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 use to unsubscribe. This does give a hint. It would help to see an example. the question Using @apollo/react-hooks , inside of a useEffect() and returning the results of the subscribeToMore , is this the way to unsubscribe on a component unmount?

how to unsubscribe with useQuery and subscribeToMore

≯℡__Kan透↙ 提交于 2020-07-18 05:05:06
问题 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 use to unsubscribe. This does give a hint. It would help to see an example. the question Using @apollo/react-hooks , inside of a useEffect() and returning the results of the subscribeToMore , is this the way to unsubscribe on a component unmount?

refetchQueries works for only some queries

大城市里の小女人 提交于 2020-07-16 08:04:45
问题 I use a Friend component on my AllFriends screen that runs this mutation: const [deleteUserRelation] = useDeleteUserRelationMutation({ onCompleted: () => { Alert.alert('Unfriended'); }, refetchQueries: [{ query: GetMyProfileDocument }], awaitRefetchQueries: true, onError: _onDeleteUserRelationError, }); Every time, the mutation is successful, the query is refetched and data here is successfully re-rendered. I also see the necessary logs. export const AllFriends: React.FunctionComponent = () =

react firebase authentication with apollo graphql

橙三吉。 提交于 2020-07-05 05:11:20
问题 I have found a great article adding authentication into react. Article: https://www.robinwieruch.de/complete-firebase-authentication-react-tutorial/ This article finishes the firebase setup (before redux) with a HOC component that I can put into the app and can access with context. My issue is how do i put this into the apollo client which is outside of the app component so even with the context I cant set it. I have this same problem with redux. Only one I have found is use local storage but

Triggering a second GraphQL query based on data from initial query

蓝咒 提交于 2020-06-29 04:08:41
问题 Overview When WrappedApp initially loads, a query is sent to the GraphQL API to fetch the data (Tags). After this has completed a user can add an item to the ShortList in WrappedApp by clicking on a Tag in the TagsList (see screenshot below). Question How can I get this click of a Tag in the TagsList (i.e. security was clicked in the example below) to trigger the second GraphQL query named GQLSIMILARTAGS and render the result above the ShortList components data or at least console.log the

onError in GraphQL mutations

冷暖自知 提交于 2020-06-23 10:59:01
问题 I was trying onError for graphql mutations and realised that they don't work properly: https://github.com/apollographql/apollo-client/issues/5708 What else can be done for catching errors then? In a previous question, I was told that using try catch blocks for mutations is not a good idea. I am trying to do something like this, with a possible workaround: I ask user for an input, then run a query. Depending on the results of the query, I render some User components. From the user component, I

onError in GraphQL mutations

好久不见. 提交于 2020-06-23 10:58:06
问题 I was trying onError for graphql mutations and realised that they don't work properly: https://github.com/apollographql/apollo-client/issues/5708 What else can be done for catching errors then? In a previous question, I was told that using try catch blocks for mutations is not a good idea. I am trying to do something like this, with a possible workaround: I ask user for an input, then run a query. Depending on the results of the query, I render some User components. From the user component, I

“Error: Cannot read property 'slice' of undefined” when importing apollo-link-ws in nativescript vue?

帅比萌擦擦* 提交于 2020-06-17 09:34:28
问题 My goal is to use subscriptions in GraphQL in a nativescript vue app to avoid google firebase. It works fine using HttpLink, but it doesn't with websockets. The Error: TypeError: Cannot read property 'slice' of undefined occurs on runtime when importing apollo-link-ws or subscription-transport-ws . As soon as I comment both imports out, the code runs again and I can use GraphQL over http. const Vue = require('nativescript-vue'); import { ApolloClient } from 'apollo-client' import { HttpLink }