标签: apollo

如何在 Strapi、GraphQL 中的 where 子句中使用多个“and”条件进行查询?

现在我尝试在 Strapi GraphQL 游乐场中的位置内使用多个 _and 进行查询。我正在使用的查询是:

 {
  clients(
    where: {
      _and: [{ name: { _contains: "a" } }, { endDate: { _gte: "2017-12-31" } }]
    }
  ) {
    id
    name
    endDate
    reasonForEnding
  }
}
Run Code Online (Sandbox Code Playgroud)

但出现错误提示如下:

 "Error: Your filters contain a field '_and' that doesn't appear on your model definition nor it's relations".
Run Code Online (Sandbox Code Playgroud)

如何使用 GraphQL 在 Strapi 中使用多个 _and 条件 where 子句正确进行查询

where-clause apollo graphql strapi angular

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

如何在 apollo graphQL 服务器中的枚举值中添加特殊字符?

我在 apollo-graphQL 中的枚举类型有问题,我在 nodejs 中使用 apollo-server 。问题是我无法使用具有像 image/jpeg 或 svg+xml 这样的值的字符串。它给我带来了错误,这些值无法解析为枚举。

枚举值

在此输入图像描述

有人可以告诉我如何解决这个问题吗?

enums node.js apollo graphql apollo-server

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

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
查看次数

apollo-server-micro:响应缺少标头“access-control-allow-methods:POST”

在我的next.js应用程序中,我尝试配置 Apollo 端点:

import { ApolloServer, gql } from "apollo-server-micro";

// This data will be returned by our test endpoint. Not sure if I need id? https://apuyou.io/blog/serverless-graphql-apollo-server-nextjs
const tacos = {
  meat: [
    {
      type: 'Al Pastor',
      imgURL: 'https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/190130-tacos-al-pastor-horizontal-1-1549571422.png?crop=0.668xw:1.00xh;0.175xw,0&resize=480:*'
    },
    {
      type: 'Barbacoa',
      imgURL: 'https://i2.wp.com/www.downshiftology.com/wp-content/uploads/2021/02/Barbacoa-Tacos-3.jpg'
    },
    {
      type: 'Chorizo',
      imgURL: 'https://www.seriouseats.com/thmb/-8LIIIObcZMUBy-9gXlMsHcaeMI=/610x458/filters:fill(auto,1)/__opt__aboutcom__coeus__resources__content_migration__serious_eats__seriouseats.com__recipes__images__2014__04__20140428-sloppy-joe-chorizo-taco-recipe-food-lab-lite-8-503212a07b0a4d499952ff40aed57694.jpg'
    },
  ],
  fish: [
    {
      type: 'Camaron',
      imgURL: 'https://juegoscocinarpasteleria.org/wp-content/uploads/2019/07/1563435179_315_Tacos-De-Camarones-Con-Crema-De-Cal-Y-Cilantro.jpg'
    },
    {
      type: 'Salmon',
      imgURL: 'https://www.cookingclassy.com/wp-content/uploads/2015/04/salmon-tacos-with-avocado-salsa4-srgb..jpg'
    },
    {
      type: 'Pulpo',
      imgURL: 'https://images.squarespace-cdn.com/content/v1/5710a8b3e707ebb8c58fea2c/1590075315244-QNXQE1LGPH06HV3EDF6B/tacos_34.jpg?format=1000w'
    },
  ],
  veggi: [
    {
      type: …
Run Code Online (Sandbox Code Playgroud)

apollo apollo-server react-apollo next.js

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

停止“useMutation”重新渲染组件并忽略结果

我有一个像这样的突变(这不是实际的突变调用,而是一个最小的例子):

const App = () => {
  const [myMutation] = useMutation(gql`
    mutation Test($updateUserId: ID!, $updateUserInput: UpdateUserInput!) {
      updateUser(id: $updateUserId, input: $updateUserInput) {
        id
        firstname
        age
      }
    }
  `);

  // Runs every time this component is rendered
  console.log("rendered");

  // Called when the button is clicked
  const update = () => {
    myMutation({
      variables: {
        updateUserId: 1,
        updateUserInput: {
          age: Math.round(Math.random() * 10 + 5) // Set a random age from 5 - 15
        }
      }
    });
  };

  return (
    <>
      <h1>Update …
Run Code Online (Sandbox Code Playgroud)

apollo reactjs apollo-client

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

Lodash Debounce 和 Apollo Client useLazyQuery debounce 一次

当尝试调用_.debounce(fn, wait);apollo-client 调用useLazyQuery(...)时,它会第一次对查询进行反跳,然后调用查询函数,但此后它会在每次更改时继续调用查询,而不会发生任何反跳。

但是,如果我使用 aconsole.log(...)而不是调用,useLazyQuery(...)它将完美地工作。

第一次工作,但随后立即调用该函数,没有任何去抖:

const [value, setValue] = useState('');

const [search, { loading, data }] = useLazyQuery(SEARCH_QUERY, { variables: { searchString: value } });

const debouncer = React.useCallback(_.debounce(search, 1500), []);

...
<call to debouncer() with onChange event>
Run Code Online (Sandbox Code Playgroud)

每次都完美运行:

const [value, setValue] = useState('');

const [search, { loading, data }] = useLazyQuery(SEARCH_QUERY, { variables: { searchString: value } });

const debouncer = React.useCallback(_.debounce(val => (console.log(val)), 1500), []);

...
<call to debouncer() …
Run Code Online (Sandbox Code Playgroud)

javascript apollo lodash reactjs graphql

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

Apollo GraphQL 动态认证子图

我正在构建一个带有联合模式的 Apollo 网关 - 并且我有许多子图 - 每个子图都有自己的身份验证令牌(例如许多 REST API,每个用户在每个 REST API 的数据库中保存了自己的令牌)。

我正在为网关中的每个用户的每个 REST API 获取令牌,以减少每个子图的过载并检查网关级别的权限,但我正在努力解决如何将凭据从网关传递到每个子图的问题。

我遇到了这个答案,但是,在这里他正在构建自己serviceList,而我正在使用 Apollo Federation - 并且网关对象无法访问,serviceMap因为它在 Typescript 定义下是私有的 - 这是一种非常黑客的方式实现它的方法:

class RequestHander extends RemoteGraphQLDataSource {
    willSendRequest({ request }: { request: GraphQLRequest }) {
        // if request.http.url matches url of a service which you
        // use, add api-key to headers, e.g.
        if (request.http.url === 'http://localhost:3001') {
            request.http.headers.set('api-key', <API_KEY>)
        }
    }
}

const main = () => {
    const gateway = …
Run Code Online (Sandbox Code Playgroud)

apollo graphql graphql-js apollo-server apollo-federation

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