apollo

How to set up Apollo client only after user authenticates?

倖福魔咒の 提交于 2019-12-06 05:44:49
问题 I'm a bit confused on how to structure my React/GraphQL (Apollo) app when no connection should be made until the user authenticates/logs in. Currently I have this: class App extends Component { render() { return ( <ApolloProvider client={client}> <Provider store={store}> <Router> <div> <ul> <li><Link to="/">Home</Link></li> <li><Link to="/login">Log In</Link></li> <li><Link to="/signup">Sign Up</Link></li> </ul> <AuthenticatedRoute exact path="/" component={HomePage} /> <Route path="/login"

001-apollo的安装

和自甴很熟 提交于 2019-12-06 05:11:05
Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够集中化管理应用不同环境、不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限、流程治理等特性。服务端基于Spring Boot和Spring Cloud开发,打包后可以直接运行,不需要额外安装Tomcat等应用容器。Java客户端不依赖任何框架,能够运行于所有Java运行时环境,同时对Spring环境也有较好的支持。.Net客户端不依赖任何框架,能够运行于所有.Net运行时环境,而且已经支持.NET Core。 官网: https://github.com/ctripcorp/apollo Wiki: https://github.com/ctripcorp/apollo/wiki (一切的集成方式和使用方法都在这里) Issues: https://github.com/ctripcorp/apollo/issues (如果期间有任何问题,请通过这里查找大部分解决方法) 说明:官方提供了分布式部署方案,但是基于本地开发和调试上一般是单机部署的比较多。且提供的Quick Start方案跑不起来。所以下面将针对单机搭建上做详细的实践,用作开发环境。 注意:如果是生产环境一定要使用分布式部署方案来做高可用集群。 下载Release版本: https://github.com/ctripcorp/apollo

How to write to apollo cache from within React component with out losing context of “this”

拜拜、爱过 提交于 2019-12-06 03:42:17
I'm having trouble trying to read from apollo cache from within a react component the mutation works and writes to my server and returns the data but when passed to my update function it seems to lose the context of this when in inMemoryCache.js "apollo-cache-inmemory": "^1.2.5" "react-apollo": "^2.1.4" "apollo-boost": "^0.1.7" TypeError: Cannot read property 'read' of undefined at ./node_modules/apollo-cache-inmemory/lib/inMemoryCache.js.InMemoryCache.readQuery import React, { Component } from "react"; import { graphql } from "react-apollo"; import trim from "lodash/trim"; import AuthorForm

React Apollo 2 with React Router. graphql HOC loading: true forever if I navigate

大憨熊 提交于 2019-12-06 02:15:32
This is the code: https://codesandbox.io/s/p90q6674qq I simply use: export default graphql(CURRENT_USER_QUERY)(Menu); on the Menu component and simply this code in App component: class App extends Component { render() { return ( <div> {/* <Menu /> */} <Route component={Menu} /> <Route exact path="/" component={Home} /> <Route path="/login" component={Login} /> </div> ); } } A bug? Where am I wrong? 来源: https://stackoverflow.com/questions/47733633/react-apollo-2-with-react-router-graphql-hoc-loading-true-forever-if-i-navigat

Why isn't Apollo Server a middleware for Express, rather than being a server that accepts Express as a middleware?

偶尔善良 提交于 2019-12-06 00:54:19
问题 I'm just wondering what's the reason for this seemingly awkward configuration (from Getting Started w/ Apollo Server), const server = new ApolloServer({ // These will be defined for both new or existing servers typeDefs, resolvers, }); server.applyMiddleware({ app }); // app is from an existing express app Why is that I'm calling .applyMiddleware() and feeding it my app rather than using app.use(), it even seems from the docs that Apollo is only answering requests on /graphql wouldn't it be

How do I update the Apollo data store/cache from a mutation query, the update option doesn't seem to trigger

此生再无相见时 提交于 2019-12-05 22:44:21
I have a higher order component in my react native application that retrieves a Profile. When I call an "add follower" mutation, I want it to update the Profile to reflect the new follower in it's followers collection. How do I trigger the update to the store manually. I could refetch the entire profile object but would prefer to just do the insertion client-side without a network refetch. Currently, when I trigger the mutation, the Profile doesn't reflect the change in the screen. It looks like I should be using the update option but it doesn't seem to work for me with my named mutations.

携程Apollo简单入门教程这一篇就够了

心已入冬 提交于 2019-12-05 19:35:20
1. Apollo背景 对程序配置的期望值也越来越高:配置修改后实时生效,灰度发布,分环境、分集群管理配置,完善的权限、审核机制…… 废话不多说,参考 官方文档 如果不想看文档, 也没关系, 跟着我一步步走. 2. 安装Apollo服务端 因为是简单案例, 所以就用官方的 Quick Start 2.1 环境要求 以下是采用Linux环境配置 Apollo服务启动包 2.1.1 CentOS7, 不懂linux的, 可以不要继续往下看了. 虚拟机ip为: 192.168.102.140 2.1.2 JDK1.8 以上, 不懂安装JDK, 请自行百度 2.1.3 MySQL5.6.5+以上, 不懂安装MySQL, 请自行百度 2.2 下载 Apollo服务端 Jar包 2.2.1 百度网盘 下载 2.2.2 自己下载源码, 自己打包, 挑战性比较大, 建议放弃 下载 2.2.3 把下载好的jar包, 从windows上, 拉取到linux系统中 2.3 创建数据库, 存储Apollo的配置数据 2.3.1 创建ApolloPortalDB 步骤1 通过mysql客户端, 如Navicat, 连接linux中的数据库. 步骤2 导入sql 通过各种MySQL客户端导入 sql/apolloportaldb.sql 即可。 2.3.2 创建ApolloConfigDB

使用Apollo动态修改线上数据源

大憨熊 提交于 2019-12-05 18:10:42
前言    最近需要实现一个功能,动态刷新线上数据源环境,下面来使用Apollo配置中心和Spring提供的AbstractRoutingDataSource来实现。 具体实现    Apollo是携程开源的统一配置中心,和springboot无缝衔接并且不需要安装其他软件就可以直接使用,可以实时推送最新的配置文件。Spring提供的AbstractRoutingDataSource用于动态管理数据源,可以动态更新数据源,一般数据库的读写分离也是用这个抽象类实现的。   对Apollo不熟悉的可以先了解一下,GitHub:https://github.com/ctripcorp/apollo   关于AbstractRoutingDataSource,介绍一下我们用到的方法 public abstract class AbstractRoutingDataSource extends AbstractDataSource implements InitializingBean { //传入的数据源 private Map<Object, Object> targetDataSources; //拿着子类实现的determineCurrentLookupKey()方法的返回值当做key在这个Map中寻找数据源 private Map<Object, DataSource>

springboot项目使用 apollo 配置中心

元气小坏坏 提交于 2019-12-05 08:58:36
1. 引入 apollo 配置依赖 <dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> <version>1.1.0</version> </dependency> 2. 在应用名添加 apollo 配置开启 @EnableApolloConfig 3. 指定 app.id 和 environment -Dapp.id=YOUR-APP-ID -Denv=YOUR-ENVIRONMENT 4. 删除本地配置文件 application.properties/application.yml 或者在配置文件中添加,让配置中心的配置生效 apollo.bootstrap.enabled=true 来源: https://www.cnblogs.com/zhaopengcheng/p/11917674.html

GraphQL - How to chain queries and mutations? [duplicate]

早过忘川 提交于 2019-12-05 08:29:04
This question already has an answer here: How to chain two GraphQL queries in sequence using Apollo Client 2 answers In my graphQL schema, I have a relationship between two objects. Say Humans and Cats. Humans have many Cats and Cats have one human. If I want to create a new Cat belonging to a human, I need to query for the human by ID and then I need to use that ID to do a mutation to create the cat. How can I chain these together? It seems simple but can't find an appropriate example. It is also very likely that I'm thinking about this in the wrong way. I don't think it makes sense to chain