我使用 Apollo 设置了一个 React 应用程序,以拥有一个处理从网络加载数据的包装器组件,以便下面的每个组件都可以直接从 Apollo 缓存查询数据,而不必担心处理加载状态。因此,我的组件如下所示:
export const COUNT_OFF_ADAPTER_QUERY = gql`
query CountOffAdapterQuery($vampId: ID!) {
vamp(id: $vampId) @client {
id
countingOff
countingOffStartTime
}
}
`;
export const CountOffAdapter: React.FC<{}> = () => {
const vampId = useCurrentVampId();
const {
data: {
vamp: { countingOff, countingOffStartTime }
}
} = useQuery<CountOffAdapterQuery>(COUNT_OFF_ADAPTER_QUERY, {
variables: { vampId }
});
const prev = usePrevious({ countingOff, countingOffStartTime });
const countOff = useCountOff();
useEffect(() => {
// Do react stuff
}, [countOff, countingOff, prev]);
return …Run Code Online (Sandbox Code Playgroud) 我尝试过但没有成功。出现错误:评估 SSR 模块 /node_modules/cross-fetch/dist/browser-ponyfill.js 时出错:
<script lang="ts">
import fetch from 'cross-fetch';
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client";
const client = new ApolloClient({
ssrMode: true,
link: new HttpLink({ uri: '/graphql', fetch }),
uri: 'http://localhost:4000/graphql',
cache: new InMemoryCache()
});
</script>
Run Code Online (Sandbox Code Playgroud) 自从弃用以来,apollo-server-testing我正在使用与 apollo-server 进行集成测试的新方法(包含在 apollo-server 2.25.0 中)。从突变登录中,我在 OutgoingMessage 标头(在 中'Set-Cookie')中设置了刷新令牌。
@Mutation(() => RefreshTokenOutput)
async refreshToken(@Ctx() { response, contextRefreshToken }: Context): Promise<RefreshTokenOutput> {
if (contextRefreshToken) {
const { accessToken, refreshToken } = await this.authService.refreshToken(contextRefreshToken);
response.setHeader(
'Set-Cookie',
cookie.serialize('refreshToken', refreshToken, {
httpOnly: true,
maxAge: maxAge,
secure: true,
})
);
return { accessToken: accessToken };
} else {
throw new AuthenticationError();
}
}
Run Code Online (Sandbox Code Playgroud)
// given:
const { user, clearPassword } = await userLoader.createUser16c();
const input = new …Run Code Online (Sandbox Code Playgroud) 我更新了我的 nextjs 安装和 apollo,
错误:找不到模块“micro”需要堆栈:
- C:\work\cloud\node_modules\apollo-server-micro\dist\ApolloServer.js
- C:\work\cloud\node_modules\apollo-server-micro\dist\index.js
- C:\work\cloud.next\server\pages\api\auth.js
- C:\work\cloud\node_modules\next\dist\next-server\server\next-server.js
- C:\work\cloud\node_modules\next\dist\server\next.js
- C:\work\cloud\node_modules\next\dist\server\lib\start-server.js
- C:\work\cloud\node_modules\next\dist\cli\next-dev.js
- C:\work\cloud\node_modules\next\dist\bin\next 位于 Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) 位于 Function.mod._resolveFilename (C:\work\cloud \node_modules\next\dist\build\webpack\require-hook.js:4:1855) 在 Function.Module._load (internal/modules/cjs/loader.js:746:27) 在 Module.require (internal/modules) /cjs/loader.js:974:19) 在需要 (internal/modules/cjs/helpers.js:92:18) 在对象。(C:\work\cloud\node_modules\apollo-server-micro\dist\ApolloServer.js:5:17) 在 Module._compile (internal/modules/cjs/loader.js:1085:14) 在 Object.Module 处。 _extensions..js(内部/模块/cjs/loader.js:1114:10)在Module.load(内部/模块/cjs/loader.js:950:32)在Function.Module._load(内部/模块/cjs) /loader.js:790:14) { 代码: 'MODULE_NOT_FOUND', requireStack: [ 'C:\work\cloud\node_modules\apollo-server-micro\dist\ApolloServer.js', 'C:\work\cloud\ node_modules\apollo-server-micro\dist\index.js', 'C:\work\cloud\.next\server\pages\api\auth.js', 'C:\work\cloud\node_modules\next\dist \next-server\server\next-server.js', 'C:\work\cloud\node_modules\next\dist\server\next.js', 'C:\work\cloud\node_modules\next\dist\server \lib\start-server.js', 'C:\work\cloud\node_modules\next\dist\cli\next-dev.js', 'C:\work\cloud\node_modules\next\dist\bin\next ']}
我不确定缺少什么,因为这是在包更新之前工作的 - 阅读在线文档似乎没有对 apollo 服务器微的工作方式进行任何更改?
我刚刚将 NestJs 从 7.5 更新到最新版本(8.3.1),解决了弹出的问题,但我无法摆脱其中之一。
完整错误:
node_modules/@apollo/federation/dist/composition/utils.d.ts:43:316 - error TS2503: Cannot find namespace 'Kind'.
Run Code Online (Sandbox Code Playgroud)
虽然 Kind 是从 GraphQl 模块导入的常量,但它似乎无法识别它。或者也许是打字稿问题?
任何帮助将不胜感激。
我正在尝试对我的 SPA 实施 JWT 身份验证,登录和注销已完成,但我无法找出实施刷新令牌的正确(或只是工作)方法,任何帮助将不胜感激!
我找不到任何有关通过 Vue Appollo 处理刷新令牌的教程。有“ Vue CLI Apollo 插件”
createApolloClient({
...
// Custom pre-auth links
// Useful if you want, for example, to set a custom middleware for refreshing an access token.
preAuthLinks: [],
...})
Run Code Online (Sandbox Code Playgroud)
但没有关于实现它的示例,并且看起来“Vue CLI Apollo 插件”已被弃用,它长时间更新并且无法与 VUE CLI 4 一起使用。
当前的前端堆栈是:
Vue-cli 4.5,
Apollo/client 3.5.8
Vue-apollo-option 4.0.0
Graphql 16.3.0
Vuex 4.0
Run Code Online (Sandbox Code Playgroud)
我的 vue-apollo.js 配置:
import { createApolloProvider } from "@vue/apollo-option";
import { AUTH_TOKEN } from "@/constants/settings";
import {
ApolloClient,
createHttpLink,
InMemoryCache,
ApolloLink, …Run Code Online (Sandbox Code Playgroud) 我正在使用 Apollo SDK,它生成一个 API.swift 文件。我们可以从代码覆盖率中排除这个文件吗
我正在尝试从缓存中读取数据,使用cache.readFragment并订阅更改,就像这样useQuery做一样。我尝试使用useQuerywithfetchPolicy: 'cache-only'但尽管我在缓存中看到我的实体,但数据返回为空。这cache.readFragment正常,但它不订阅,这意味着应用于缓存的任何更改都不会重新触发它。
我怎样才能实现这种行为,并让它在某些内容突变到缓存后立即工作?
// one time read
const data = client.cache.readFragment({
id: client.cache.identify({
__typename: 'Creator',
id: creatorId,
}),
fragment: IS_FOLLOWING_FRAGMENT,
}) as MyCreatorIsFollowing;
Run Code Online (Sandbox Code Playgroud)
// comes back as null although I see it in the cache
const { data } = useQuery(GET_IS_FOLLOW_CREATOR, {
fetchPolicy: 'cache-only',
variables: { id: creatorId },
});
Run Code Online (Sandbox Code Playgroud) 根据https://apollo-angular.com/docs/data/network#file-upload,为了使用 Apollo Angular 上传文件,您必须添加context: {useMultipart: true}到 graphQL 查询中,并将该extractFiles函数添加到 httpLink 创建中。
但是,我不断收到此错误。似乎isExtractableFile没有使用默认功能,我不知道为什么会这样。
这是我的graphql.module.ts:
const uri = environment.graphQLUrl; // <-- add the URL of the GraphQL server here
export function createApollo(httpLink: HttpLink): ApolloClientOptions<any> {
return {
link: httpLink.create({uri, useMultipart: true, extractFiles}),
cache: new InMemoryCache(),
};
}
@NgModule({
exports: [ApolloModule],
providers: [
{
provide: APOLLO_OPTIONS,
useFactory: createApollo,
deps: [HttpLink],
},
],
})
export class GraphQLModule {}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用可可豆荚按照此步骤生成代码。步骤: 5. 使用appolo-ios-cli generate命令设置并运行代码生成我收到此错误:
Error: Cannot query field "getAuthServiceHealth" on type "undefined"
./../NetworkInterface/GraphQL/QueriesList.graphql:2:2
1 | query Health {
2 | getAuthServiceHealth{
| ^
3 | status
Run Code Online (Sandbox Code Playgroud)
查询.graphql:
query Health {
getAuthServiceHealth{
status
service
}
}
Run Code Online (Sandbox Code Playgroud)
架构:
{
"__schema": {
"queryType": {
"name": "Query"
},
"mutationType": null,
"subscriptionType": null,
"types": [
{
"kind": "OBJECT",
"name": "Query",
"description": null,
"fields": [
{
"name": "getAuthServiceHealth",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT", …Run Code Online (Sandbox Code Playgroud) apollo ×10
graphql ×3
ios ×2
node.js ×2
react-apollo ×2
angular ×1
apollo-ios ×1
file-upload ×1
nestjs ×1
next.js ×1
svelte ×1
sveltekit ×1
swift ×1
typescript ×1
vue-apollo ×1
vue-cli ×1
vue.js ×1