标签: apollo

Apollo 客户端 MockedProvider:跳过加载状态

我使用 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)

typescript apollo react-apollo apollo-client

5
推荐指数
1
解决办法
1382
查看次数

如何在 SvelteKit 中初始化 ApolloClient 以在 SSR 和客户端上工作

我尝试过但没有成功。出现错误:评估 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 svelte sveltekit

5
推荐指数
1
解决办法
3660
查看次数

使用 Apollo Server (apollo-server) 上的executeOperation 获取标头以进行集成测试

自从弃用以来,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)

apollo graphql apollo-server

5
推荐指数
1
解决办法
2785
查看次数

更新到 nextjs 11 后的 Micro MODULE_NOT_FOUND

我更新了我的 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 服务器微的工作方式进行任何更改?

node.js apollo apollo-server next.js

5
推荐指数
1
解决办法
4028
查看次数

我需要有关“找不到命名空间种类”问题的帮助

我刚刚将 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 模块导入的常量,但它似乎无法识别它。或者也许是打字稿问题?

任何帮助将不胜感激。

node.js apollo nestjs

5
推荐指数
1
解决办法
904
查看次数

Vue Apollo自动刷新令牌实现

我正在尝试对我的 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 vue.js apollo-client vue-cli vue-apollo

5
推荐指数
0
解决办法
861
查看次数

从 XCode 代码覆盖范围中排除 swift 文件

我正在使用 Apollo SDK,它生成一个 API.swift 文件。我们可以从代码覆盖率中排除这个文件吗

ios apollo swift apollo-ios

5
推荐指数
1
解决办法
4401
查看次数

Apollo客户端,订阅fragment

我正在尝试从缓存中读取数据,使用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)

apollo react-apollo apollo-client

5
推荐指数
0
解决办法
129
查看次数

“错误错误:参数 2 `isExtractable` 必须是一个函数。” 使用 Apollo Angular 上传文件时

根据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)

file-upload apollo graphql apollo-client angular

5
推荐指数
1
解决办法
395
查看次数

Apollo iOS 客户端代码生成:“错误:无法查询字段”

我正在尝试使用可可豆荚按照此步骤生成代码。步骤: 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)

ios apollo graphql apollo-client

5
推荐指数
1
解决办法
480
查看次数