graphql 标量类型_使用graphql类型的graphql订阅

news/2024/7/24 13:20:10 标签: python, java

graphql 标量类型

Being a developer it’s always cool to explore new libraries and technology.

作为开发人员,探索新的库和技术总是很酷的。

Being fed up with REST API’s, I moved to GraphQL last year. In simple words, GraphQL is not a 100% solution for every endpoint. When it comes to webhooks, simple public routes REST API’s suits better.

我受够了REST API,去年我搬到了GraphQL。 简而言之,GraphQL并不是每个端点的100%解决方案。 当涉及到Webhooks时,简单的公共路由REST API更适合。

So the purpose of this post is to show how to code a simple graphql subscription in typescript.

因此,本文的目的是展示如何在打字稿中编写简单的graphql订阅代码。

Here we’ll be using well known graphql library Apollo Graphql. For typescript compatibility, we’ll be using type-graphql.

在这里,我们将使用众所周知的graphql库Apollo Graphql 。 为了兼容打字稿,我们将使用type-graphql 。

Okay now let’s take a look at how subscription work in brief.

好了,现在让我们简要地看一下订阅的工作方式。

Image for post

The above image shows the working of a subscription. It's just like a phone call one will listen and one will talk. Here client (subscriber) will be listening to any published event and the server (publisher) will publish an event whenever a certain mutation or query is hit.

上图显示了订阅的工作方式。 就像一个电话,一个人会听,一个人会说话。 此处的客户 (订户) 将侦听任何已发布的事件,并且只要命中某个突变或查询, 服务器 (发布者)就会发布事件。

Here is the folder structure.

这是文件夹结构。

Image for post

Let’s configure the subscription resolver first.

让我们先配置订阅解析器。

Subscription Resolver:

订阅解析器:

Going through the above code. We create a simple query which will return Hello World on request but before returning there is an event being published called MESSAGES. Now we’ll create one more subscription query to listen for the events published. We add topics for which subscription query should listen to, in this case, its MESSAGES. This can be also an array of topics if it’s multiple.

通过上面的代码。 我们创建一个简单的查询,它将返回Hello World 根据要求,但在返回之前,将发布一个名为MESSAGES的事件。 现在,我们将再创建一个订阅查询,以监听发布的事件。 我们添加了订阅查询应监听的主题,在这种情况下,它是MESSAGES 。 如果涉及多个主题,则也可以是一系列主题。

Here is the full code.

这是完整的代码。

输出: (Output:)

翻译自: https://medium.com/@imdhanush/graphql-subscription-using-type-graphql-f65abee4e62d

graphql 标量类型


http://www.niftyadmin.cn/n/1468854.html

相关文章

使用 fftw matlab mex,关于C#:使用minGW将FFTW链接到matlab

我的目标是混合使用库FFTW的C代码。#include #include #include"C:\\Users\\my_user_name\\Documents\\fftw-3.3.5-dll64\\fftw3.h"void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){int i, j, bw, bw2_1, size, size2_1, nrow, nc…

gatsby_在gatsby中共享网站预览图像

gatsbyWhen sharing web content across phone, tablet, or laptop, image previews of a website provide a valuable first impression. If you’re developing websites using static site generators in the React ecosystem, such as Gatsby or Next.js, it’s not immedi…

小鱼易连电脑版_瞩目、腾讯会议、好视通、小鱼易连各有什么优势?怎么收费?...

视频会议并不是一个新鲜事物,存在已30多年,以传统厂商宝利通、思科、华为等大公司为代表,其时早就抢占了政府、金融、教育等领域以及各大公司。但在中小微公司,视频会议设备并不普及,要知道,动辄几十万的一…

matlab设置稀疏矩阵非零元素的个数,Matlab(12)——稀疏矩阵

Matlab(12)——稀疏矩阵文章目录Matlab(12)——稀疏矩阵一、矩阵的存储方式1.完全存储方式2.稀疏存储方式二、稀疏存储方式的产生1.矩阵的完全存储方式与稀疏存储方式的转换2.直接建立稀疏存储方式的矩阵①sparse函数②spconvert函数3.带状稀疏矩阵的稀疏存储方式①从带状稀疏矩…

_带你全面认识 Linux

作者 | arvin译者 | Enmanuel,责编 | 屠敏头图 | CSDN 下载自东方 IC出品 | CSDN(ID:CSDNnews)以下为译文:你知道哪个操作系统是世界上最受欢迎的操作系统吗?是Linux!它一般运行于服务器和超级计算机上,我们…

如何在角度上创建无限滚动

If you’ve ever had to deal with large lists in your web app, then you’re probably familiar with infinite scrolling lists. Infinite scrolling is a common UX solution to the problem of presenting a large list to your users. Think about the Facebook feed or…

PHP中4中标量数据类型,PHP 数据类型 之 标量数据类型

写在前面在程序员开发世界,程序操作的对象是数据,并且每一个数据都有其类型,具备相同类型的数据才可以互相操作,PHP 的数据类型可分为三种:标量数据类型、复合数据类型和特殊数据类型。一、数据类型1.标量数据类型 标量…

python 去掉双引号_史上最全python字符串操作指南

惨不忍睹拿出了看家的老中医野广告,都没能拯救惨淡的selenium剧集。上周五和朋友聊天,说希望看到一些python基础的知识。本来还担心更新基础的东西没人看,但现在看来,最差不过selenium系列了...哈哈。虽然说更新基础知识&#xff…