我之前没有任何使用*MQ的经验,而且我希望通常能够构建有关JMS和消息队列的知识.这样,我想知道我是应该从ActiveMQ开始,还是只是"忽略"它,然后开始自学阿波罗.Apollo是否像ActiveMQ一样功能齐全?它是否实现了JMS 2.0(我看到ActiveMQ卡在1.1中)?我会遗漏一些非常重要的东西吗?
另外,Kafka与这两种解决方案相比如何?
如何使用以下查询阻止对Apollo服务器的嵌套攻击:
{
authors {
firstName
posts {
title
author {
firstName
posts{
title
author {
firstName
posts {
title
[n author]
[n post]
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
换句话说,如何限制查询中提交的递归数量?这可能是潜在的服务器漏洞.
我有一个产品页面/products/[slug].js
我对 wordpress/graphql 站点使用增量静态生成:
export async function getStaticProps(context) {
const {params: { slug }} = context
const {data} = await client.query(({
query: PRODUCT_SLUG,
variables: { slug }
}));
return {
props: {
categoryName: data?.productCategory?.name ?? '',
products: data?.productCategory?.products?.nodes ?? []
},
revalidate: 1
}
}
export async function getStaticPaths () {
const { data } = await client.query({
query: PRODUCT_SLUGS,
})
const pathsData = []
data?.productCategories?.nodes && data?.productCategories?.nodes.map((productCategory) => {
if (!isEmpty(productCategory?.slug)) {
pathsData.push({ params: { slug: productCategory?.slug } …
Run Code Online (Sandbox Code Playgroud) 我有一个查询文件,如下所示:
import {gql} from 'react-apollo';
const queries = {
getApps: gql`
{
apps {
id
name
}
}
`,
getSubjects: gql`
{
subjects {
id
name
}
}
`
};
export default queries;
Run Code Online (Sandbox Code Playgroud)
然后我将此文件导入到我的React组件:
import React, {Component} from 'react'
import queries from './queries'
class Test extends Component {
...
}
export default graphql(queries.getSubjects)(graphql(queries.getApps)(Test));
Run Code Online (Sandbox Code Playgroud)
这将只获取其中一个查询(getApps)的数据,而不是两者.如果我一次做一个这样看起来像这样:
export default graphql(queries.getSubjects)(Test);
Run Code Online (Sandbox Code Playgroud)
然后它工作,但我没有我的其他查询.是的,我已经单独测试了它们并且它们有效.如何获取它以便两个查询都显示在我的props.data中?
我正在尝试启动我的 nestJs 服务器,它一直给我这个错误:
UnhandledPromiseRejectionWarning:错误:您必须await server.start()
在调用server.applyMiddleware()
ApolloServer之前
我什至不确定从哪里调试,因为我对 NestJs 和 GraphQL 还是很陌生。
当我运行命令时apollo client:codegen
出现以下错误:
Error: Cannot find module 'graphql/validation/rules/KnownArgumentNamesRule'
Require stack:
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\@apo
llo\federation\dist\composition\validate\preNormalization\tagDirective.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\@apo
llo\federation\dist\composition\validate\preNormalization\index.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\@apo
llo\federation\dist\composition\validate\index.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\@apo
llo\federation\dist\composition\composeAndValidate.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\@apo
llo\federation\dist\composition\index.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\@apo
llo\federation\dist\index.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\apol
lo-language-server\lib\providers\schema\file.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\apol
lo-language-server\lib\providers\schema\index.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\apol
lo-language-server\lib\project\base.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\apol
lo-language-server\lib\index.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\lib\commands\clie
nt\codegen.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\@ocl
if\config\lib\plugin.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\@ocl
if\config\lib\config.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\@ocl
if\config\lib\index.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\@ocl
if\command\lib\command.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\node_modules\@ocl
if\command\lib\index.js
- C:\Users\Minseo\AppData\Roaming\npm\node_modules\apollo\bin\run
Code: MODULE_NOT_FOUND
Run Code Online (Sandbox Code Playgroud) 我正在使用 React、Apollo 和 Next.js 构建一个项目。我正在尝试将 react-apollo 更新到 3.1.3,现在在查看站点时出现以下错误。
不变违规:无法在上下文中找到“客户端”或作为选项传入。将根组件包装在 中,或通过选项传递 ApolloClient 实例。
如果我将 react-apollo 包降级到 2.5.8,它可以正常工作,所以我认为 2.5 和 3.x 之间发生了一些变化,但在 react-apollo 或 next-with-apollo 文档中找不到任何内容来表明那可能是什么。任何帮助将不胜感激。
withData.js
import withApollo from 'next-with-apollo';
import ApolloClient from 'apollo-boost';
import { endpoint } from '../config';
function createClient({ headers }) {
return new ApolloClient({
uri: endpoint,
request: operation => {
operation.setContext({
fetchOptions: {
credentials: 'include'
},
headers
});
},
// local data
clientState: {
resolvers: {
Mutation: {}
},
defaults: {}
}
});
}
export default withApollo(createClient); …
Run Code Online (Sandbox Code Playgroud) 我正在使用<Mutation />
具有Render Prop API的组件并尝试在UI中执行乐观响应.
到目前为止,我在_onSubmit
功能中有这个块-
createApp({
variables: { id: uuid(), name, link },
optimisticResponse: {
__typename: "Mutation",
createApp: {
__typename: "App",
id: negativeRandom(),
name,
link
}
}
});
Run Code Online (Sandbox Code Playgroud)
我的<Mutation />
组件看起来像 -
<Mutation
mutation={CREATE_APP}
update={(cache, { data: { createApp } }) => {
const data = cache.readQuery({ query: LIST_APPS });
if (typeof createApp.id == "number") {
data.listApps.items.push(createApp);
cache.writeQuery({
query: LIST_APPS,
data
});
}
}}
>
{/*
some code here
*/}
</Mutation>
Run Code Online (Sandbox Code Playgroud)
我知道该update
函数在<Mutation …
这是我在这里的第一篇讨论帖子。我通过奥德赛学到了Apollo
+ 。目前,我正在使用Next.js构建自己的项目,该项目需要从 2 个GraphQL 端点获取数据。GraphQL
我的问题:如何使用GraphQL 从多个端点ApolloClient
获取数据?
以下是我的第一个端点的代码:
import { ApolloClient, InMemoryCache, createHttpLink } from "@apollo/client";
const client = new ApolloClient({
ssrMode: true,
link: createHttpLink({
uri: "https://api.hashnode.com/",
credentials: "same-origin",
headers: {
Authorization: process.env.HASHNODE_AUTH,
},
}),
cache: new InMemoryCache(),
});
export default client;
Run Code Online (Sandbox Code Playgroud) 我在 Apollo、GraphQL 和 Nuxtjs 项目中工作,在设置 Apollo 配置时我收到了这个警告:
link.js:38 Error: You are calling concat on a terminating link, which will have no effect
at new LinkError (linkUtils.js:41)
at concat (link.js:38)
at ApolloLink.webpackJsonp../node_modules/apollo-link/lib/link.js.ApolloLink.concat (link.js:65)
at link.js:13
at Array.reduce (<anonymous>)
at from (link.js:13)
at createApolloClient (index.js:58)
at webpackJsonp../.nuxt/apollo-module.js.__webpack_exports__.a (apollo-module.js:66)
at _callee2$ (index.js:140)
at tryCatch (runtime.js:62)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
link.js:38 Error: You are calling concat on a terminating link, which will have no effect
at new LinkError (linkUtils.js:41)
at concat (link.js:38)
at ApolloLink.webpackJsonp../node_modules/apollo-link/lib/link.js.ApolloLink.concat (link.js:65)
at link.js:13 …
Run Code Online (Sandbox Code Playgroud) apollo ×10
graphql ×7
next.js ×3
reactjs ×3
javascript ×2
react-apollo ×2
apache-kafka ×1
caching ×1
graphql-js ×1
jms ×1
nestjs ×1
server ×1
wordpress ×1