cc 使用yarn


yarn init

yarn add rxjs

yarn add  @apollo/client graphql


import {ApolloClient, gql, InMemoryCache} from "@apollo/client";
import {ajax} from "rxjs/ajax";
import {map} from "rxjs";

class GraphqlClient {
    private static instance: GraphqlClient

    public static get(): GraphqlClient {
        if (this.instance == null) {
            this.instance = new this();
        }
        return this.instance;
    }

    client = new ApolloClient({
        uri: 'https://test.shuangyangad.com/online-earning-core/graphql',
        cache: new InMemoryCache(),
        headers: {"Authorization": ""}
    });

    public async test() {
        await this.client
            .query({
                query: gql`
                query {
                  timestamp
                }
    `
            })
            .then(result => console.log("graphql==================" + result))
            .catch(err => {
                console.log("graphql=================" + err)

            });
    }

    public async test1() {
        ajax({
            url: "https://test.shuangyangad.com/online-earning-core/api/timestamp", method: "GET", headers: {
                "Authorization": " "

            }
        }).pipe(map(data => data.response)
        ).subscribe({
            error: (err) => {
                console.log("rxjs==================" + err)
            },
            next: (data) => {
                console.log("rxjs======================" + data.timestamp)
            }
        })
    }
}

export default GraphqlClient.get()

上一篇:Java学习笔记——正则表达式


下一篇:angular国际化 / rxjs使用技巧