标签: graphql-js

如何在apollo-client查询中全局设置fetchPolicy?

我有一些突变应该触发一些refetchQueries,但我需要这些查询有一个fetchPolicy而不是默认值.

有没有办法全局设置fetchPolicy而不是每个查询?因此,要避免在每个查询上设置fetchPolicy.

graphql-js react-apollo apollo-client

12
推荐指数
1
解决办法
2024
查看次数

使用Facebook的DataLoader传递参数

我正在使用DataLoader将请求/查询一起批处理.在我的加载器功能中,我需要知道所请求的字段,以避免有一个SELECT * FROM query而是SELECT field1, field2, ... FROM query...

使用DataLoader传递resolveInfo所需的最佳方法是什么?(我resolveInfo.fieldNodes用来获取请求的字段)

目前,我正在做这样的事情:

await someDataLoader.load({ ids, args, context, info });
Run Code Online (Sandbox Code Playgroud)

然后在实际的loaderFn中:

const loadFn = async options => {
const ids = [];
let args;
let context;
let info;
options.forEach(a => {
    ids.push(a.ids);
    if (!args && !context && !info) {
        args = a.args;
        context = a.context;
        info = a.info;
    }
});

return Promise.resolve(await new DataProvider().get({ ...args, ids}, context, info));};
Run Code Online (Sandbox Code Playgroud)

但正如你所看到的那样,这很黑,而且感觉并不好......

有谁知道我怎么能做到这一点?

javascript graphql graphql-js

12
推荐指数
1
解决办法
758
查看次数

buildSchema和makeExecutableSchema之间有什么区别

是什么区别buildSchema来自graphql包和makeExecutableSchemagraphql-tools包.

apollo graphql graphql-js

12
推荐指数
1
解决办法
3067
查看次数

Graphql - 如何执行where子句

我是graphql的新手,我正在努力查询.我想通过他们的电子邮件地址返回用户

我有一个类型定义的调用V1User,它有以下字段id,email,password,role

在此查询中需要更改哪些内容才能根据电子邮件返回用户?

    query GetAllV1User {
  viewer {
     allV1Users{
      edges {
        node {
          id
          email
          role
          createdAt
          modifiedAt
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我试过这个查询

    query getV1UserQuery($email: String!) {
  getV1User(email: $email) {
    id
    email
  }
}
Run Code Online (Sandbox Code Playgroud)

有了这些参数

{"email": "test@test.com"}
Run Code Online (Sandbox Code Playgroud)

但是得到以下错误

    {
  "errors": [
    {
      "message": "Unknown argument \"email\" on field \"getV1User\" of type \"Query\".",
      "locations": [
        {
          "line": 2,
          "column": 13
        }
      ],
      "name": "GraphQLError"
    },
    {
      "message": "Field \"getV1User\" argument \"id\" of type \"ID!\" is required but not provided.",
      "locations": …
Run Code Online (Sandbox Code Playgroud)

graphql graphql-js

12
推荐指数
2
解决办法
1万
查看次数

包 apollo-link-http 中的 new HttpLink 和 createHttpLink 之间的差异

在教程中

https://www.howtographql.com/vue-apollo/1-getting-started/

有提供的new HttpLink语法,但在官方文档中

https://www.apollographql.com/docs/link/links/http/

函数createHttpLink被应用。

这两个来源都没有描述这些方法之间的差异。

apollo graphql-js apollo-client

12
推荐指数
1
解决办法
3008
查看次数

GraphQL突变变量

我正在尝试使用GraphQL与GraphiQL接口进行简单的变异.我的突变看起来像这样:

mutation M($name: String) {
  addGroup(name:$name) {
    id,
    name
  }
}
Run Code Online (Sandbox Code Playgroud)

变量:

{
  "name": "ben"
}
Run Code Online (Sandbox Code Playgroud)

但它给了我错误: Variable $name of type "String" used in position expecting type "String!"

如果我改变我的突变mutation M($name: String = "default")它按预期工作.这看起来与类型系统有关,但我似乎无法弄清楚问题是什么.

graphql graphql-js

11
推荐指数
1
解决办法
5919
查看次数

有没有办法从protobuf生成GraphQL架构?

我有一个相当大/复杂的protobuf定义的API,我想知道是否有一个方便的工具,从这个protobuf的子集自动生成文本GraphQL架构及其(嵌套)类型?

我正常使用Node.js,但我开放其他语言来生成模式.提前致谢!

javascript protocol-buffers node.js graphql graphql-js

11
推荐指数
2
解决办法
4503
查看次数

如何将扩展从一台服务器转发到中间件服务器

我在我的middlware服务器上使用远程架构拼接.我能够在中间件服务器上远程获取架构,在中间件服务器上定义我的路由.

app.use('/graphql', graphqlHTTP((request,res) => {
 const startTime = Date.now();
 return {
   schema: remoteSchema
   graphiql: false,
   extensions({ document, variables, operationName, result }) {
     return {
       // here I am not getting extensions which I have on my another server as below.
       console.log(res); // this does not have additional info and response headers
       console.log(result); // this only has response against the query
     }
   };
})); 
Run Code Online (Sandbox Code Playgroud)

我在结果中得到查询的结果,但没有得到响应标题和附加信息,这是我在其他解析器所在的其他服务器上添加的扩展的一部分.

{
    "data": {
        "records": {
            "record": [{
                    "id": 1,
                },
                {
                    "id": 2,
                }
            ],
        }, …
Run Code Online (Sandbox Code Playgroud)

node.js express graphql graphql-js express-graphql

11
推荐指数
1
解决办法
309
查看次数

如何从数据库中获取用于在 Graphql 中进行分页的游标?

我在获取真正的游标以解决 GraphQL 中的数据库分页结果时遇到了可怕的问题。无论我使用哪种数据库(SQL 例如 mysql 或 NoSQL 文档例如 mongodb),我都没有办法,我似乎能够获得游标或类似游标的对象。

可能我错过了一些基本概念,但是在搜索了我的 b 之后......关闭我开始严重怀疑官方的 GraphQL 分页文档

https://graphql.org/learn/pagination/

完全基于任何真实的现场体验。

这是我的问题:我怎样才能从这样的 SQL 查询中获得任何与游标相似的东西?

SELECT authors.id, authors.last_name, authors.created_at FROM authors
ORDER BY authors.last_name, author.created_at
LIMIT 10
OFFSET 20
Run Code Online (Sandbox Code Playgroud)

我知道,不应使用基于偏移量的分页,而是将基于光标的导航视为一种补救措施。而且我绝对想治愈我的应用程序中的胶印病。但是为了做到这一点,我需要能够从某处检索游标。

我也明白(忘了我在哪里读到的)主键也不应该用于分页。

所以,我被困在这里。

database cursor-position resolver graphql graphql-js

11
推荐指数
1
解决办法
1150
查看次数

GraphQL将args传递给sub解析

我和User之间有关系.这是我查询用户帖子的方式.

const UserType = new GraphQLObjectType({
  name: 'User'
  fields: () => ({
    name: {
      type: GraphQLString
    },
    posts: {
      type: new GraphQLList(PostType),
      resolve(parent, args , { db }) {
        // I want to get here the args.someBooleanArg
        return someLogicToGetUserPosts();
      }
    }
  })
});
Run Code Online (Sandbox Code Playgroud)

主要查询是:

const queryType = new GraphQLObjectType({
  name: 'RootQuery',
  fields: {
    users: {
      type: new GraphQLList(UserType),
      args: {
        id: {
          type: GraphQLInt
        },
        someBooleanArg: {
          type: GraphQLInt
        }
      },
      resolve: (root, { id, someBooleanArg }, { db }) …
Run Code Online (Sandbox Code Playgroud)

graphql graphql-js

10
推荐指数
1
解决办法
5324
查看次数