40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { ofetch } from 'ofetch';
|
|
// import { gql } from './__generated__';
|
|
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
|
|
|
|
const gqlText = gql(
|
|
`
|
|
query get {
|
|
demo_projects {
|
|
id
|
|
}
|
|
}`
|
|
);
|
|
|
|
const client = new ApolloClient({
|
|
uri: process.env.GRAPHQL_ENDPOINT_WITH_TOKEN, // 你的 GraphQL 服务器地址
|
|
cache: new InMemoryCache(), // 内置的内存缓存
|
|
// 可以添加更多选项,比如 headers、fetchPolicy 等
|
|
});
|
|
|
|
(async () => {
|
|
const result = await client.query({
|
|
query: gqlText
|
|
})
|
|
})
|
|
|
|
// (async () => {
|
|
// const result = await ofetch("http://172.16.6.246:8055/graphql", {
|
|
// method: 'POST',
|
|
// headers: {
|
|
// 'Authorization': 'Bearer WkVWFMiFcrjsXRZqsL30Cd4Sboe0DRk-',
|
|
// 'Content-Type': 'application/json',
|
|
// },
|
|
// body: {
|
|
// query: gqlText,
|
|
// variables: {}
|
|
// },
|
|
// })
|
|
// console.log(JSON.stringify(result, null, 2));
|
|
// })();
|