不确定这是 React Router v4、React Apollo 客户端还是我的实现的问题。
但是<ApolloProvider>
作为顶级 HOC,即:
const ComponentsWithData = await getDataFromTree(
<ApolloProvider client={apolloClient}>
<StaticRouter location={ctx.request.url} context={route}>
<App />
</StaticRouter>,
</ApolloProvider>,
);
const html = ReactDOMServer.renderToString(ComponentsWithData);
Run Code Online (Sandbox Code Playgroud)
......我明白了:
警告:无法丙类型:无效支柱
children
型的array
供给ApolloProvider
,预期单个ReactElement。在 ApolloProvider 错误 React.Children.only 期望接收单个 React 元素子元素。
并翻转过来,以 React Router<StaticRouter>
为顶部,即:
const ComponentsWithData = await getDataFromTree(
<ApolloProvider client={apolloClient}>
<StaticRouter location={ctx.request.url} context={route}>
<App />
</StaticRouter>,
</ApolloProvider>,
);
Run Code Online (Sandbox Code Playgroud)
...然后我得到:
A
<Router>
可能只有一个子元素
渲染在浏览器中工作正常(使用 React Router 的<BrowserRouter>
),但在服务器上失败。
由于在 React 层次结构之外进行所有路由匹配,而不是在其内部进行声明,因此它在 React Router …
所以,我遇到了一个问题,一个操作返回上面提到的错误(参见附图),而不是按预期更新redux状态.我在这里俯瞰什么?
actionCreators.js
export function userToken(token) {
console.log('userToken has been fired');
return (dispatch) => {
dispatch({
type: 'Graphcool_Token',
payload: token
});
}
}
Run Code Online (Sandbox Code Playgroud)
App.js
....
// Root Query
const allPostsCommentsQuery = graphql(All_Posts_Comments_Query, {
options: {
cachePolicy: 'offline-critical',
fetchPolicy: 'cache-first',
},
});
export const mapDispatchToProps = (dispatch) => {
return bindActionCreators(actionCreators, dispatch);
}
export default compose(
allPostsCommentsQuery,
connect(mapDispatchToProps)
)(Main);
Run Code Online (Sandbox Code Playgroud)
减速器
var tokenDetails = function(state, action) {
if (state === undefined) {
state = [];
}
switch (action.type) {
case 'Graphcool_Token':
const newState …
Run Code Online (Sandbox Code Playgroud) 使用REST-API,我们可以进行获取查询,而不是对服务器进行查询。我使用“ Apollo-client”,但是我想创建查询而不将查询连接到组件。我可以做吗?可能我应该使用方法client.query(http://dev.apollodata.com/core/apollo-client-api.html#ApolloClient.query)和client.mutate或类似的方法?
我对AWS AppSync和ApolloClient有问题。如何使用Amazon Service中名为AppSync的用户之间的关联,即作为节点和边缘的连接。我想做的是,当我关注用户时,我希望通过一个请求查看所有用户的流量。这是我想要成为的要求。我如何为此构建结构?
query {
getFeeds(id:"myUserId") {
following {
userFeed {
id
ImageDataUrl
textData
date
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我创建的架构如下
type Comments {
id: ID!
date: Int!
message: String!
user: User
}
type Feed {
id: ID!
user: User!
date: Int!
textData: String
ImageDataUrl: String
VideoDataUrl: String
likes: Like
comments: [Comments]
}
#Objects
type Like {
id: ID!
number: Int!
likers: [User]
}
}
type Query {
getAllUsers(limit: Int): [User]
}
type User {
id: ID!
name: String!
email: String! …
Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-dynamodb apollo graphql aws-appsync
我有一个突变:
const createSomethingMutation = gql`
mutation($data: SomethingCreateInput!) {
createSomething(data: $data) {
something {
id
name
}
}
}
`;
Run Code Online (Sandbox Code Playgroud)
如何Something
在一个请求中创建多个?我需要像这样在我的GraphQL服务器上创建一个新的Mutation吗:
mutation {
addManySomethings(data: [SomethingCreateInput]): [Something]
}
Run Code Online (Sandbox Code Playgroud)
还是有一种方法可以createSomethingMutation
在一个请求中多次使用来自Apollo Client的现有方法和不同的参数?
我按照Apollo的安装教程进行操作.而且我完全相信我按照安装教程中的描述完成了所有工作.但是,在项目构建期间,我收到了编译器错误,如:
TypeError:无法读取未定义的属性"length"
Run Code Online (Sandbox Code Playgroud)at Object.yargs.command.command.command.argv [as handler] (/usr/local/lib/node_modules/apollo-codegen/src/cli.js:186:17) at Object.runCommand (/usr/local/lib/node_modules/apollo- codegen/node_modules/yargs/lib/command.js:235:44) at Object.parseArgs [as _parseArgs] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:1013:30) at Object.get [as argv] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:957:21) at Object.<anonymous> (/usr/local/lib/node_modules/apollo-codegen/lib/cli.js:197:5) at Module._compile (module.js:660:30) at Object.Module._extensions..js (module.js:671:10) at Module.load (module.js:573:32) at tryModuleLoad (module.js:513:12) at Function.Module._load (module.js:505:3)
命令/ bin/sh失败,退出代码为1
和
++ exec apollo-codegen生成--schema schema.json --output API.swift
TypeError:无法读取未定义的属性"length"
Run Code Online (Sandbox Code Playgroud)at Object.yargs.command.command.command.argv [as handler] (/usr/local/lib/node_modules/apollo-codegen/src/cli.js:186:17) at Object.runCommand (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/lib/command.js:235:44) at Object.parseArgs [as _parseArgs] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:1013:30) at Object.get [as argv] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:957:21) at Object.<anonymous> (/usr/local/lib/node_modules/apollo-codegen/lib/cli.js:197:5) at Module._compile (module.js:652:30) at Object.Module._extensions..js …
我构建了一个 graphQL 服务器来包装多个 Restful API。我将集成的一些 API 是第三方的,而一些是我们拥有的。我们使用 redis 作为缓存层。如果我在 graphQL 上实现数据加载器缓存可以吗?它会影响我现有的 redis 缓存吗?
我正在尝试使用AWS AppSync JavaScript SDK在Apollo客户端中实现缓存,但我一直在努力了解首先要使用缓存的最佳方法,其次是如果需要进行任何更改以适应Apollo V2教程以与AppSync配合使用,该如何做? SDK。
关于使用缓存,我有一个对象列表,然后我想从该列表中查看和修改单个对象。关于如何更新列表中的某些内容的教程很多,但是我宁愿运行第二个查询,该查询通过其ID获取单个对象,以便该页面始终可以工作,而不必先浏览列表。
缓存是否足够聪明,以至于知道通过查询Y和Z获得的对象X是同一个对象,并且将同时进行更新?如果没有,是否有任何文档说明如何编写将同时更新列表中的对象和本身的更新?
如果没有文档,那么我将自己尝试并发布代码(因为它很可能无法工作)。
关于第二个问题,我已使应用程序正常运行,并使用Amplify进行身份验证来查询API,但不确定如何正确实现缓存。创建客户端时是否需要指定缓存,或者SDK具有内置缓存?如何访问缓存?是否只是像这些教程中那样通过查询客户端?https://www.apollographql.com/docs/react/advanced/caching.html
Hy我正在一个有Apollo GraphQL
方法的项目,它的工作正常。但是现在客户端需要使用Apollo API添加其他标头。但是添加标头后,API的响应将返回unAuthorized。
我将标题添加为
let apolloAuth: ApolloClient = {
let configuration = URLSessionConfiguration.default
// Add additional headers as needed
configuration.httpAdditionalHeaders = ["Authorization" : self.singleTonInstance.token]
configuration.httpAdditionalHeaders = ["channel" : "mobile"]
let url = URL(string: "http://xxx/graphql")!
return ApolloClient(networkTransport: HTTPNetworkTransport(url: url, configuration: configuration))
}()
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我了解如何使用Apollo GraphQL添加标头。
我使用Apollo Express编写了一个简单的GraphQL服务器,并将其部署到Heroku。在弄乱了Procfiles之类的东西之后,它构建成功。
当我点击主URL https://limitless-atoll-59109.herokuapp.com时,我得到了错误
不能获取 /
好的,那我以为Express服务器必须只是在graphql端点上查找get。但是当我点击https://limitless-atoll-59109.herokuapp.com/graphql时,我得到了
缺少GET查询。
我需要在网址中包含端口吗?我在代码中正确设置了端口
const PORT = process.env.PORT || 4000
app.listen({port: PORT}, () =>
console.log(`Server ready at http://localhost:${PORT}${server.graphqlPath}`)
);
Run Code Online (Sandbox Code Playgroud)
但是访问Heroku上的服务器时,我不需要添加它,对吗?
值得的是,这是错误日志中的错误
019-05-08T17:07:41.492327 + 00:00 heroku [router]:at = info method = GET path =“ / graphql” host = limitless-atoll-59109.herokuapp.com request_id = b6171835-aac4-4b45-8a7b -daebbb3167ed fwd =“ 139.47.21.74” dyno = web.1 connect = 0ms服务= 900ms状态= 400字节= 196协议= https
谢谢你的帮助!
apollo ×10
graphql ×7
javascript ×3
graphql-js ×2
ios ×2
react-apollo ×2
aws-appsync ×1
heroku ×1
node.js ×1
react-router ×1
reactjs ×1
redux ×1
redux-thunk ×1
swift ×1