我正在尝试优化在整个应用程序中共享的一些反应组件(例如页脚和页眉组件)执行的查询。
institutionPath当未提供变量时,我试图不获取学生解决方案详细信息。
query organisationAndInstitution($organisationName: String!, $institutionPath: String!, $fetchInstitution: Boolean!){
organisation(where: {
name: $organisationName
}){
name
}
studentSolutionRelationships(where:{
AND: [
{
status: PUBLISHED
},
{
studentSolution: {
status: PUBLISHED
}
}
]
}) @include(if: $fetchInstitution) {
status
}
}
Run Code Online (Sandbox Code Playgroud)
为此,我添加了一个fetchInstitution布尔变量并添加了@include(if: $fetchInstitution)指令。
但指令似乎仅适用于字段,而不适用于整个查询。所以我想知道我想做的是否可能,因为我写的方式是无效的。
我必须使用的其余 api 提供多个端点上的数据。结果中的对象可能具有 api 无法直接解析的关系,而是提供指向实际资源的 id。
示例:
为了简单起见,假设一个Person可以拥有多个Books.
现在api/person/{i}端点返回:
{ id: 1, name: "Phil", books: [1, 5, 17, 31] }
Run Code Online (Sandbox Code Playgroud)
端点api/book/{i}返回此(请注意,作者可能又是一个关系):
{ id: 5, title: "SPRINT", author: 123 }
Run Code Online (Sandbox Code Playgroud)
有什么方法可以教 apollo 客户端以我可以编写以下(或类似)查询的方式解析这些端点:
query fetchBooksOfUser($id: ID) {
person (id: $id) {
name,
books {
title
}
}
}
Run Code Online (Sandbox Code Playgroud) 我将 NextJS 与 Material UI 和 Apollo 结合使用。虽然一切正常,但警告没有消失。在我看来,很多 Material UI 组件都在使用useLayoutEffect,这是 React 发出的警告。错误如下。
警告:useLayoutEffect 在服务器上不执行任何操作,因为它的效果无法编码为服务器渲染器的输出格式。这将导致初始的、非水合的 UI 与预期的 UI 之间不匹配。为了避免这种情况,useLayoutEffect 应该只在专门在客户端渲染的组件中使用。请参阅 fb.me/react-uselayouteffect-ssr 了解常见修复。
material-ui server-side-rendering react-apollo next.js react-hooks
我试图在网络状态正在进行时显示预加载器。
我知道每个查询都会返回自己的网络状态,但在我的应用程序中有很多不同的查询。我希望有一种方法可以在全球范围内处理所有查询的所有网络状态。
我想在代码中了解以下问题的答案:“网络上是否有任何待处理的查询?”。
我在 Express 上有 Apollo Graph 的后端。
在我的客户端 React 应用程序中,我下一步要做的是:
apollo codegen:generate --excludes=node_modules/* --includes=**/*.tsx --target typescript --tagName gql --outputFlat generate
Run Code Online (Sandbox Code Playgroud)
我等待生成文件夹,但此命令给出了下一个错误:
Error: There are multiple definitions for the herewas operation.
All operations in a project must have unique names.
If generating types, only the types for the first definition
found will be generated.at GraphQLClientProject.checkForDuplicateOperations
(....\node_modules\apollo\node_modules\apollo-language-server\lib\project\base.js:129:31)
.........
.........
Generating query files with 'typescript' target
> Apollo does not support anonymous operations
Run Code Online (Sandbox Code Playgroud)
我还有 apollo.config.js:
module.exports = {
client: {
service: {
url: "http://localhost:4000/graphql" …Run Code Online (Sandbox Code Playgroud) 我正在尝试从缓存中获取一些数据。在初始重新加载时,数据道具返回未定义,但如果我快速重新加载应用程序(反应本机快速重新加载)数据道具具有我想要的值。我不明白为什么它在初始重新加载中返回未定义。一种情况可能是我在初始化缓存之前调用查询。我已经控制台了本地缓存,它显示了值,但查询正在重新调整未定义。
我在 client.js 中的客户端设置
const dev = {
base_url: BASE_URL
};
const httpLink = createHttpLink({
uri: dev.base_url
});
const errorLink = onError(({ graphQLErrors, networkError, response }) => {
if (graphQLErrors) {
// do something with graphql error
console.log(graphQLErrors);
}
if (networkError) {
// do something with network error
console.log(networkError);
// console.log('network not available');
}
if (response) {
console.log(response);
}
});
const cache = new InMemoryCache();
const setupPersistedCache = async () => {
const persistor = new CachePersistor({
cache,
storage: AsyncStorage …Run Code Online (Sandbox Code Playgroud) 我有表格原则和标签。并且它们之间存在多对多关系(隐式连接)。
如果不使用prisma.raw,我如何运行以下查询?
SELECT p.id, p.title, p.description, p.createdAt, p.modifiedAt
FROM principle p
WHERE EXISTS (SELECT NULL
FROM _PrincipleToTag pt
WHERE pt.B IN (${tagIds.join(',')})
AND pt.A = p.id
GROUP BY pt.A
HAVING COUNT(DISTINCT pt.B) = ${tagIds.length})
Run Code Online (Sandbox Code Playgroud)
如何更新此 Prisma 2 查询,以便返回的原则仅是与所有提供的 tagId 关联的原则?
export const principles = ({ tagIds }) => {
const payload = {
where: {
//TODO filter based on tagIds
},
}
return db.principle.findMany(payload)
}
Run Code Online (Sandbox Code Playgroud)
文档提到了containsandin和every,但我找不到我想要做的事情的例子。
我正在使用 RedwoodJs、Prisma 2、Apollo、GraphQL。 …
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 的方法吗?
我有以下组件,它有一个date变量。每次重新渲染时,date变量都会更新。现在的问题是,当我将日期分配给查询变量时,graphql 会无限地一次又一次地获取。我调试了代码,发现apollo是在观察date变量,当它接收到新值时,它会重新执行。
import React from 'react';
import { getISODate } from '../../dateUtils';
import { useQuery } from '@apollo/react-hooks';
import { GET_EXPENSE_STATUS } from '../../queries';
import get from 'lodash/get';
const ExpenseStatus = (props) => {
const date = getISODate(); // returns current date as ISO String Format
const { loading, error, data } = useQuery(GET_EXPENSE_STATUS, {
variables: {
date
}
});
if (error) return <p>Error :(</p>;
return(
<div>
{get(data, 'expenseStatus.value')}
</div>
);
};
Run Code Online (Sandbox Code Playgroud)
我也尝试过useLazyQuery …
react-apollo ×10
graphql ×5
apollo ×4
reactjs ×4
javascript ×1
material-ui ×1
networking ×1
next.js ×1
prisma ×1
react-gql ×1
react-hooks ×1
react-native ×1
redwoodjs ×1
typescript ×1