pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<tfoot id='OY0Ar'></tfoot>
<legend id='OY0Ar'><style id='OY0Ar'><dir id='OY0Ar'><q id='OY0Ar'></q></dir></style></legend>
        <bdo id='OY0Ar'></bdo><ul id='OY0Ar'></ul>
      <i id='OY0Ar'><tr id='OY0Ar'><dt id='OY0Ar'><q id='OY0Ar'><span id='OY0Ar'><b id='OY0Ar'><form id='OY0Ar'><ins id='OY0Ar'></ins><ul id='OY0Ar'></ul><sub id='OY0Ar'></sub></form><legend id='OY0Ar'></legend><bdo id='OY0Ar'><pre id='OY0Ar'><center id='OY0Ar'></center></pre></bdo></b><th id='OY0Ar'></th></span></q></dt></tr></i><div class="lkvhldj" id='OY0Ar'><tfoot id='OY0Ar'></tfoot><dl id='OY0Ar'><fieldset id='OY0Ar'></fieldset></dl></div>

    1. <small id='OY0Ar'></small><noframes id='OY0Ar'>

        我應該在客戶端將 GraphQL ID 作為字符串處理嗎?

        Should I handle a GraphQL ID as a string on the client?(我應該在客戶端將 GraphQL ID 作為字符串處理嗎?)

              <tbody id='bzQxJ'></tbody>
            <tfoot id='bzQxJ'></tfoot>

              <small id='bzQxJ'></small><noframes id='bzQxJ'>

              1. <i id='bzQxJ'><tr id='bzQxJ'><dt id='bzQxJ'><q id='bzQxJ'><span id='bzQxJ'><b id='bzQxJ'><form id='bzQxJ'><ins id='bzQxJ'></ins><ul id='bzQxJ'></ul><sub id='bzQxJ'></sub></form><legend id='bzQxJ'></legend><bdo id='bzQxJ'><pre id='bzQxJ'><center id='bzQxJ'></center></pre></bdo></b><th id='bzQxJ'></th></span></q></dt></tr></i><div class="d3jvg8f" id='bzQxJ'><tfoot id='bzQxJ'></tfoot><dl id='bzQxJ'><fieldset id='bzQxJ'></fieldset></dl></div>
                  <bdo id='bzQxJ'></bdo><ul id='bzQxJ'></ul>
                  <legend id='bzQxJ'><style id='bzQxJ'><dir id='bzQxJ'><q id='bzQxJ'></q></dir></style></legend>
                  本文介紹了我應該在客戶端將 GraphQL ID 作為字符串處理嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用以下方法構建應用程序:

                  I am building an application using:

                  • MySQL 作為后端數據庫
                  • Apollo GraphQL 服務器作為該數據庫的查詢層
                  • Sequelize 作為 GraphQL 和 MySQL 之間的 ORM 層

                  在構建 GraphQL 架構時,我使用 GraphQL ID 數據類型來唯一標識記錄.這是一個示例架構及其 MySQL 解析器/連接器

                  As I am building out my GraphQL schema I'm using the GraphQL ID data type to uniquely identify records. Here's an example schema and its MySQL resolver/connector

                  Graphql 類型:

                  type Person {
                    id: ID!
                    firstName: String
                    middleName: String
                    lastName: String
                    createdAt: String
                    updatedAt: String
                  }
                  

                  續集連接器

                  export const Person = sequelize.define('person', {
                    firstName: { type: Sequelize.STRING },
                    middleName: { type: Sequelize.STRING },
                    lastName: { type: Sequelize.STRING },
                  });
                  

                  GraphQL 解析器:

                  Query: {
                    person(_, args) {
                      return Person.findById(args.id);
                  }
                  

                  這樣一切正常.這是我的問題.GraphQL 似乎將 ID 類型視為字符串.雖然 ID 值被 Sequelize 作為 INT 存儲在 MySQL 數據庫中.我可以使用 GraphQL 使用與數據庫中的 ID 值匹配的字符串或整數來查詢 MySQL 數據庫.但是,GraphQL 將始終以字符串形式返回 ID 值.

                  So that all works. Here's my question. GraphQL seems to treat the ID type as a string. While the ID value gets stored in the MySQL database as an INT by Sequelize. I can use GraphQL to query the MySQL db with either a string or a integer that matches the ID value in the database. However, GraphQL will always return the ID value as a string.

                  我應該如何在客戶端處理這個值?我是否應該在從 GraphQL 獲取它后立即將其轉換為整數?我應該修改我的續集代碼以將 ID 值存儲為字符串嗎?像這樣使用 GraphQL ID 時,是否有正確的處理方法?

                  How should I be handling this value in the client? Should I always convert it to an integer as soon as I get it from GraphQL? Should I modify my sequelize code to store the ID value as a string? Is there a correct way to proceed when using GraphQL IDs like this?

                  推薦答案

                  ID 是 GraphQL 規范(2016 年 10 月工作草案):

                  ID is a scalar type described in the GraphQL specification (working draft October 2016):

                  ID 類型的序列化方式與 String 相同;然而,它并不是人類可讀的.雖然它通常是數字,但它應該始終序列化為字符串.

                  The ID type is serialized in the same way as a String; however, it is not intended to be human‐readable. While it is often numeric, it should always serialize as a String.


                  你的觀察


                  Your observation

                  我可以使用 GraphQL 使用與數據庫中的 ID 值匹配的字符串或整數來查詢 MySQL 數據庫.但是,GraphQL 將始終以字符串形式返回 ID 值.

                  I can use GraphQL to query the MySQL db with either a string or a integer that matches the ID value in the database. However, GraphQL will always return the ID value as a string.

                  符合關于結果強制的規范:

                  GraphQL 與 ID 格式無關,并序列化為字符串以確保 ID 可以表示的多種格式的一致性

                  GraphQL is agnostic to ID format, and serializes to string to ensure consistency across many formats ID could represent

                  輸入強制:

                  當期望作為輸入類型時,任何字符串(例如4")或整數(例如 4)輸入值都應根據給定的 GraphQL 服務器期望的 ID 格式強制轉換為 ID

                  When expected as an input type, any string (such as "4") or integer (such as 4) input value should be coerced to ID as appropriate for the ID formats a given GraphQL server expects


                  我應該如何在客戶端處理這個值?

                  • 使用 ID results 時,將它們視為字符串.
                  • 當使用 ID inputs 時(在 GraphQL 變量或用于突變或查詢的輸入參數中),您可以使用整數或字符串.
                  • When working with ID results, treat them as strings.
                  • When using ID inputs (in GraphQL variables or input parameters for mutations or queries), you can either use integers or strings.

                  我是否應該在從 GraphQL 中獲取后立即將其轉換為整數?

                  這在很大程度上取決于您的應用程序.沒有明確規定是"的一般規則.或否"在這里.

                  That's highly depending on your application. There is no general rule that dictates a clear "yes" or "no" here.

                  我是否應該修改我的 sequelize 代碼以將 ID 值存儲為字符串?

                  不,這不是必需的.

                  關于 ID 類型的 GraphQL 規范沒有涵蓋你如何存儲id,只涵蓋了 GraphQL 服務器應該如何處理 ID輸入和輸出.由 GraphQL 層來確保這種行為.實際存儲中如何處理 id 由存儲層決定.

                  The GraphQL specification about the ID type does not cover how you store the ids, only how a GraphQL server is expected to treat ID input and output. It's up to the GraphQL layer to ensure this behaviour. How ids are handled in the actual storage is up to the storage layer.

                  在使用像這樣的 GraphQL ID 時,是否有正確的處理方法?

                  我希望上面的答案也回答了這個問題:)

                  I hope the above answers also answer this question :)

                  這篇關于我應該在客戶端將 GraphQL ID 作為字符串處理嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)

                      <tbody id='MxwX5'></tbody>
                      • <bdo id='MxwX5'></bdo><ul id='MxwX5'></ul>
                        1. <legend id='MxwX5'><style id='MxwX5'><dir id='MxwX5'><q id='MxwX5'></q></dir></style></legend>
                        2. <i id='MxwX5'><tr id='MxwX5'><dt id='MxwX5'><q id='MxwX5'><span id='MxwX5'><b id='MxwX5'><form id='MxwX5'><ins id='MxwX5'></ins><ul id='MxwX5'></ul><sub id='MxwX5'></sub></form><legend id='MxwX5'></legend><bdo id='MxwX5'><pre id='MxwX5'><center id='MxwX5'></center></pre></bdo></b><th id='MxwX5'></th></span></q></dt></tr></i><div class="ottemaa" id='MxwX5'><tfoot id='MxwX5'></tfoot><dl id='MxwX5'><fieldset id='MxwX5'></fieldset></dl></div>

                          <small id='MxwX5'></small><noframes id='MxwX5'>

                          <tfoot id='MxwX5'></tfoot>

                          1. 主站蜘蛛池模板: 软文世界-软文推广-软文营销-新闻稿发布-一站式软文自助发稿平台 | 上海风淋室_上海风淋室厂家_上海风淋室价格_上海伯淋 | 算命免费_生辰八字_免费在线算命 - 卜算子算命网 | 高空重型升降平台_高空液压举升平台_高空作业平台_移动式升降机-河南华鹰机械设备有限公司 | 希望影视-高清影视vip热播电影电视剧免费在线抢先看 | 磁力抛光研磨机_超声波清洗机厂家_去毛刺设备-中锐达数控 | NBA直播_NBA直播免费观看直播在线_NBA直播免费高清无插件在线观看-24直播网 | 珠海白蚁防治_珠海灭鼠_珠海杀虫灭鼠_珠海灭蟑螂_珠海酒店消杀_珠海工厂杀虫灭鼠_立净虫控防治服务有限公司 | 铝箔袋,铝箔袋厂家,东莞铝箔袋,防静电铝箔袋,防静电屏蔽袋,防静电真空袋,真空袋-东莞铭晋让您的产品与众不同 | 电磁辐射仪-电磁辐射检测仪-pm2.5检测仪-多功能射线检测仪-上海何亦仪器仪表有限公司 | 北京中创汇安科贸有限公司 | 千淘酒店差旅平台-中国第一家针对TMC行业的酒店资源供应平台 | 代写标书-专业代做标书-商业计划书代写「深圳卓越创兴公司」 | 苏州同创电子有限公司 - 四探针测试仪源头厂家 | 乐泰胶水_loctite_乐泰胶_汉高乐泰授权(中国)总代理-鑫华良供应链 | 排烟防火阀-消防排烟风机-正压送风口-厂家-价格-哪家好-德州鑫港旺通风设备有限公司 | PCB设计,PCB抄板,电路板打样,PCBA加工-深圳市宏力捷电子有限公司 | 哈尔滨京科脑康神经内科医院-哈尔滨治疗头痛医院-哈尔滨治疗癫痫康复医院 | 脱硫搅拌器厂家-淄博友胜不锈钢搅拌器厂家 | 科普仪器菏泽市教育教学仪器总厂 | 胶原检测试剂盒,弹性蛋白检测试剂盒,类克ELISA试剂盒,阿达木单抗ELISA试剂盒-北京群晓科苑生物技术有限公司 | 首页|光催化反应器_平行反应仪_光化学反应仪-北京普林塞斯科技有限公司 | 水压力传感器_数字压力传感器|佛山一众传感仪器有限公司|首页 | 压片机_高速_单冲_双层_花篮式_多功能旋转压片机-上海天九压片机厂家 | 沈飞防静电地板__机房地板-深圳市沈飞防静电设备有限公司 | 示波器高压差分探头-国产电流探头厂家-南京桑润斯电子科技有限公司 | 祝融环境-地源热泵多恒系统高新技术企业,舒适生活环境缔造者! | 河南砖机首页-全自动液压免烧砖机,小型砌块水泥砖机厂家[十年老厂] | 一路商机网-品牌招商加盟优选平台-加盟店排行榜平台 | 上海瑶恒实业有限公司|消防泵泵|离心泵|官网 | 冷却塔降噪隔音_冷却塔噪声治理_冷却塔噪音处理厂家-广东康明冷却塔降噪厂家 | 重庆磨床过滤机,重庆纸带过滤机,机床伸缩钣金,重庆机床钣金护罩-重庆达鸿兴精密机械制造有限公司 | 艺术涂料_进口艺术涂料_艺术涂料加盟_艺术涂料十大品牌 -英国蒙太奇艺术涂料 | 回转炉,外热式回转窑,回转窑炉-淄博圣元窑炉工程有限公司 | 艺术涂料|木纹漆施工|稻草漆厂家|马来漆|石桦奴|水泥漆|选加河南天工涂料 | 3dmax渲染-效果图渲染-影视动画渲染-北京快渲科技有限公司 | 河南包装袋厂家_河南真空袋批发价格_河南服装袋定制-恒源达包装制品 | 高硼硅玻璃|水位计玻璃板|光学三棱镜-邯郸奥维玻璃科技有限公司 高温高压釜(氢化反应釜)百科 | 高柔性拖链电缆-聚氨酯卷筒电缆-柔性屏蔽电缆厂家-玖泰电缆 | 中医中药治疗血小板减少-石家庄血液病肿瘤门诊部 | 小型UV打印机-UV平板打印机-大型uv打印机-UV打印机源头厂家 |松普集团 |