我目前正在尝试使用 useEffect 挂钩中 apollo v3 的 useSubscription 挂钩来更新 GraphQL 订阅:
let containerSubscription = useSubscription<CreatedDateSubscription, CreatedDateSubscriptionVariables>(
gql(containerUpdatedOnCreatedDate),
{
variables: { createdDate: selectedDate },
shouldResubscribe: true, // is this needed?
},
);
// update subscription on date change
React.useEffect(() => {
// how do I update the subscription here?
// setting containerSubscription.variables = ... does not change the subscription
}, [selectedDate]);
Run Code Online (Sandbox Code Playgroud)
我在阿波罗文档中找不到有关如何解决此问题的任何解决方案。
任何帮助,将不胜感激!
我在 Android 项目中使用 Apollo 客户端。我有 2 个架构文件,并将它们放在 2 个不同的目录中。
但是当我构建一个项目来通过 Apollo 生成代码时,它给了我一个错误:
ApolloGraphQL: By default, only one schema.json file is supported.
并建议我使用多个服务 构建输出:
ApolloGraphQL: By default, only one schema.json file is supported. Please use multiple services instead:
apollo {
service("search") {
sourceFolder = "/.../app/src/main/graphql/com/example/data/search"
}
service("customer") {
sourceFolder = "/.../app/src/main/graphql/com/example/data/customer"
}
}
Run Code Online (Sandbox Code Playgroud)
我还将其添加到我的build.gradle(应用程序级别)文件中,但仍然显示相同的构建错误。
请建议我如何解决这个错误
我正在尝试使用Nuxt Apollo进行 websocket 订阅。对于我的服务器(8base.com),我需要connectionParams随订阅请求一起发送一个对象。
似乎 Nuxt Apollo 有一个httpLinkOptions,但我真正需要的是一个wssLinkOptions. 有人知道用 Nuxt 做到这一点的方法吗?理想情况下,我不必替换 Nuxt Apollo,因为我在整个应用程序中都使用它。
我正在尝试将文件从前端应用程序上传到服务器,但我不断收到这个奇怪的错误,并且不知道为什么会发生这种情况。
错误是前端:
Variable "$file" got invalid value {}; Expected type Upload. Upload value invalid.
Run Code Online (Sandbox Code Playgroud)
后台报错:
GraphQLError: Upload value invalid.
at GraphQLScalarType.parseValue (/app/backend/node_modules/graphql-upload/lib/GraphQLUpload.js:66:11)
Run Code Online (Sandbox Code Playgroud)
这就是我添加上传标量的方法
Variable "$file" got invalid value {}; Expected type Upload. Upload value invalid.
Run Code Online (Sandbox Code Playgroud)
这就是我在 React/NextJS 应用程序中制作 uplaod 客户端的方法
GraphQLError: Upload value invalid.
at GraphQLScalarType.parseValue (/app/backend/node_modules/graphql-upload/lib/GraphQLUpload.js:66:11)
Run Code Online (Sandbox Code Playgroud)
即使当尝试使用前端应用程序以外的其他东西运行突变时,我也会遇到相同的错误,所以我猜问题出在我的后端设置上,尽管我搜索了很多方法来做到这一点似乎都不起作用。
src/another_folder/reactiveVarInitializationFile.js 从“@apollo/client”导入 {makeVar}
导出 const selectStore = makeVar('')
//我的组件
import {Select,Spin} from "antd"
import {selectStore} from "../../reactives/selectStore.RV"
import {useQuery} from "@apollo/client"
import FETCH_STORES from "../../queries/getStoresSelectSoreDPD"
export default function(){
const {data}= useQuery(FETCH_STORES)
const store = selectStore()
const onChange=(val)=>{
console.log(val)
selectStore(val)
}
console.log(store)
return(
<>
{!data?(<Spin/>):(
<Select
style={{width:"200px"}}
placeholder="Select store"
onChange={onChange}>
{data.currentUser.outlets.map(el=><Select.Option key={el.id} value={el.id}>{el.name}
</Select.Option>)}
</Select>
)}
<p>{store}</p>
</>
)
}
Run Code Online (Sandbox Code Playgroud)
问题是当我将 selectStore 导入到我的组件中时,我无法通过 selectStore() 获取其值或通过执行 selectStore("new value") 修改 var
有人可以帮我吗?
我正在开发一个微前端应用程序。我们正在构建一个库来管理所有用户数据、权限、角色等。
<ApolloProvider client={userManagementClient}>
{children}
</ApolloProvider>
Run Code Online (Sandbox Code Playgroud)
这将在许多应用程序中使用,它看起来像这样:
<ApolloProvider client={appClient}>
<UserManagementProvider><App /></UserManagementProvider>
</ApolloProvider>
Run Code Online (Sandbox Code Playgroud)
问题是应用程序的 ApolloProvider 不起作用,因为查询是针对图书馆的数据源而不是应用程序进行的。
有谁知道嵌套或多个 ApolloProvider 的方法吗?
我使用 apollo 作为我的客户端,并且在我的应用程序上运行了大量查询和突变。我想知道是否有一种方法可以让我的每个查询/突变按其名称(例如 getProduct)显示,而不是在我的网络选项卡中全部显示为“图形”?我使用的是 Brave(Chromium)。
如果我不必单击每个请求并检查标头或响应来确定该请求对应于哪个查询或突变,那么调试会更容易。
这是它目前在我的开发工具中的显示方式:
多谢!
我正在使用 GraphQL 在两个域客户端和服务器之间进行通信。我已按照vercel 文档在我的 API 网站上启用了 CORS ,但它似乎引发了blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.错误。我在 GraphQL 中有这样的代码:
function createApolloClient() {
return new ApolloClient({
ssrMode: typeof window === "undefined",
link: new HttpLink({
uri: <link>,
credentials: "include",
fetchOptions: {
mode: "cors",
},
}),
}),
...
}
Run Code Online (Sandbox Code Playgroud)
在API网站中,该next.config.js文件有这样的内容:
module.exports = {
async headers() {
return [
{
// matching all API routes
source: "/api/:path*",
headers: …Run Code Online (Sandbox Code Playgroud) 我喜欢 graphql。因为它只有一个端点,我只能提取我需要的数据。
所以我使用 apollo-server 作为服务器,使用 apollo-client 作为客户端。
从 apollo-client 3.0 开始,支持状态管理。
apollo-client的reactive变量功能很方便,但我更喜欢redux。
Redux工具包还缩短了需要编写的代码长度。
问题是这样的。
apollo-client 3.0 和 redux 不能一起使用吗?
我不能在 redux 上只使用 graphql 而不使用 apollo-client 吗?那么如何呢?
请检查!
const { ApolloServer, gql } = require('apollo-server');
// A schema is a collection of type definitions (hence "typeDefs")
// that together define the "shape" of queries that are executed against
// your data.
const typeDefs = gql`
# Comments in GraphQL strings (such as this one) start with the hash (#) symbol.
# This "Book" type defines the queryable fields for every book in our data source.
type Book {
title: String
author: String
}
# The "Query" type is …Run Code Online (Sandbox Code Playgroud) apollo ×10
graphql ×6
reactjs ×3
react-apollo ×2
android ×1
cors ×1
devtools ×1
graphql-java ×1
next.js ×1
nexus-prisma ×1
node.js ×1
nuxt.js ×1
prisma ×1
react-gql ×1
react-hooks ×1
redux ×1
subscription ×1
websocket ×1