V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ethego
V2EX  ›  Python

一个新的 GraphQL Python 实现, Python 且更加现代

  •  2
     
  •   ethego ·
    ethe · 2019-07-16 11:12:22 +08:00 · 4148 次点击
    这是一个创建于 1739 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近我司也开始使用 GraphQL 了,真香是真香,尤其是前端的同学会比较喜欢 : ), 选择的实现也是官方的 Graphene 与 graphql-core。但用着用着发现 graphql-core 的使用方法极其的反直觉,连带着基于它的 Graphene 等等都十分难用。究其根本,在于 graphql-core 是直接“翻译”的 graphql.js 的实现,所以其行为方式完全与 Python 相左。

    痛过之后我还是决定新写一个 Python 实现:Pygraphy,使其更加符合 Python 的编写习惯,在调整了 GraphQL 的类型声明设计之后,一切都严丝合缝了。在使用体验上 Pygraphy 更加接近于 ORM 并且舍弃了 Graphene 与 Strawberry 基于 graphql-core 所带来的不和谐。

    如果对于设计的细节有疑问,我在 graphql-core 的 issue 下详细地说明了细节,欢迎来讨论。

    10 条回复    2019-08-06 10:40:51 +08:00
    janxin
        1
    janxin  
       2019-07-16 11:13:46 +08:00
    赞一个
    laravel
        2
    laravel  
       2019-07-16 11:50:25 +08:00
    看来我也要学 GraphQL 了
    mway
        3
    mway  
       2019-07-16 14:52:53 +08:00 via Android
    GraphQL 很好,我博客项目上试用了一下,发现一旦掌握它的思路,用起来很爽。
    razertory
        4
    razertory  
       2019-07-16 17:26:10 +08:00
    我用了很长时间了。再去写 REST 发现难受的一逼
    ethego
        5
    ethego  
    OP
       2019-07-16 17:38:05 +08:00
    如果已经有在使用 Graphene 或者其它 GraphQL 实现的话,可以尝试一下 Pygraphy。
    forblackking
        6
    forblackking  
       2019-07-16 17:52:58 +08:00
    看起来挺优雅的,现在个人项目用的是魔改的 graphene-peewee-async,用起来有点僵硬,周末用这个试试手
    ethego
        7
    ethego  
    OP
       2019-07-16 18:02:17 +08:00
    @forblackking 如果有好的建议以及 bug 反馈,欢迎联系我,email 以及其它联系方式均可。
    omph
        8
    omph  
       2019-07-16 22:07:50 +08:00
    不由想起了另一个引战贴:ApiJson
    [APIJSON-以坚持和偏执,回敬傲慢和偏见 - 孤独的探索号 - 博客园]( https://www.cnblogs.com/tommylemon/p/6573740.html)
    楼主怎么看?
    ethego
        9
    ethego  
    OP
       2019-07-16 23:24:32 +08:00
    @omph 本质上没有太大区别,不过由于舍弃了 JSON 作为传输协议,GraphQL 更加人类可读。另外假设你决定要实现一个第三方库,然后你去找了 GraphQL 的 spec: https://graphql.github.io/graphql-spec/June2018/ ,然后你又看了看 JSONAPI 的 spec: https://jsonapi.org/format/ 。你会决定做哪个?高下立判。GraphQL 在标准化以及组件支持上比 JSONAPI 要好。
    ethego
        10
    ethego  
    OP
       2019-08-06 10:40:51 +08:00
    @mway GraphQL 可以看做是更精细的 RPC 协议
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2805 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:06 · PVG 20:06 · LAX 05:06 · JFK 08:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.