如何在自有前端工程中使用gql请求?

场景

客户在个性化程度比较高的h5工程中想使用平台的服务端能力,这个时候需要调用后端的gql请求,此时需要引入平台的请求库依赖

npm的package.json中加入依赖

此文档以4.x举例,使用其他版本的请自行修改版本号

"dependencies": {
    "@kunlun/request": "~4.3.0",
    "@kunlun/state": "~4.3.0"
}

使用示例

import { HttpClient } from '@kunlun/request' const http = HttpClient.getInstance() http.setBaseURL('') export const login = (data) => { const gqlBody = `mutation { pamirsUserTransientMutation { login(user: {login: "${data.username}", password: "${data.password}"}) { broken errorMsg errorCode errorField } } }` return http.mutate('user', gqlBody) }

注意事项

开发环境记得配置oinone请求的路由转发规则,这里以vite.config.js举例

import { defineConfig } from 'vite' export default defineConfig({ server: { port: 8088, open: true, proxy: { '/pamirs': { changeOrigin: true, // 服务端请求地址 target: 'http://127.0.0.1:8091' } } } })

Oinone社区 作者:oinone原创文章,如若转载,请注明出处:https://doc.oinone.top/frontend/21.html

访问Oinone官网:https://www.oinone.top获取数式Oinone低代码应用平台体验

(0)
oinone的头像oinone
上一篇 2023年6月20日 下午4:07
下一篇 2023年11月2日 下午1:58

相关推荐

  • 左树右表默认选择第一行

    import { BaseElementWidget, Widget, SPI, ViewType, TableSearchTreeWidget } from '@kunlun/dependencies'; @SPI.ClassFactory( BaseElementWidget.Token({ viewType: ViewType.Ta…

    2024年11月26日
    54000
  • 界面设计器 扩展字段的查询上下文

    默认情况下oinone平台对于查询条件,只提供的当前登录用户这一个配置,但是允许开发者扩展 开发者可以在前端代码的main.ts进行扩展 import { SessionContextOptions, ModelFieldType } from '@kunlun/dependencies'; const currentDeptOption…

    2023年11月8日
    66200
  • Oinone移动端快速入门

    介绍 oinone的pc端的页面默认都可以在移动端直接访问。自定义mask、layout、视图组件、字段组件、动作组件方式都参考pc端实现。目前移动端的UI组件是基于vant@3.6.0版本开发,如有自定义部分的代码,推荐使用该组件库。 “注意”: 由于移动端和pc端在交互上的巨大差异,两端用的是不同的UI组件库是,按照此约定开发的自定义组件在两端也是无法相…

    2024年9月19日
    48700
  • Class Component(ts)(v4)

    Class Component 一种使用typescript的class声明组件的方式。 IWidget类型声明 IWidget是平台内所有组件的统一接口定义,也是一个组件定义的最小集。 /** * 组件构造器 */ export type WidgetConstructor<Props extends WidgetProps, Widget exte…

    2023年11月1日
    48800
  • 函数扩展

    oinone 平台内置了一些函数, 如果当前函数不满足,那么可以通过扩展的方式添加函数 后端实现 后端实现 import {Expression} from '@kunlun/dependencies' Expression.getInstance().registerFunction(); registerFunction函数的参数如下…

    2023年11月9日
    1.1K00

发表回复

登录后才能评论