apollo-client

Use result for first query in second query with Apollo Client?

大憨熊 提交于 2019-12-01 05:53:13
问题 Im using Apollo, React and Graphcool. I have a query to get the logged in users ID: const LoginServerQuery = gql` query LoginServerQuery { loggedInUser { id } } `; I need to use the returned ID in another query which is called from the same React component. Here Ive hardcoded "xxxxxxxxxxxxx" which is where the dynamic user ID needs to go: const LocationQuery = gql` query LocationsQuery { User(id: "xxxxxxxxxxxxx") { location { name } } } `; 回答1: If you import compose like so: import { graphql,

Using ApolloClient with node.js. “fetch is not found globally and no fetcher passed”

…衆ロ難τιáo~ 提交于 2019-12-01 02:53:30
I am attempting to use an Apollo Client on a node.js server to interface with another GraphQL API using the following code: import fetch from 'node-fetch' import { createHttpLink } from 'apollo-link-http' import ApolloClient from 'apollo-boost' import { API_URL } from '...' const client = new ApolloClient({ link: createHttpLink({ uri: API_URL, fetch: fetch, }), }) Which yields the following error: module initialization error: Error fetch is not found globally and no fetcher passed, to fix pass a fetch for your environment like https://www.npmjs.com/package/node-fetch. For example: import fetch

Apollo client mutation error handling

不打扰是莪最后的温柔 提交于 2019-12-01 00:58:00
问题 I'm using GraphQL and mongoose on the server. When a validation error occurs the GraphQL mutation sends a response with status code 200. On the client side the response looks like this: { "data": null, "errors": [{ "message": "error for id...", "path": "_id" }] } I would like to get access to the validation error using the catch functionality of the apollo-client mutation promise. Something like: this.props.deleteProduct(this.state.selectedProductId).then(response => { // handle successful

How to chain together Mutations in apollo client

柔情痞子 提交于 2019-11-30 23:08:46
I have a bunch of information stored in my state that I need to pass to my graphQL server using mutations, but I need to use the results of each mutation before I call the next one since I need to: Create a new object in my database Use the id generated for that object to create another object Modify the original object to store the id generated by the second object I noticed that apollo Mutation components have an onCompleted callback, but I don't know how to use this callback to fire off another mutation or whether it's the right way solve my problem. I also looked into batching my mutations

Using ApolloClient with node.js. “fetch is not found globally and no fetcher passed”

我们两清 提交于 2019-11-30 22:44:17
问题 I am attempting to use an Apollo Client on a node.js server to interface with another GraphQL API using the following code: import fetch from 'node-fetch' import { createHttpLink } from 'apollo-link-http' import ApolloClient from 'apollo-boost' import { API_URL } from '...' const client = new ApolloClient({ link: createHttpLink({ uri: API_URL, fetch: fetch, }), }) Which yields the following error: module initialization error: Error fetch is not found globally and no fetcher passed, to fix

Uncaught TypeError: Can't add property 12, object is not extensible

让人想犯罪 __ 提交于 2019-11-30 21:23:26
I can't seem to understand the error I am getting on my client application. I am subscribing to a graphql subscription and I am able to retrieve the updates but I am not being able to push the changes to the typescript array called "models:ModelClass[]" which is bound to the view. Is there something I am missing or doing wrong? models.component.ts this.apollo.subscribe({ query: gql` subscription { newModelCreated{ _id name type train_status deploy_status data_path description created_at updated_at } } ` }).subscribe((data) => { console.log("CREATED: " + JSON.stringify(data.newModelCreated));

Uncaught TypeError: Can't add property 12, object is not extensible

别来无恙 提交于 2019-11-30 05:16:22
问题 I can't seem to understand the error I am getting on my client application. I am subscribing to a graphql subscription and I am able to retrieve the updates but I am not being able to push the changes to the typescript array called "models:ModelClass[]" which is bound to the view. Is there something I am missing or doing wrong? models.component.ts this.apollo.subscribe({ query: gql` subscription { newModelCreated{ _id name type train_status deploy_status data_path description created_at

How to execute an async fetch request and then retry last failed request?

巧了我就是萌 提交于 2019-11-30 02:19:22
Apollo link offers an error handler onError Issue: Currently, we wish to refresh oauth tokens when they expires during an apollo call and we are unable to execute an async fetch request inside the onError properly. Code: initApolloClient.js import { ApolloClient } from 'apollo-client'; import { onError } from 'apollo-link-error'; import { ApolloLink, fromPromise } from 'apollo-link'; //Define Http link const httpLink = new createHttpLink({ uri: '/my-graphql-endpoint', credentials: 'include' }); //Add on error handler for apollo link return new ApolloClient({ link: ApolloLink.from([ onError(({

How to run a mutation on mount with React Apollo 2.1's Mutation component?

只愿长相守 提交于 2019-11-29 07:34:44
问题 We are currently moving from Relay to React Apollo 2.1 and something I'm doing seems fishy. Context: Some components must only be rendered if the user is authenticated (via an API key), so there is an Authenticator component guarding the rest of the tree. In App.js , it gets used like this (obviously all snippets below are minimal examples): import React from 'react'; import Authenticator from './Authenticator'; import MyComponent from './MyComponent'; export default function App({ apiKey })

How to execute an async fetch request and then retry last failed request?

左心房为你撑大大i 提交于 2019-11-28 23:00:19
问题 Apollo link offers an error handler onError Issue: Currently, we wish to refresh oauth tokens when they expires during an apollo call and we are unable to execute an async fetch request inside the onError properly. Code: initApolloClient.js import { ApolloClient } from 'apollo-client'; import { onError } from 'apollo-link-error'; import { ApolloLink, fromPromise } from 'apollo-link'; //Define Http link const httpLink = new createHttpLink({ uri: '/my-graphql-endpoint', credentials: 'include' }