AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[graphql](coding)

Martin Hope
nicholaspooran
Asked: 2025-03-28 14:11:14 +0800 CST

如何使用 api 获取基因变异的基于群体的等位基因频率?

  • 6

我正在尝试使用 GraphQL API 从 gnomAD 数据库获取变体详细信息,包括种群等位基因频率 ( af)。但是,查询不会返回种群的等位基因频率。当我af在 下添加时populations,出现以下错误:

GraphQLError: Cannot query field 'af' on type 'VariantPopulation'. Did you mean 'ac' or 'an'?

GraphQL request:10:9
 9 |         populations {
10 |         af
   |         ^
11 |         id

我的疑问:

from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

# GraphQL query to fetch variant details
query = gql(
"""
query VariantsInGene {
    gene(gene_symbol: "PTH", reference_genome: GRCh38) {
        variants(dataset: gnomad_r4) {
            variant_id
            pos
            exome {
                af
                populations {
                    id
                    af
                }
            }
        }
    }
}
"""
)

res = await client.execute_async(query)

我尝试过的:

  • 在外显子组水平获取等位基因频率(af) (工作正常)。
  • 添加af内部populations(导致错误)。
  • 检查可用字段VariantPopulation(建议ac和an,但不建议af)。

问题:

如何在 gnomAD GraphQL 中检索每个人群的等位基因频率 (af ) ?如果我从查询中删除 af,它会执行,但不会检索到人群的 af:

graphql
  • 1 个回答
  • 21 Views
Martin Hope
Earthling
Asked: 2025-01-22 15:59:43 +0800 CST

了解 GraphQL Mutation 以及数据如何传递到输出字段

  • 5

我是 GraphQL 的初学者,正在学习以下示例

https://graphql.com/learn/mutations/

  **Mutation definition:**

         type Mutation {
              updateProducePrice(producePriceInput: UpdateProducePriceInput!): UpdateProducePriceResponse
            }
            
            input UpdateProducePriceInput {
              produceItemId: ID!
              newPrice: Int!
            }
            
            type UpdateProducePriceResponse {
              code: Int!
              success: Boolean!
              message: String!
              produceItem: Produce
            }
    
    
    **Mutation request:**
    
    mutation UpdateProducePrice($producePriceInputVariable: UpdateProducePriceInput!) {
      updateProducePrice(producePriceInput: $producePriceInputVariable) {
        success
        message
        produceItem {
          name
          price
        }
      }
    }
    
    **Variable input:**
    
        {
          "producePriceInputVariable": {
            "produceItemId": "F4",
            "newPrice": 113 
          }
        }

**Response:**

{
  "data": {
    "updateProducePrice": {
      "success": true,
      "message": "Price successfully updated for orange, from 41 to 113",
      "produceItem": {
        "name": "orange",
        "price": 113
      }
    }
  }
}

由于produceItem:Produce在中定义 type UpdateProducePriceResponse ,并且突变返回Produce 类型的name和price(从 41 更新为 113),给定 Id 和 newPrice 作为输入。

newPrice 的值如何传递给 Produce 类型中定义的价格字段?我读过有关解析器的文章,但不明白其内部是如何运作的。

graphql
  • 1 个回答
  • 20 Views
Martin Hope
nik0x1
Asked: 2024-12-07 00:25:57 +0800 CST

GraphQL API 中已弃用的参数(规范 2021)

  • 5

我有一个按照2021 年 10 月的规范描述的 GraphQL API 。

size我有一个想要删除的论点。

type Product {
  picture(size: Int): Url
}

但是如果不在 API 规范中通知消费者,我就不能立即将其删除。我知道工作草案规范允许使用带参数的 @deprecated 指令,但2021 规范不允许这样做。

如何在不违反 2021 规范的情况下以明智的方式删除该字段?

我曾有一个想法,即弃用该字段并在其旁边创建一个具有相同名称但没有参数的字段,但不幸的是这不是一个有效的操作。

graphql
  • 1 个回答
  • 16 Views
Martin Hope
CleverPatrick
Asked: 2024-12-06 20:22:46 +0800 CST

Shopify GraphQL API:使用 2024-10 API 版本创建基本产品并设置价格

  • 5

Shopify GraphQL 变体的旧版本productCreate似乎提供了一个variants字段,您可以在其中设置您正在创建的产品的价格。

截至撰写本文时的最新版本(2024-10)似乎没有此选项。

有没有办法创建仅有一个变体(或没有变体!)的基本产品并通过单一操作设定价格?

如果必须通过两次操作完成呢?正确的第二次突变是什么?

  • productVariantsBulkCreate似乎是一个可行的选择,但名称中的“批量”一词让我想到可能存在更简单的变异。但这似乎是唯一可以让你定价的变异。
graphql
  • 1 个回答
  • 14 Views
Martin Hope
Jan Zapał
Asked: 2024-10-30 17:06:49 +0800 CST

嵌套字段上的 Strawberry GraphQL 过滤器

  • 6

我正在使用 Strawberry GraphQL 和 FastAPI 构建 API。我正在考虑提供带有附加到嵌套字段的过滤器的查询,例如:

query {
  users {
    pets(type: DOG) {
      name
    }
}

但我找不到实现它的方法。我看到的例子是类似的问题通过顶层过滤器解决,例如:

query {
  users(where: {pets: {type: DOG}) {
    pets(type: DOG) {
      name
    }
}

第一个查询是否是 GraphQL 中允许的模式?如果是,如何在 Strawberry 中实现它?

graphql
  • 1 个回答
  • 24 Views
Martin Hope
wallop
Asked: 2024-06-10 08:04:36 +0800 CST

实现是否必须明确提及所有接口字段,或者是否可以按照理解的方式跳过它们?

  • 5

假设存在如下接口?

interface Node {
  id: ID!
  something1: string,
  something2: number
}

是否应该按如下方式实施?

    type User implements Node {
       id: ID!
       something1: string,
       something2: number,
       something3: string
    } 

或者可以如下实现并理解为包含接口字段

type User implements Node {
    something3: string
} 

或者是否有一条规则,只有不可为空的字段必须明确提及,如下所示

type User implements Node {
    id: ID!
    something3: string
}
graphql
  • 1 个回答
  • 11 Views
Martin Hope
Lance
Asked: 2023-12-02 19:20:12 +0800 CST

GraphQL 查询的示例,其中单个记录类型有多个不同的过滤器类型,具体取决于它在查询树中的位置?

  • 4

我正在向 ChatGPT 寻求帮助,深入研究 GraphQL 查询的可能性,因为我正在尝试制作 GraphQL 的 JSON 变体以用于学习目的。我很困惑并且已经困惑了很长一段时间的一件事是如何支持在一个节点上查询输入参数/参数,但在另一个相同类型的节点上不支持查询输入参数/参数。

构建长的 ChatGPT 线程(您不需要阅读本文),假设您有一个像这样的系统:

const resolvers = {
  Query: {
    author: (parent, args) => {
      // Implement logic to fetch an author by ID
    },
    post: (parent, args) => {
      // Implement logic to fetch a post by ID
    },
  },
  Author: {
    posts: (author) => {
      // Implement logic to fetch all posts by this author
    },
  },
  Post: {
    comments: (post) => {
      // Implement logic to fetch all comments for this post
    },
  },
  Comment: {
    author: (comment) => {
      // Implement logic to fetch the author of this comment
    },
  },
};

我试图想象一个图像,其中有类似这样的查询:

query {
  author(id: "1") {
    id
    name
    posts(limit: 10) {
      id
      title
      content
      comments(limit: 10) {
        id
        text
        author {
          id
          name
          posts(createdAtGt: someDate) {
            id
            title
            content
          }
        }
      }
    }
  }
}

或者更复杂的东西。

基本上,我们在这里看到Query.author和Comment.author,所以问题的第一部分是,为什么需要作用域Comment.author,为什么不直接使用Query.author作用域?这不像我们正在做一个Author.posts.comments()作用域,而是有一个顶级Post.comments解析器。

但是,如果我们遇到这样一种情况(我还找不到一个简单清晰的例子),您想以一种方式过滤 的帖子author.posts,但以完全不同的方式过滤comment.author.posts, _并且您不想允许过滤一个上下文中的帖子将用于查询树中另一上下文中的 GraphQL 查询...

你有遇到过这样的情况吗?

基本上我想知道为什么你会选择一个方向而不是另一个方向:

  1. 要么只允许一种类型的过滤在特定类型的所有节点/记录上起作用。
  2. 或者 2,在每个分支级别指定唯一的输入/过滤功能,因此一种类型的记录可能根据其在查询树中的位置具有 10 种不同的过滤机制。

如果(2)发生在更复杂的生产应用程序中,那么您似乎必须在解析器的许多不同位置重新实现大量基本逻辑,然后在需要的地方进行自定义。基本上想知道为什么你不直接构建一个看起来更像这样的解析器(记住我正在集体讨论 GraphQL 的 JSON 替代方案以用于学习目的):

{
  author: {
    resolve(parent, args) {
      // Find author by id
    },
    children: {
      posts: {
        resolve(parent) {
          // find posts by author id, and allow `limit` on the posts query, only here.
        },
        children: {
          comments: {
            resolve(parent) {
              // find comments by post id
            },
            children: {
              author: {
                resolve(parent) {
                  // find author by comment author id
                },
                children: {
                  posts: {
                    resolve(parent) {
                      // find posts by author id, but only allow searching for greater than certain date.
                    }
                  }
                }
              }
            }
          }
        }
      },
      comments: {
        resolve(parent) {
          // now find comments by author id
        },
        children: {
          author: {
            resolve(parent) {
              // maybe here we have different logic and only return authors with a first name starting with "A".
            },
            children: {
              posts: {
                resolve(parent) {
                  // and another variant here too... it can go on more and more custom cases.
                }
              }
            }
          }
        }
      }
    }
  }
}

GraphQL 领域是否发生过类似的事情?如果是这样,要演示的半复杂示例是什么?如果没有,为什么不呢?

graphql
  • 1 个回答
  • 27 Views
Martin Hope
Binho
Asked: 2023-09-17 03:58:26 +0800 CST

Strapi - 从嵌套可重复组件中删除项目

  • 5

我想知道是否可以通过 API 或 graphQL 从嵌套对象中删除项目。我有一个集合类型(餐厅),内部有一个可重复的组件,称为“特许经营”(佛罗里达和纽约)。我只想删除其中之一(例如佛罗里达州)。那可能吗?

API获取

{
    "data": [{
        "id": 2,
        "attributes": {
            "name": "Italian Food",
            "address": null,
            "createdAt": "2023-09-16T19:13:50.831Z",
            "updatedAt": "2023-09-16T19:13:51.632Z",
            "publishedAt": "2023-09-16T19:13:51.629Z",
            "franchise": [{
                "id": 4,
                "state": "Florida"
            }, {
                "id": 5,
                "state": "New York"
            }]
        }
    }],
    "meta": {
        "pagination": {
            "page": 1,
            "pageSize": 25,
            "pageCount": 1,
            "total": 1
        }
    }
}

在此输入图像描述

graphql
  • 1 个回答
  • 13 Views
Martin Hope
Teseu
Asked: 2023-08-20 03:54:29 +0800 CST

Knex 查询 .where() 在 GraphQL 中返回 null

  • 5

我正在尝试使用 knex 和 apollo 服务器构建一个简单的 api,该服务器正在运行,但 where 的查询返回 null

服务器

import { ApolloServer } from 'apollo-server'
import knex from './knex'
import { resolvers, typeDefs } from './schema'
import { UserSQLDataSource } from './schema/users/datasource'

const server = new ApolloServer({
  typeDefs,
  resolvers,
  dataSources: () => {
    return {
      userDb: new UserSQLDataSource(knex),
    }
  },
  uploads: false,
  cors: {
    origin: ['https://studio.apollographql.com'],
    credentials: true,
  },
})

server.listen(4003).then(({ url }) => {
  console.log(`Server listening on url ${url}`)
})

节点指数

const knexFn = require('knex')
const knexfile = require('./knexfile')
const knex = knexFn(knexfile[process.env.NODE_ENV])
module.exports = knex

knex文件

const dotenv = require('dotenv').config()

module.exports = {
  development: {
    client: process.env.DB_CLIENT,
    connection: {
      database: process.env.DB_NAME,
      user: process.env.DB_USER,
      password: process.env.DB_PASS,
    },
    pool: {
      min: 2,
      max: 10,
    },
    migrations: {
      tableName: process.env.MIGRATION_NAME,
    },
  },
}

数据源

import { DataSource } from 'apollo-datasource'
import { InMemoryLRUCache } from '@apollo/utils.keyvaluecache'
import DataLoader from 'dataloader'

export class SQLDatasource extends DataSource {
  constructor(knex, tableName) {
    super()
    this.db = knex
    this.tableName = tableName
    this._loader = new DataLoader(async ids => this.batchLoaderCallback(ids))
  }

  initialize({ context, cache }) {
    this.context = context
    this.cache = cache || new InMemoryLRUCache()
  }

  async batchLoad(id) {
    return this._loader.load(id)
  }

  async batchLoaderCallback(_ids) {
    return _ids
  }
}

带有查询 getUser 日志的用户数据源

import { SQLDatasource } from '../../schema/datasources'

export class UserSQLDataSource extends SQLDatasource {
  constructor(knex) {
    super(knex, 'users')
  }

  async getUsers() {
    return await this.db(this.tableName)
  }

  async getUser(id) {
    try {
      const query = this.db(this.tableName).where({ id: id })
      console.log(query.toSQL())

      return await query
    } catch (error) {
      console.error(error)
      throw error
    }
  }
}

查询的日志

Server listening on url http://localhost:4003/
{
  method: 'select',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ '1' ],
  __knexQueryUid: 'sH05Z4l3pgdNm5mY9YPkeu6',
  sql: 'select * from `users` where `id` = ?'
}

用户类型定义

import { gql } from 'apollo-server'

export const userTypeDefs = gql`
  extend type Query {
    user(id: ID!): User!
    users: [User!]!
  }

  type User {
    id: ID!
    firstName: String!
    lastName: String!
    userName: String!
    email: String!
    password_hash: String!
    token: String!
    createdAt: String!
    updatedAt: String!
  }
`

用户解析器

const users = async (_, { input }, { dataSources }) => {
  const users = await dataSources.userDb.getUsers(input)
  return users
}

const user = async (_, { id }, { dataSources }) => {
  const user = await dataSources.userDb.getUser(id)
  return user
}

export const userResolvers = {
  Query: { user, users },
}

不带 where、所有用户的查询返回 ok,带 where 的查询,使用 id 作为参数,或更改为其他列(名字、电子邮件等)始终返回 null。

我对查询做了一些更改,更改参数,结果相同。我不知道当前版本的所有组件是否有问题,package.json 是这样的

{
  "name": "mysql",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "sucrase": "./src -d ./Dir --transforms imports",
    "knex": "npx knex --cwd ./src/knex",
    "knex-h": "npx knex --help",
    "dev": "nodemon -e js src/index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "apollo-server": "^3.12.0",
    "dataloader": "^2.2.2",
    "datasource-sql": "^2.1.0",
    "dotenv": "^16.3.1",
    "graphql": "^16.8.0",
    "knex": "^2.5.1",
    "mysql2": "^3.6.0",
    "path": "^0.12.7"
  },
  "devDependencies": {
    "eslint": "^8.47.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.0",
    "nodemon": "^3.0.1",
    "prettier": "^3.0.2",
    "sucrase": "^3.34.0"
  }
}
graphql
  • 1 个回答
  • 12 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve